From patchwork Thu Aug 24 06:17:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 4817 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp252886jao; Wed, 23 Aug 2017 23:18:13 -0700 (PDT) X-Received: by 10.28.23.132 with SMTP id 126mr3099336wmx.111.1503555493867; Wed, 23 Aug 2017 23:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503555493; cv=none; d=google.com; s=arc-20160816; b=gnsSrKvKZxWyVoY00amDOErR6HZaqOhlARIA2oXQKU2IrQtD67UJ0FFpuepFEJS6gS y76mjX3AJ8HPwSeRjcsykrh1fsNgS0abRjfzNW3OpOiKILngnW87GDMq3+SFG2v2vEXd SR2RZzojNr33u4+ZpJih2uTEktfHDvOJ+LQXYcU9B3l5WEXbXPejfK9bjQwhqqUD4+Dc NkVT3Cm2fq68nvSS432IQKYvGhtrvJlJkZezPX6+kadwslbT/GEeDf7RHL2kfwJoIyBi egbk8P48vgBaVEdMZ6rt1FMbN4glNzIsnb6Vnw7Q/wr3IflN+b1zcIaN1+vWUzLvbcsz Vdpg== 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=YSNYxQk1zTwB9PtrFglF7QgDt4sbgsJ+nPjp4VGsbO4=; b=BoCiidqstMnUot8oeEDvNOBOnpHBTkbgxZBlITChGqCU1+0/dVqx9ho4Kiu6pVpj/S 8G3+BUzg3dY4B5lz7qHKd3iDNQFysbx/EOR6LpAmZkY2jV6sJ/lB2a5mmblGLA9KGcvu pCVGlVFBonWHJH1FTyDg8GnsgmYkRyJfbkgrJD1OrIQWGRqMyHbpKxdcH0xoeTdL0h+y dm3Jv333WcoSrGPDJzu6I520oE0gl3n6tbLRkOLLi1r8Uf9YTF9h+iNDrsG70YbO2RZ5 QZ7xIJspPaBjsRKML05XzlagxXGlTFRfGSSHiaH+fgbD//R8fApsGIrpypRS7rDXDpfK 8E6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=SMYVvICN; 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 b79si2651667wmb.223.2017.08.23.23.18.12; Wed, 23 Aug 2017 23:18:13 -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=SMYVvICN; 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 D6F38689A7C; Thu, 24 Aug 2017 09:18:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 48DC86883AE for ; Thu, 24 Aug 2017 09:17:56 +0300 (EEST) Received: by mail-wm0-f43.google.com with SMTP id r134so13171625wmf.0 for ; Wed, 23 Aug 2017 23:18:04 -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=qugIRKdatUjk78jpB94gLZ0pF3pMRVGLezH/T6ILxWc=; b=SMYVvICNwwPCpXKI1bDB1zWt9rUEKo1Vv+mdFprqxC6C+5rDDwWhwFikG6sdYtixQT lxlItl084aEC1fnwRLWmV8DFkU8DNncliUU4LbKd93IlyEGHSzWryk/fjh971gI52fAf e40p9fv4792/IXrwTRDabIaI2k68UGvtf1Mmao9y3exV0yXhUveqB0ZVEmi45tgBDh5e Ta1n3kIHUAPikptxnAkqjZtIGjC2KCVFK+RArFTtBZRvtbpdBuhUUThstAC8RNulgHos Co/LK8tIkDHDbbl4JlhwlzV2AhkwvLyMNvI5BjTQG5D9rt64BC6LxCp8PilMe3yuvCHS 6btg== 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=qugIRKdatUjk78jpB94gLZ0pF3pMRVGLezH/T6ILxWc=; b=CF1o3ok4QOrY5kKgfnS71H3f3MDMxL2TMZvFDoUnVtVb21Uh+PahnZMdAptgtUb8lZ 3O2T+4IlrTUMC7M519bnV91yryqU210TDJD9pIFU7sVHjx8fkYg7dr/r7fy0hnWD/TSO qFV1Nw5tqpt2PCZgzOCQsMBgfPXMqHKvwP26+h0ctYPC9O3lkfpHTctvOP1NMTlZ7z24 JZESAEfFR6Ou4nK4ZzluHgtcy/FTi7+QuNUDzNqy7kRc9+7M9HBezz5qOP9SUhjyJIM5 dv8GBtIOidlmFgFpd5vuWczhKi/xWpasQs6Oe1qx6gWM1iuA9dRpPuqeZnC736h8mRW0 GhTg== X-Gm-Message-State: AHYfb5js7qTwibMRFd68pJpEemCVRUQlG8ezIgLZauNKnI7+ON4847tT /dBfvox3yKFM5/0l X-Received: by 10.28.154.215 with SMTP id c206mr3501743wme.151.1503555483630; Wed, 23 Aug 2017 23:18:03 -0700 (PDT) Received: from [192.168.0.2] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id b130sm2490875wme.28.2017.08.23.23.18.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 23:18:02 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <20170824003033.GW7094@nb4> From: "pkv.stream" Message-ID: <067da1cc-13a8-fc34-511b-6775a4bc02a4@gmail.com> Date: Thu, 24 Aug 2017 08:17:58 +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: <20170824003033.GW7094@nb4> Content-Language: fr X-Content-Filtered-By: Mailman/MimeDel 2.1.20 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" Le 24/08/2017 à 2:30 AM, Michael Niedermayer a écrit : > On Wed, Aug 23, 2017 at 06:48:14PM +0200, pkv.stream wrote: >> Hello, >> >> the following patch allows one to add a trailing ? to -map_channel >> as in -map option. >> >> E.g: -map_channel 0.0.2? so that if the channel does not exist, the >> command does not stop. >> >> This is similar to what one can do with -map. >> >> Thanks for any input. >> >> >> ffmpeg_opt.c | 24 ++++++++++++++++++++---- >> 1 file changed, 20 insertions(+), 4 deletions(-) >> 28689933986d73050286e700752ace032df6dc1b 0001-ffmpeg-options-Enable-trailing-for-map_channel.patch >> From 07959dfe79816d03c30b8027f45b41d60078b3fa 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). >> --- >> ffmpeg_opt.c | 24 ++++++++++++++++++++---- >> 1 file changed, 20 insertions(+), 4 deletions(-) > the patch contains tabs (cannot be pushed to git master) > and this is missing an update to the documentation thanks Michael. Patch corrected per your instructions. Updated doc , provided an example and removed all tabs ! > > [...] > > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From 110ab5a6393639be565820b98fe6b1a51524f796 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 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) 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; }