[FFmpeg-devel] [PATCH] lavfi: add avfilter_copy_frame_props()

Stefano Sabatini stefano.sabatini-lala at poste.it
Sun May 1 15:56:56 CEST 2011


Avoid code duplication, increase robustness.
---
 ffplay.c                  |    4 ++--
 libavfilter/avfilter.h    |   24 ++++++++++++++++++++++++
 libavfilter/vsrc_buffer.c |    8 ++------
 libavfilter/vsrc_movie.c  |    7 +------
 4 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/ffplay.c b/ffplay.c
index 945e08f..6f41a55 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1686,9 +1686,9 @@ static int input_request_frame(AVFilterLink *link)
     }
     av_free_packet(&pkt);
 
+    avfilter_copy_frame_props(picref, priv->frame);
     picref->pts = pts;
-    picref->pos = priv->frame->pkt_pos;
-    picref->video->sample_aspect_ratio = priv->frame->sample_aspect_ratio;
+
     avfilter_start_frame(link, picref);
     avfilter_draw_slice(link, 0, link->h, 1);
     avfilter_end_frame(link);
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 5003152..7a3f54a 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -163,6 +163,30 @@ static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilt
     }
 }
 
+#if CONFIG_AVCODEC
+#include "libavcodec/avcodec.h" // AVFrame
+
+static inline
+void avfilter_copy_frame_props(AVFilterBufferRef *dst, AVFrame *src)
+{
+    /* use pkt_dts if pkt_pts is not available */
+    dst->pts    = src->pts;
+    dst->pos    = src->pkt_pos;
+    dst->format = src->format;
+
+    switch (dst->type) {
+    case AVMEDIA_TYPE_VIDEO:
+        dst->video->w                   = src->width;
+        dst->video->h                   = src->height;
+        dst->video->sample_aspect_ratio = src->sample_aspect_ratio;
+        dst->video->interlaced          = src->interlaced_frame;
+        dst->video->top_field_first     = src->top_field_first;
+        dst->video->key_frame           = src->key_frame;
+        dst->video->pict_type           = src->pict_type;
+    }
+}
+#endif
+
 /**
  * Add a new reference to a buffer.
  *
diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index 222ff81..b8c1660 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -191,13 +191,9 @@ static int request_frame(AVFilterLink *link)
     av_image_copy(picref->data, picref->linesize,
                   c->frame.data, c->frame.linesize,
                   picref->format, link->w, link->h);
+    avfilter_copy_frame_props(picref, &c->frame);
+    picref->pts = c->pts;
 
-    picref->pts                    = c->pts;
-    picref->video->sample_aspect_ratio = c->frame.sample_aspect_ratio;
-    picref->video->interlaced      = c->frame.interlaced_frame;
-    picref->video->top_field_first = c->frame.top_field_first;
-    picref->video->key_frame       = c->frame.key_frame;
-    picref->video->pict_type       = c->frame.pict_type;
     avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
     avfilter_draw_slice(link, 0, link->h, 1);
     avfilter_end_frame(link);
diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c
index e94e77d..6b4f6a4 100644
--- a/libavfilter/vsrc_movie.c
+++ b/libavfilter/vsrc_movie.c
@@ -239,20 +239,15 @@ static int movie_get_frame(AVFilterLink *outlink)
                 av_image_copy(movie->picref->data, movie->picref->linesize,
                               movie->frame->data,  movie->frame->linesize,
                               movie->picref->format, outlink->w, outlink->h);
+                avfilter_copy_frame_props(movie->picref, movie->frame);
 
                 /* FIXME: use a PTS correction mechanism as that in
                  * ffplay.c when some API will be available for that */
                 /* use pkt_dts if pkt_pts is not available */
                 movie->picref->pts = movie->frame->pkt_pts == AV_NOPTS_VALUE ?
                     movie->frame->pkt_dts : movie->frame->pkt_pts;
-
-                movie->picref->pos                    = movie->frame->pkt_pos;
                 if (!movie->frame->sample_aspect_ratio.num)
                     movie->picref->video->sample_aspect_ratio = st->sample_aspect_ratio;
-                movie->picref->video->interlaced      = movie->frame->interlaced_frame;
-                movie->picref->video->top_field_first = movie->frame->top_field_first;
-                movie->picref->video->key_frame       = movie->frame->key_frame;
-                movie->picref->video->pict_type       = movie->frame->pict_type;
                 av_dlog(outlink->src,
                         "movie_get_frame(): file:'%s' pts:%"PRId64" time:%lf pos:%"PRId64" aspect:%d/%d\n",
                         movie->file_name, movie->picref->pts,
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list