[FFmpeg-devel] [PATCH 1/7] ffmpeg: dynamically allocate streamid_map

Aurélien Jacobs aurel
Fri Aug 13 20:24:14 CEST 2010


From: Aurelien Jacobs <aurel at gnuage.org>

---
 ffmpeg.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 28ce27f..1546582 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -123,7 +123,8 @@ static AVMetaDataMap meta_data_maps[MAX_FILES];
 static int nb_meta_data_maps;
 
 /* indexed by output file stream index */
-static int streamid_map[MAX_STREAMS];
+static int *streamid_map = NULL;
+static int nb_streamid_map = 0;
 
 static int frame_width  = 0;
 static int frame_height = 0;
@@ -615,6 +616,7 @@ static int ffmpeg_exit(int ret)
     av_free(vstats_filename);
 
     av_free(opt_names);
+    av_free(streamid_map);
 
     av_free(video_codec_name);
     av_free(audio_codec_name);
@@ -3371,7 +3373,7 @@ static void new_video_stream(AVFormatContext *oc)
     AVCodecContext *video_enc;
     enum CodecID codec_id;
 
-    st = av_new_stream(oc, streamid_map[oc->nb_streams]);
+    st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
     if (!st) {
         fprintf(stderr, "Could not alloc stream\n");
         ffmpeg_exit(1);
@@ -3509,7 +3511,7 @@ static void new_audio_stream(AVFormatContext *oc)
     AVCodecContext *audio_enc;
     enum CodecID codec_id;
 
-    st = av_new_stream(oc, streamid_map[oc->nb_streams]);
+    st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
     if (!st) {
         fprintf(stderr, "Could not alloc stream\n");
         ffmpeg_exit(1);
@@ -3582,7 +3584,7 @@ static void new_subtitle_stream(AVFormatContext *oc)
     AVStream *st;
     AVCodecContext *subtitle_enc;
 
-    st = av_new_stream(oc, streamid_map[oc->nb_streams]);
+    st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
     if (!st) {
         fprintf(stderr, "Could not alloc stream\n");
         ffmpeg_exit(1);
@@ -3669,6 +3671,7 @@ static void opt_streamid(const char *opt, const char *arg)
     }
     *p++ = '\0';
     idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
+    GROW_ARRAY(streamid_map, idx+1);
     streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
 }
 
@@ -3820,7 +3823,7 @@ static void opt_output_file(const char *filename)
 
     set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);
 
-    memset(streamid_map, 0, sizeof(streamid_map));
+    nb_streamid_map = 0;
 }
 
 /* same option as mencoder */
-- 
1.7.1




More information about the ffmpeg-devel mailing list