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

pkv.stream pkv.stream at gmail.com
Wed Aug 23 19:48:14 EEST 2017


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.


-------------- next part --------------
From 07959dfe79816d03c30b8027f45b41d60078b3fa Mon Sep 17 00:00:00 2001
From: pkviet <pkv.stream at 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(-)

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;
 }
-- 
2.10.1.windows.1



More information about the ffmpeg-devel mailing list