From: Stefano Sabatini <[email protected]>
avfilter_copy_frame_props() avoids code duplication and increases
robustness.
---
avplay.c | 4 ++--
libavfilter/avfilter.c | 19 +++++++++++++++++++
libavfilter/avfilter.h | 9 +++++++++
libavfilter/vsrc_buffer.c | 5 +----
libavfilter/vsrc_movie.c | 5 +----
5 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/avplay.c b/avplay.c
index bf246f2..c217010 100644
--- a/avplay.c
+++ b/avplay.c
@@ -1649,9 +1649,9 @@ static int input_request_frame(AVFilterLink *link)
}
av_free_packet(&pkt);
+ avfilter_copy_frame_props(picref, priv->frame);
picref->pts = pts;
- picref->pos = pkt.pos;
- picref->video->pixel_aspect = 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.c b/libavfilter/avfilter.c
index b0304d6..d426591 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -25,6 +25,7 @@
#include "libavutil/rational.h"
#include "libavutil/audioconvert.h"
#include "libavutil/imgutils.h"
+#include "libavcodec/avcodec.h"
#include "avfilter.h"
#include "internal.h"
@@ -681,3 +682,21 @@ int avfilter_init_filter(AVFilterContext *filter, const
char *args, void *opaque
return ret;
}
+int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
+{
+ if (dst->type != AVMEDIA_TYPE_VIDEO)
+ return AVERROR(EINVAL);
+
+ dst->pts = src->pts;
+ dst->format = src->format;
+
+ dst->video->w = src->width;
+ dst->video->h = src->height;
+ dst->video->pixel_aspect = 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;
+
+ return 0;
+}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index e0c664d..a5cc8b2 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -27,6 +27,7 @@
#include "libavutil/samplefmt.h"
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"
+#include "libavcodec/avcodec.h"
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 13
@@ -862,4 +863,12 @@ static inline void avfilter_insert_outpad(AVFilterContext
*f, unsigned index,
&f->output_pads, &f->outputs, p);
}
+/**
+ * Copy the frame properties of src to dst, without copying the actual
+ * image data.
+ *
+ * @return 0 on success, a negative number on error.
+ */
+int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
+
#endif /* AVFILTER_AVFILTER_H */
diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index 1f0233e..982fed5 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -131,12 +131,9 @@ static int request_frame(AVFilterLink *link)
c->frame.data, c->frame.linesize,
picref->format, link->w, link->h);
+ avfilter_copy_frame_props(picref, &c->frame);
picref->pts = c->pts;
picref->video->pixel_aspect = c->pixel_aspect;
- 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 a176473..4ac079c 100644
--- a/libavfilter/vsrc_movie.c
+++ b/libavfilter/vsrc_movie.c
@@ -240,6 +240,7 @@ 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 */
@@ -250,10 +251,6 @@ static int movie_get_frame(AVFilterLink *outlink)
movie->picref->pos =
movie->frame->reordered_opaque;
if (!movie->frame->sample_aspect_ratio.num)
movie->picref->video->pixel_aspect =
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.7.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel