[FFmpeg-cvslog] examples/filtering_video: update to the new API
Gavin Kinsey
git at videolan.org
Tue Jun 26 19:05:06 CEST 2012
ffmpeg | branch: master | Gavin Kinsey <gkinsey at ad-holdings.co.uk> | Tue Jun 26 09:16:16 2012 +0100| [9ebed95db6c4fece96f56c10f50acf5ec47dc308] | committer: Stefano Sabatini
examples/filtering_video: update to the new API
Update the video filtering example program based on the audio one.
Signed-off-by: Stefano Sabatini <stefasab at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9ebed95db6c4fece96f56c10f50acf5ec47dc308
---
doc/examples/filtering_video.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c
index 29fb77b..0cf23be 100644
--- a/doc/examples/filtering_video.c
+++ b/doc/examples/filtering_video.c
@@ -34,6 +34,7 @@
#include <libavfilter/avfiltergraph.h>
#include <libavfilter/avcodec.h>
#include <libavfilter/buffersink.h>
+#include <libavfilter/buffersrc.h>
const char *filter_descr = "scale=78:24";
@@ -87,13 +88,17 @@ static int init_filters(const char *filters_descr)
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
enum PixelFormat pix_fmts[] = { PIX_FMT_GRAY8, PIX_FMT_NONE };
+ AVBufferSinkParams *buffersink_params;
+
filter_graph = avfilter_graph_alloc();
/* buffer video source: the decoded frames from the decoder will be inserted here. */
- snprintf(args, sizeof(args), "%d:%d:%d:%d:%d:%d:%d",
- dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
- dec_ctx->time_base.num, dec_ctx->time_base.den,
- dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);
+ snprintf(args, sizeof(args),
+ "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
+ dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
+ dec_ctx->time_base.num, dec_ctx->time_base.den,
+ dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);
+
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
args, NULL, filter_graph);
if (ret < 0) {
@@ -102,8 +107,11 @@ static int init_filters(const char *filters_descr)
}
/* buffer video sink: to terminate the filter chain. */
+ buffersink_params = av_buffersink_params_alloc();
+ buffersink_params->pixel_fmts = pix_fmts;
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
- NULL, pix_fmts, filter_graph);
+ NULL, buffersink_params, filter_graph);
+ av_free(buffersink_params);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
return ret;
@@ -201,14 +209,22 @@ int main(int argc, char **argv)
frame.pts = av_frame_get_best_effort_timestamp(&frame);
/* push the decoded frame into the filtergraph */
- av_vsrc_buffer_add_frame(buffersrc_ctx, &frame, 0);
+ if (av_buffersrc_add_frame(buffersrc_ctx, &frame, 0) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
+ break;
+ }
/* pull filtered pictures from the filtergraph */
- while (avfilter_poll_frame(buffersink_ctx->inputs[0])) {
- av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
+ while (1) {
+ ret = av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
+ if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
+ break;
+ if (ret < 0)
+ goto end;
+
if (picref) {
display_picref(picref, buffersink_ctx->inputs[0]->time_base);
- avfilter_unref_buffer(picref);
+ avfilter_unref_bufferp(&picref);
}
}
}
More information about the ffmpeg-cvslog
mailing list