From patchwork Thu Aug 24 21:10:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 4822 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp689321jao; Thu, 24 Aug 2017 14:19:27 -0700 (PDT) X-Received: by 10.223.136.104 with SMTP id e37mr4904224wre.152.1503609567680; Thu, 24 Aug 2017 14:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503609567; cv=none; d=google.com; s=arc-20160816; b=mbFMBVv98gbbgnJyo4t5X+LRZ8fPwgeUJbsNvk3mfInzZS8V7VR9s6cXP/NNNxZfVk LKKy01VbjWkx5rkiZ6WzilL6NtMc95UCk5Mu/n1MpR8ZHy6Xe2sQoTJ1+7sQRGEVPTa2 gGsZUpW0FT0zoxbQPbEs+V/VRunEYCCmPumZxe+N145j1cPWQOwhOrCdmxhd36AACJRh zWNiq0//BoeMm/OwbAYxFn0v3x0rjeYy0tCiukBq4RlMdYFzJCm9yxZFKIxEMMaMRMSA N/HG9EOvZrKuVEXLstSUI7+/vP0Mbk6dnrTaESXgmy5O+37iB2JHwB2XA6iIZRQtUsDb +tiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=cVdW5cYEO3hLyJ7V86CUbTk+v6EAGsnbt4qAMKxyTy8=; b=EUBmmK3BLsgPU044DNYueUT19NPFYSkZ4VAMGVVtgkyetOBd9nO5pGxFcLytUjEJ9P tFhwaVCnod5Wtei2Mdux64Ad07LvM7wTZH3clBwxIAnRC2owiMe3U89qNcLrv9nMWAfZ RvKELV11ly3pVfy5Ot5W/Ak4gami2766LXMa/op4IDGPPZN3CfqIomMJQMpjP19aXpL6 imBEvydVzvCKD03zho6EkK0mv9/BYsvO5EEBavI30pmCv2hGCDAh3tE6+1N0GwOHpYw7 YdblHASq9qrLoTeBRQFPcsjfQlwLR9ZC5QBQgFHnDcFIq73Aag6r8XZH6IQLr5ghmau/ j5YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WvW1U1F0; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p16si3985004wrg.184.2017.08.24.14.19.27; Thu, 24 Aug 2017 14:19:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WvW1U1F0; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 845E46891FA; Fri, 25 Aug 2017 00:19:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com [209.85.128.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A92636806B8 for ; Fri, 25 Aug 2017 00:19:09 +0300 (EEST) Received: by mail-wr0-f182.google.com with SMTP id a47so2014114wra.4 for ; Thu, 24 Aug 2017 14:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=mpWpx/sykp0vXyaZkcxlu95HHyREf0PklalTEMkJa/0=; b=WvW1U1F0ZXWBHrqn/HCTcdH9Ux50kU4pDrl6cB4CY3x9+rMrSu/jGbungaObvcwhtq MFjMp53/elXJN5bUraSr/vFD+w/9xrRQtoOerBFRfktvPHAamwcNAbv1YgzIHDR35Djt obInAsquZvGHxsdYRegAQllzbgw/fqef0qubg39zQqnkpienqCUtEt8iOXHKo5n9ky+/ QKatZ39wTu49jn2u4pCJm3OgReylH2LM3ozgloQWD4/Guwb3yErkrIa8KHHjkGFxwJSM x8oBvxjouybIY2fFmCS9QqPA1XNNPT1jVK0WJPglCZS/EsaINdoR7eC/Dc8jgG+Le5ZU X5JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=mpWpx/sykp0vXyaZkcxlu95HHyREf0PklalTEMkJa/0=; b=QALrs09lUZAsXYfAed0Os5Mu/vl8aGQi8c37q8NQYHa2omU12ppHHtd8HthIbZSBQb MXjuGnU/Z2OhgTXPWqeP2UWKimdZmE/ladTY5ONeVfs8E9JaH2lym+0Y9Y/9DQWJQGOj OMYiidODfE4btd1OPNcJfi6wkF+qN+5QaPT/5FUOJ+k8CZz6j/NCCkWA6NPaMsN7dZ6k fFn9MJmJqwoz3tWA8END2T2V9sxZNYQ3pHqiiigLFwNkP7tdnNyxWMiA+jl1lbvq99kF auJW2uMiSbAYgj6YXPg2r4CWmBYf7FT4/LONvLfSXtDDiqiUwRjSWfQ2V5vDeI84L/8M Sq2Q== X-Gm-Message-State: AHYfb5jU6NiBluPPmXr2lkLTvv2DwwVGyf18/6V7K89hlivRvbtLLrpW MVBmzVcOhNALUUhv X-Received: by 10.223.195.207 with SMTP id d15mr4551820wrg.203.1503609052901; Thu, 24 Aug 2017 14:10:52 -0700 (PDT) Received: from [192.168.0.2] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id q45sm11213444wrb.3.2017.08.24.14.10.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Aug 2017 14:10:51 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <20170824003033.GW7094@nb4> <067da1cc-13a8-fc34-511b-6775a4bc02a4@gmail.com> <20170824083259.GY7094@nb4> <20170824085116.GZ7094@nb4> <7ed6bc3a-69ca-dc82-cb85-9c33dac99036@gmail.com> From: "pkv.stream" Message-ID: <91b7982c-743c-cb1a-c51b-c1a93a6399e7@gmail.com> Date: Thu, 24 Aug 2017 23:10:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Language: fr Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Thanks a lot Martin !!! all sorted out thanks to your kind help. I had run fate previously but obviously missed something; so re-run and it's ok. I created two tests per your advice testing for a third channel in a stereo file and then in a 2.1 file. Instead of CRC, I've used MD5 because the extant mapchan fate tests were using it. Updated patch in attachment. Michael: would that be OK or do you see other changes to make ? From 5c3b0fed39b713b19ed53b5704b1fce63b2742ad Mon Sep 17 00:00:00 2001 From: pkviet Date: Tue, 22 Aug 2017 11:30:45 +0200 Subject: [PATCH] ffmpeg options: Enable trailing ? for map_channel The -map option allows for a trailing ? so that an error is not thrown if the input stream does not exist. This capability is extended to the map_channel option. This allows a ffmpeg command not to break if an input channel does not exist, which can be of use (for instance, scripts processing audio channels with sources having unset number of audio channels). --- doc/ffmpeg.texi | 13 ++++++++++++- ffmpeg_opt.c | 21 ++++++++++++++++++--- tests/fate/ffmpeg.mak | 8 ++++++++ tests/ref/fate/mapchan-2ch-extract-ch0-ch2-trailing | 1 + tests/ref/fate/mapchan-3ch-extract-ch0-ch2-trailing | 1 + 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 tests/ref/fate/mapchan-2ch-extract-ch0-ch2-trailing create mode 100644 tests/ref/fate/mapchan-3ch-extract-ch0-ch2-trailing diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 4616a42..de6d3f1 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -996,7 +996,7 @@ such streams is attempted. Allow input streams with unknown type to be copied instead of failing if copying such streams is attempted. -@item -map_channel [@var{input_file_id}.@var{stream_specifier}.@var{channel_id}|-1][:@var{output_file_id}.@var{stream_specifier}] +@item -map_channel [@var{input_file_id}.@var{stream_specifier}.@var{channel_id}|-1][?][:@var{output_file_id}.@var{stream_specifier}] Map an audio channel from a given input to an output. If @var{output_file_id}.@var{stream_specifier} is not set, the audio channel will be mapped on all the audio streams. @@ -1005,6 +1005,10 @@ Using "-1" instead of @var{input_file_id}.@var{stream_specifier}.@var{channel_id} will map a muted channel. +A trailing @code{?} will allow the map_channel to be +optional: if the map_channel matches no channel the map_channel will be ignored instead +of failing. + For example, assuming @var{INPUT} is a stereo audio file, you can switch the two audio channels with the following command: @example @@ -1052,6 +1056,13 @@ video stream), you can use the following command: ffmpeg -i input.mkv -filter_complex "[0:1] [0:2] amerge" -c:a pcm_s16le -c:v copy output.mkv @end example +To map the first two audio channels from the first input, and using the +trailing @code{?}, ignore the audio channel mapping if the first input is +mono instead of stereo: +@example +ffmpeg -i INPUT -map_channel 0.0.0 -map_channel 0.0.1? OUTPUT +@end example + @item -map_metadata[:@var{metadata_spec_out}] @var{infile}[:@var{metadata_spec_in}] (@emph{output,per-metadata}) Set metadata information of the next output file from @var{infile}. Note that those are file indices (zero-based), not filenames. diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index 1c4a11e..2f6bfc9 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -405,6 +405,11 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) int n; AVStream *st; AudioChannelMap *m; + char *allow_unused; + char *mapchan; + mapchan = av_strdup(arg); + if (!mapchan) + return AVERROR(ENOMEM); GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps); m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1]; @@ -450,10 +455,20 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) m->file_idx, m->stream_idx); exit_program(1); } + /* allow trailing ? to map_channel */ + if (allow_unused = strchr(mapchan, '?')) + *allow_unused = 0; if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels) { - av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n", - m->file_idx, m->stream_idx, m->channel_idx); - exit_program(1); + if (allow_unused) { + av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n", + m->file_idx, m->stream_idx, m->channel_idx); + } else { + av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n" + "To ignore this, add a trailing '?' to the map_channel.\n", + m->file_idx, m->stream_idx, m->channel_idx); + exit_program(1); + } + } return 0; } diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index 0ec5a34..f3fbc84 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -10,6 +10,14 @@ FATE_MAPCHAN-$(CONFIG_CHANNELMAP_FILTER) += fate-mapchan-silent-mono fate-mapchan-silent-mono: tests/data/asynth-22050-1.wav fate-mapchan-silent-mono: CMD = md5 -i $(TARGET_PATH)/tests/data/asynth-22050-1.wav -map_channel -1 -map_channel 0.0.0 -fflags +bitexact -f wav +FATE_MAPCHAN-$(CONFIG_CHANNELMAP_FILTER) += fate-mapchan-2ch-extract-ch0-ch2-trailing +fate-mapchan-2ch-extract-ch0-ch2-trailing: tests/data/asynth-44100-2.wav +fate-mapchan-2ch-extract-ch0-ch2-trailing: CMD = md5 -i $(TARGET_PATH)/tests/data/asynth-44100-2.wav -map_channel 0.0.0 -map_channel 0.0.2? -fflags +bitexact -f wav + +FATE_MAPCHAN-$(CONFIG_CHANNELMAP_FILTER) += fate-mapchan-3ch-extract-ch0-ch2-trailing +fate-mapchan-3ch-extract-ch0-ch2-trailing: tests/data/asynth-44100-3.wav +fate-mapchan-3ch-extract-ch0-ch2-trailing: CMD = md5 -i $(TARGET_PATH)/tests/data/asynth-44100-3.wav -map_channel 0.0.0 -map_channel 0.0.2? -fflags +bitexact -f wav + FATE_MAPCHAN = $(FATE_MAPCHAN-yes) FATE_FFMPEG += $(FATE_MAPCHAN) diff --git a/tests/ref/fate/mapchan-2ch-extract-ch0-ch2-trailing b/tests/ref/fate/mapchan-2ch-extract-ch0-ch2-trailing new file mode 100644 index 0000000..a540037 --- /dev/null +++ b/tests/ref/fate/mapchan-2ch-extract-ch0-ch2-trailing @@ -0,0 +1 @@ +b6e1d142b4e484221562e7b66b9bbbdc diff --git a/tests/ref/fate/mapchan-3ch-extract-ch0-ch2-trailing b/tests/ref/fate/mapchan-3ch-extract-ch0-ch2-trailing new file mode 100644 index 0000000..6237a98 --- /dev/null +++ b/tests/ref/fate/mapchan-3ch-extract-ch0-ch2-trailing @@ -0,0 +1 @@ +ae533985186cab287309c04f6b3e866c