[FFmpeg-cvslog] r25500 - trunk/ffmpeg.c

stefano subversion
Sat Oct 16 12:06:10 CEST 2010


Author: stefano
Date: Sat Oct 16 12:06:10 2010
New Revision: 25500

Log:
Move the allocation of the AVOutputStream structure earlier in the
code flow, in the new_video_stream() / new_audio_stream() /
new_subtitle_stream() functions.

Patch by Nicolas George <$name.$surname at normalesup.org>.

Modified:
   trunk/ffmpeg.c

Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c	Sat Oct 16 10:50:50 2010	(r25499)
+++ trunk/ffmpeg.c	Sat Oct 16 12:06:10 2010	(r25500)
@@ -300,6 +300,9 @@ typedef struct AVOutputStream {
     FILE *logfile;
 } AVOutputStream;
 
+static AVOutputStream **output_streams_for_file[MAX_FILES] = { NULL };
+static int nb_output_streams_for_file[MAX_FILES] = { 0 };
+
 typedef struct AVInputStream {
     int file_index;
     int index;
@@ -570,6 +573,7 @@ static int ffmpeg_exit(int ret)
         av_metadata_free(&s->metadata);
         av_free(s);
         av_free(bitstream_filters[i]);
+        av_free(output_streams_for_file[i]);
     }
     for(i=0;i<nb_input_files;i++) {
         av_close_input_file(input_files[i]);
@@ -2037,21 +2041,12 @@ static int transcode(AVFormatContext **o
     ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
     if (!ost_table)
         goto fail;
-    for(i=0;i<nb_ostreams;i++) {
-        ost = av_mallocz(sizeof(AVOutputStream));
-        if (!ost)
-            goto fail;
-        ost_table[i] = ost;
-    }
-
     n = 0;
     for(k=0;k<nb_output_files;k++) {
         os = output_files[k];
         for(i=0;i<os->nb_streams;i++,n++) {
             int found;
-            ost = ost_table[n];
-            ost->file_index = k;
-            ost->index = i;
+            ost = ost_table[n] = output_streams_for_file[k][i];
             ost->st = os->streams[i];
             if (nb_stream_maps > 0) {
                 ost->source_index = file_table[stream_maps[n].file_index].ist_index +
@@ -3356,9 +3351,31 @@ static void check_audio_video_sub_inputs
     *has_subtitle_ptr = has_subtitle;
 }
 
+static AVOutputStream *new_output_stream(AVFormatContext *oc, int file_idx)
+{
+    int idx = oc->nb_streams - 1;
+    AVOutputStream *ost;
+
+    output_streams_for_file[file_idx] =
+        grow_array(output_streams_for_file[file_idx],
+                   sizeof(*output_streams_for_file[file_idx]),
+                   &nb_output_streams_for_file[file_idx],
+                   oc->nb_streams);
+    ost = output_streams_for_file[file_idx][idx] =
+        av_mallocz(sizeof(AVOutputStream));
+    if (!ost) {
+        fprintf(stderr, "Could not alloc output stream\n");
+        ffmpeg_exit(1);
+    }
+    ost->file_index = file_idx;
+    ost->index = idx;
+    return ost;
+}
+
 static void new_video_stream(AVFormatContext *oc, int file_idx)
 {
     AVStream *st;
+    AVOutputStream *ost;
     AVCodecContext *video_enc;
     enum CodecID codec_id;
     AVCodec *codec= NULL;
@@ -3368,6 +3385,7 @@ static void new_video_stream(AVFormatCon
         fprintf(stderr, "Could not alloc stream\n");
         ffmpeg_exit(1);
     }
+    ost = new_output_stream(oc, file_idx);
 
     output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
     if(!video_stream_copy){
@@ -3503,6 +3521,7 @@ static void new_video_stream(AVFormatCon
 static void new_audio_stream(AVFormatContext *oc, int file_idx)
 {
     AVStream *st;
+    AVOutputStream *ost;
     AVCodec *codec= NULL;
     AVCodecContext *audio_enc;
     enum CodecID codec_id;
@@ -3512,6 +3531,7 @@ static void new_audio_stream(AVFormatCon
         fprintf(stderr, "Could not alloc stream\n");
         ffmpeg_exit(1);
     }
+    ost = new_output_stream(oc, file_idx);
 
     output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
     if(!audio_stream_copy){
@@ -3583,6 +3603,7 @@ static void new_audio_stream(AVFormatCon
 static void new_subtitle_stream(AVFormatContext *oc, int file_idx)
 {
     AVStream *st;
+    AVOutputStream *ost;
     AVCodec *codec=NULL;
     AVCodecContext *subtitle_enc;
 
@@ -3591,6 +3612,7 @@ static void new_subtitle_stream(AVFormat
         fprintf(stderr, "Could not alloc stream\n");
         ffmpeg_exit(1);
     }
+    ost = new_output_stream(oc, file_idx);
     subtitle_enc = st->codec;
     output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
     if(!subtitle_stream_copy){



More information about the ffmpeg-cvslog mailing list