[FFmpeg-devel] [PATCH 2/4] ffmpeg: do not reset the map when adding an input.

Clément Bœsch ubitux at gmail.com
Thu Apr 5 11:00:46 CEST 2012


On Sat, Mar 24, 2012 at 12:44:25PM +0100, Stefano Sabatini wrote:
> On date Thursday 2012-03-22 16:50:39 +0100, Clément Bœsch encoded:
> > From: Clément Bœsch <clement.boesch at smartjog.com>
> > 
> > The map array contains a reference to the input file and stream, so it
> > won't mix up with any following specified input; there is no reason to
> > drop them.
> > 
> > Also, keeping the maps allows to create new streams on the fly and not
> > break the map definitions.
> 
> Please be more specific in the commit subject/log, there are at least
> 4 different maps.
> 

Rewritten.

> > ---
> >  ffmpeg.c |    7 ++++++-
> >  1 files changed, 6 insertions(+), 1 deletions(-)
> > 
> > diff --git a/ffmpeg.c b/ffmpeg.c
> > index 5606f17..32286e2 100644
> > --- a/ffmpeg.c
> > +++ b/ffmpeg.c
> > @@ -456,11 +456,16 @@ static void reset_options(OptionsContext *o, int is_input)
> >          po++;
> >      }
> >  
> > -    av_freep(&o->stream_maps);
> > +    if (!is_input)
> > +        av_freep(&o->stream_maps);
> >      av_freep(&o->audio_channel_maps);
> >      av_freep(&o->streamid_map);
> >  
> >      memset(o, 0, sizeof(*o));
> 
> > +    if (is_input) {
> > +        o->stream_maps    = bak.stream_maps;
> > +        o->nb_stream_maps = bak.nb_stream_maps;
> > +    }
> >  
> >      if(is_input) o->recording_time = bak.recording_time;
> 
> You can merge these.
> 

Done.

> BTW, by following the same logic, why this is only applied to
> o->stream_maps and not to the other maps (audio_channel, meta_data,
> streamid)?
> (Note: the mapping code is new to me and pretty convoluted, so I may
> be missing something obvious.)

Done for -map and -map_channel; both options are "position independent";
they both refer to any of the input (in the syntax the input is
explicitly specified) so there is no real reason to reset the array when
a new input is added.

-streamid is an output option, not really related to the other map
options, so I left it out.

-- 
Clément B.
-------------- next part --------------
From 3ee5de2d1db11912bc89a22405ffc1e0b75c514b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
Date: Thu, 22 Mar 2012 11:42:10 +0100
Subject: [PATCH 2/4] ffmpeg: do not reset "-map" and "-map_channel" arrays
 when adding an input.

"-map" and "-map_channel" arrays contain references to the input file
and stream (both in command line parameters and internally), so they
won't be disrupted when specifying a new input (-i). There is therefore
no reason to drop them. Also, keeping the maps allows to create new
streams on the fly and not break the map definitions. Additionally,
"-map" and "-map_channel" can now be interleaved between the different
"-i" options.

This would work for the "-streamid" map, but since it is an output
option, it doesn't really belong before any "-i" option.
---
 ffmpeg.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index b0ed8bf..1e1a34c 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -456,14 +456,24 @@ static void reset_options(OptionsContext *o, int is_input)
         po++;
     }
 
-    av_freep(&o->stream_maps);
-    av_freep(&o->audio_channel_maps);
+    /* "-i" option should not reset some map arrays */
+    if (!is_input) {
+        av_freep(&o->stream_maps);
+        av_freep(&o->audio_channel_maps);
+    }
+
     av_freep(&o->streamid_map);
 
     memset(o, 0, sizeof(*o));
-
-    if(is_input) o->recording_time = bak.recording_time;
-    else         o->recording_time = INT64_MAX;
+    if (is_input) {
+        o->recording_time = bak.recording_time;
+        o->stream_maps    = bak.stream_maps;
+        o->nb_stream_maps = bak.nb_stream_maps;
+        o->audio_channel_maps    = bak.audio_channel_maps;
+        o->nb_audio_channel_maps = bak.nb_audio_channel_maps;
+    } else {
+        o->recording_time = INT64_MAX;
+    }
     o->mux_max_delay  = 0.7;
     o->limit_filesize = UINT64_MAX;
     o->chapters_input_file = INT_MAX;
-- 
1.7.9.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120405/4c0dc056/attachment.asc>


More information about the ffmpeg-devel mailing list