[FFmpeg-devel] [PATCH 3/5] Make the ffmpeg output video sink explicitely set the timebase.

Stefano Sabatini stefano.sabatini-lala
Mon Oct 11 12:19:37 CEST 2010


This guarantees that the timestamps of the filtered frames are
correctly rescaled,in the case a time base change happened in the
filterchain.

The FilterOutPriv private context of the output video sink is extended
accordingly, to make it contain the timebase to use for the output
filtered frames.
---
 ffmpeg.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index bfb7f7e..3981b90 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -341,6 +341,7 @@ static struct termios oldtty;
 #if CONFIG_AVFILTER
 typedef struct {
     int pix_fmt;
+    AVRational time_base;
 } FilterOutPriv;
 
 
@@ -349,8 +350,7 @@ static int output_init(AVFilterContext *ctx, const char *args, void *opaque)
     FilterOutPriv *priv = ctx->priv;
 
     if(!opaque) return -1;
-
-    priv->pix_fmt = *((int *)opaque);
+    *priv = *((FilterOutPriv *)opaque);
 
     return 0;
 }
@@ -414,6 +414,7 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
     /** filter graph containing all filters including input & output */
     AVCodecContext *codec = ost->st->codec;
     AVCodecContext *icodec = ist->st->codec;
+    FilterOutPriv output_filter_priv = { .pix_fmt = codec->pix_fmt, .time_base = ist->st->time_base };
     char args[255];
     int ret;
 
@@ -429,7 +430,7 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
              ist->st->time_base.num, ist->st->time_base.den);
     if ((ret = avfilter_init_filter(ist->input_video_filter, args, NULL)) < 0)
         return ret;
-    if ((ret = avfilter_init_filter(ist->output_video_filter, NULL, &codec->pix_fmt)) < 0)
+    if ((ret = avfilter_init_filter(ist->output_video_filter, NULL, &output_filter_priv)) < 0)
         return ret;
 
     /* add input and output filters to the overall graph */
-- 
1.7.1




More information about the ffmpeg-devel mailing list