Commit 1c9e340d authored by Stefano Sabatini's avatar Stefano Sabatini Committed by Anton Khirnov

lavfi: add avfilter_copy_frame_props()

avfilter_copy_frame_props() avoids code duplication and increases
robustness.
parent 8a4a5f6f
......@@ -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);
......
......@@ -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;
}
......@@ -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 */
......@@ -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);
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment