[FFmpeg-cvslog] ffmpeg: don't abuse a global for passing framerate from input to output

Anton Khirnov git at videolan.org
Thu Jun 16 04:54:02 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Jun 15 08:00:03 2011 +0200| [a6286bda0956bfe15b4e1a9f96e1689666e1d866] | committer: Anton Khirnov

ffmpeg: don't abuse a global for passing framerate from input to output

It's broken with multiple files or video streams.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a6286bda0956bfe15b4e1a9f96e1689666e1d866
---

 ffmpeg.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 3ed5789..1b31d56 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -271,6 +271,7 @@ typedef struct AVOutputStream {
     int resample_height;
     int resample_width;
     int resample_pix_fmt;
+    AVRational frame_rate;
 
     float frame_aspect_ratio;
 
@@ -2226,6 +2227,14 @@ static int transcode(AVFormatContext **output_files,
                 ost->encoding_needed = 1;
                 ist->decoding_needed = 1;
 
+                if (!ost->frame_rate.num)
+                    ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};
+                if (codec->codec && codec->codec->supported_framerates && !force_fps) {
+                    int idx = av_find_nearest_q_idx(ost->frame_rate, codec->codec->supported_framerates);
+                    ost->frame_rate = codec->codec->supported_framerates[idx];
+                }
+                codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};
+
 #if CONFIG_AVFILTER
                 if (configure_video_filters(ist, ost)) {
                     fprintf(stderr, "Error opening filters!\n");
@@ -3308,9 +3317,6 @@ static int opt_input_file(const char *opt, const char *filename)
 
                     (float)rfps / rfps_base, rfps, rfps_base);
             }
-            /* update the current frame rate to match the stream frame rate */
-            frame_rate.num = rfps;
-            frame_rate.den = rfps_base;
 
             if(video_disable)
                 st->discard= AVDISCARD_ALL;
@@ -3342,6 +3348,7 @@ static int opt_input_file(const char *opt, const char *filename)
     input_files[nb_input_files - 1].ist_index  = nb_input_streams - ic->nb_streams;
 
     video_channel = 0;
+    frame_rate    = (AVRational){0, 0};
     audio_sample_rate = 0;
     audio_channels    = 0;
 
@@ -3455,16 +3462,12 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
     } else {
         const char *p;
         int i;
-        AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
 
+        if (frame_rate.num)
+            ost->frame_rate = frame_rate;
         video_enc->codec_id = codec_id;
         set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
 
-        if (codec && codec->supported_framerates && !force_fps)
-            fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];
-        video_enc->time_base.den = fps.num;
-        video_enc->time_base.num = fps.den;
-
         video_enc->width = frame_width;
         video_enc->height = frame_height;
         video_enc->pix_fmt = frame_pix_fmt;
@@ -3891,6 +3894,7 @@ static void opt_output_file(const char *filename)
 
     set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
 
+    frame_rate    = (AVRational){0, 0};
     audio_sample_rate = 0;
     audio_channels    = 0;
 



More information about the ffmpeg-cvslog mailing list