lavfi: add video buffer sink, and use it in avtools

Also add the public interface libavfilter/buffersink.h.

Based on a commit by Stefano Sabatini.
This commit is contained in:
Anton Khirnov
2012-04-27 06:56:56 +02:00
parent ab165047a6
commit ac71230902
10 changed files with 267 additions and 122 deletions

View File

@ -1021,74 +1021,6 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
return opts;
}
#if CONFIG_AVFILTER
static int sink_init(AVFilterContext *ctx, const char *args, void *opaque)
{
SinkContext *priv = ctx->priv;
if (!opaque)
return AVERROR(EINVAL);
*priv = *(SinkContext *)opaque;
return 0;
}
static void null_end_frame(AVFilterLink *inlink) { }
static int sink_query_formats(AVFilterContext *ctx)
{
SinkContext *priv = ctx->priv;
if (priv->pix_fmts)
avfilter_set_common_formats(ctx, avfilter_make_format_list(priv->pix_fmts));
else
avfilter_default_query_formats(ctx);
return 0;
}
AVFilter sink = {
.name = "sink",
.priv_size = sizeof(SinkContext),
.init = sink_init,
.query_formats = sink_query_formats,
.inputs = (AVFilterPad[]) {{ .name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.end_frame = null_end_frame,
.min_perms = AV_PERM_READ, },
{ .name = NULL }},
.outputs = (AVFilterPad[]) {{ .name = NULL }},
};
int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
AVFilterBufferRef **picref_ptr, AVRational *tb)
{
int ret;
AVFilterBufferRef *picref;
if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0)
return ret;
if (!(picref = ctx->inputs[0]->cur_buf))
return AVERROR(ENOENT);
*picref_ptr = picref;
ctx->inputs[0]->cur_buf = NULL;
*tb = ctx->inputs[0]->time_base;
memcpy(frame->data, picref->data, sizeof(frame->data));
memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
frame->interlaced_frame = picref->video->interlaced;
frame->top_field_first = picref->video->top_field_first;
frame->key_frame = picref->video->key_frame;
frame->pict_type = picref->video->pict_type;
frame->sample_aspect_ratio = picref->video->pixel_aspect;
return 1;
}
#endif /* CONFIG_AVFILTER */
void *grow_array(void *array, int elem_size, int *size, int new_size)
{
if (new_size >= INT_MAX / elem_size) {