[Libav-user] Watermarks implementation

Andrey Mochenov andrey2067 at gmail.com
Sun Aug 18 13:20:39 CEST 2013

Hi Paul,

Thank you for your answer. So, I have tried to use overlay filter.
I use two "buffer" filters for its inputs and one "buffersink" filter for
its ouput, as shown in the code below.
The problem is that the avfilter_graph_config() command causes the error:
'Output pad "default" with type video of the filter instance
of buffer not connected to any destination.'

AVFormatContext *fmt_ctx_main;
AVCodecContext *dec_ctx_main;
AVFormatContext *fmt_ctx_wtrmrk;
AVCodecContext *dec_ctx_wtrmrk;
AVFilterContext *buffersink_ctx = NULL;
AVFilterContext *buffersrc_ctx = NULL;
AVFilterContext *bufferovrlay_ctx = NULL;
AVFilterGraph *filter_graph = NULL;

// All fmt_ctx_main, dec_ctx_main, fmt_ctx_wtrmrk, dec_ctx_wtrmrk
initializations are OK.

char argsStrMain[512] = "";
char argsStrOvrlay[512] = "";
int ret = 0;

AVFilter *buffersrc = avfilter_get_by_name("buffer");
AVFilter *bufferovrlay = avfilter_get_by_name("buffer");
AVFilter *buffersink = avfilter_get_by_name("buffersink");

AVFilterInOut *inputs = avfilter_inout_alloc();
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *outputOvrlay = avfilter_inout_alloc();

enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE};

AVBufferSinkParams *buffersink_params = NULL;

sprintf_s(argsStrMain, sizeof(argsStrMain),
          dec_ctx_main->width, dec_ctx_main->height, dec_ctx_main->pix_fmt,
          dec_ctx_main->time_base.num, dec_ctx_main->time_base.den,

sprintf_s(argsStrOvrlay, sizeof(argsStrOvrlay),
          dec_ctx_wtrmrk->width, dec_ctx_wtrmrk->height,
          dec_ctx_wtrmrk->time_base.num, dec_ctx_wtrmrk->time_base.den,

buffersink_params = av_buffersink_params_alloc();
buffersink_params->pixel_fmts = pix_fmts;

filter_graph = avfilter_graph_alloc();

ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc,
"input_main_filter", argsStrMain, NULL, filter_graph);
ret = avfilter_graph_create_filter(&bufferovrlay_ctx, bufferovrlay,
"input_overlay_filter", argsStrOvrlay, NULL, filter_graph);
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink,
"output_filter", NULL, buffersink_params, filter_graph);

outputs->name = av_strdup("in");
outputs->filter_ctx = buffersrc_ctx;
outputs->pad_idx    = 0;
outputs->next       = outputOvrlay;

outputOvrlay->name = av_strdup("overlay");   // unique name for this
input/output in the list
outputs->filter_ctx = bufferovrlay_ctx;      // filter context associated
to this input/output
outputs->pad_idx    = 0;                     // index of the filt_ctx pad
to use for linking
outputs->next       = NULL;                  // next input/output in the
list, NULL if this is the last

inputs->name = av_strdup("out");
inputs->filter_ctx = buffersink_ctx;
inputs->pad_idx    = 0;
inputs->next       = NULL;

ret = avfilter_graph_parse(filter_graph, "overlay", &inputs, &outputs,

// Till now it looks all OK, but the following line causes the error:
// 'Output pad "default" with type video of the filter instance
// of buffer not connected to any destination.'
ret = avfilter_graph_config(filter_graph, NULL);

I suppose, the reason is a wrong assigment of inputs/outputs.
But what exactly is wrong? What is the right way to link two ore more
inputs to a filter like the 'overlay' one? Please, help.

On Thu, Aug 15, 2013 at 2:43 PM, Paul B Mahol <onemda at gmail.com> wrote:

>  On 8/15/13, Andrey Mochenov <andrey2067 at gmail.com> wrote:
> > Hi,
> >
> > We are using FFmpeg libraries git-ee94362 libavformat v55.2.100.
> > Our purpose is to add watermark (semi-transparent PNG image) on the
> video.
> > The corresponding option in MMpeg application is "-vf".
> >
> > Our question: How to implement the feature using FFmpeg libraries?
> By using overlay filter, there are examples how to use filters with
> libraries.
> >
> > Andrey Mochenov.
> >
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130818/a015688d/attachment.html>

More information about the Libav-user mailing list