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

Stefano Sabatini stefano.sabatini-lala
Wed Jul 21 17:59:11 CEST 2010


This guarantee 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 |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 08acd8a..c677bd0 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -332,6 +332,7 @@ static struct termios oldtty;
 #if CONFIG_AVFILTER
 typedef struct {
     int pix_fmt;
+    AVRational time_base;
 } FilterOutPriv;
 
 
@@ -340,8 +341,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;
 }
@@ -359,6 +359,14 @@ static int output_query_formats(AVFilterContext *ctx)
     return 0;
 }
 
+static int output_config_props(AVFilterLink *inlink)
+{
+    FilterOutPriv *priv  = inlink->dst->priv;
+    inlink->dst->input_pads[inlink->dstpad].time_base = priv->time_base;
+
+    return 0;
+}
+
 static int get_filtered_video_pic(AVFilterContext *ctx,
                                   AVFilterPicRef **picref, AVFrame *pic2,
                                   uint64_t *pts)
@@ -393,6 +401,7 @@ static AVFilter output_filter =
 
     .inputs    = (AVFilterPad[]) {{ .name          = "default",
                                     .type          = AVMEDIA_TYPE_VIDEO,
+                                    .config_props  = output_config_props,
                                     .end_frame     = output_end_frame,
                                     .min_perms     = AV_PERM_READ, },
                                   { .name = NULL }},
@@ -405,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];
 
     graph = av_mallocz(sizeof(AVFilterGraph));
@@ -419,7 +429,7 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
              ist->st->time_base.num, ist->st->time_base.den);
     if (avfilter_init_filter(ist->input_video_filter, args, NULL))
         return -1;
-    if (avfilter_init_filter(ist->out_video_filter, NULL, &codec->pix_fmt))
+    if (avfilter_init_filter(ist->out_video_filter, NULL, &output_filter_priv))
         return -1;
 
     /* add input and output filters to the overall graph */
-- 
1.6.0.4




More information about the ffmpeg-devel mailing list