diff mbox

[FFmpeg-devel] ffmpeg options: Enable trailing ? for map_channel

Message ID ce0770fa-89b7-1aa8-efa0-731913451924@gmail.com
State Superseded
Headers show

Commit Message

pkv.stream Aug. 23, 2017, 4:48 p.m. UTC
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.
From 07959dfe79816d03c30b8027f45b41d60078b3fa Mon Sep 17 00:00:00 2001
From: pkviet <pkv.stream@gmail.com>
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(-)

Comments

Michael Niedermayer Aug. 24, 2017, 12:30 a.m. UTC | #1
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 <pkv.stream@gmail.com>
> 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

[...]
pkv.stream Aug. 24, 2017, 5:32 a.m. UTC | #2
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" <michael@niedermayer.cc> 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 <pkv.stream@gmail.com>
> > 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
>
>
diff mbox

Patch

diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 1c4a11e..6b3912f 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -405,7 +405,12 @@  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,21 @@  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;
 }