Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
Thanks a lot Michael. (and for spotting the avfree I missed) Le 25 août 2017 11:44 PM, "Michael Niedermayer" a écrit : On Thu, Aug 24, 2017 at 11:10:49PM +0200, pkv.stream wrote: > 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 ? > > > > 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(-) > 1d35047c00f25dc1391a541eb704a03a9c9198de 0001-ffmpeg-options-Enable- trailing-for-map_channel.patch > 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). added missing av_free() applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Asymptotically faster algorithms should always be preferred if you have asymptotical amounts of data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
On Thu, Aug 24, 2017 at 11:10:49PM +0200, pkv.stream wrote: > 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 ? > > > > 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(-) > 1d35047c00f25dc1391a541eb704a03a9c9198de > 0001-ffmpeg-options-Enable-trailing-for-map_channel.patch > 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). added missing av_free() applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Asymptotically faster algorithms should always be preferred if you have asymptotical amounts of data signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
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
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
2017-08-24 21:16 GMT+02:00 pkv.stream : > Hi > working on creating a fate test. > I am stumbling on probably a dumb issue; I want to re-use a file already > used for mapchan test: > > FATE_MAPCHAN-$(CONFIG_CHANNELMAP_FILTER) += fate-mapchan-6ch-extract-2 > fate-mapchan-6ch-extract-2: tests/data/asynth-22050-6.wav > (first two lines in ffmpeg.mak) > > But I can't get a hold of this file. I have no data folder from git; after > running a fate test, I get a fate-suite folder but this file is not > included. > > Thanks for any hint. > > run make fate and take a look at ./tests/data/ the file is generated by make fate. Did you download samples files ? if not take a look here https://www.ffmpeg.org/fate.html So you can run a fate with all the tests. Martin ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
2017-08-24 11:03 GMT+02:00 Kv Pham : > Ah ok! > Sure, I will do that. I need first to acquaint myself more with fate. > > > Hello, You can take a look at ./tests/fate/ffmpeg.mak (begin of the file seems to have test for map_channel) I think you need to add two test, one when the channel is found, and one when the channel is not found. The idea is to find an ffmpeg cmd, using generator (as input file), or input file already in the fate-suite if possible and use framecrc for example, as output, (with a minimal log level) Then you add the result as a txt file in \tests\ref\fate (with a naming consistent with the name of the test) Martin ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
Ah ok! Sure, I will do that. I need first to acquaint myself more with fate. Le 24 août 2017 10:52 AM, "Michael Niedermayer" a écrit : On Thu, Aug 24, 2017 at 10:36:20AM +0200, Kv Pham wrote: > Yes I did a make fate. Went ok. > Is there a log to attach ? Or stdout ? i meant can you add a test that tests the new feature when one runs make fate that is if the user runs "make fate" it would execute ffmpeg with map and "trailing ?" > > > Le 24 août 2017 10:34 AM, "Michael Niedermayer" a > écrit : > > On Thu, Aug 24, 2017 at 08:17:58AM +0200, pkv.stream wrote: > > 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 ! > > ok, thanks > can you also add a self test to "make fate" ? > > [...] > > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > Let us carefully observe those good qualities wherein our enemies excel us > and endeavor to excel them, by avoiding what is faulty, and imitating what > is excellent in them. -- Plutarch > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB It is what and why we do it that matters, not just one of them. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
On Thu, Aug 24, 2017 at 10:36:20AM +0200, Kv Pham wrote: > Yes I did a make fate. Went ok. > Is there a log to attach ? Or stdout ? i meant can you add a test that tests the new feature when one runs make fate that is if the user runs "make fate" it would execute ffmpeg with map and "trailing ?" > > > Le 24 août 2017 10:34 AM, "Michael Niedermayer" a > écrit : > > On Thu, Aug 24, 2017 at 08:17:58AM +0200, pkv.stream wrote: > > 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 ! > > ok, thanks > can you also add a self test to "make fate" ? > > [...] > > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > Let us carefully observe those good qualities wherein our enemies excel us > and endeavor to excel them, by avoiding what is faulty, and imitating what > is excellent in them. -- Plutarch > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB It is what and why we do it that matters, not just one of them. signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
Yes I did a make fate. Went ok. Is there a log to attach ? Or stdout ? Le 24 août 2017 10:34 AM, "Michael Niedermayer" a écrit : On Thu, Aug 24, 2017 at 08:17:58AM +0200, pkv.stream wrote: > 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 ! ok, thanks can you also add a self test to "make fate" ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
On Thu, Aug 24, 2017 at 08:17:58AM +0200, pkv.stream wrote: > 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 ! ok, thanks can you also add a self test to "make fate" ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
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->ch
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
Ah sorry about that. I forgot about the tabs. Will correct and add update to doc. Thanks Le 24 août 2017 2:32 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 > > [...] > > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > Elect your leaders based on what they did after the last election, not > based on what they say before an election. > > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffmpeg options: Enable trailing ? for map_channel
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 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Elect your leaders based on what they did after the last election, not based on what they say before an election. signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel