[Libav-user] Changing video filter parameter at runtime

Gabriele Greco gabriele.greco at wyscout.com
Wed Feb 8 16:13:16 EET 2017


It seems I've found the solution by myself looking inside* vf_scale.c*,
I'll post the answer anyway for future references:

It seems that the correct way to modify an argument of a filter is to send
a command to it, through the API *avfilter_graph_send_command()*.

The scale filter supports only "width" and "height", but that's more than
enough for my needs, so the code to change the filter when the output
widget size changes is simply:

 if (avfilter_graph_send_command(filter_graph_, "Parsed_scale_1", "width",
to_string(img_.Width()).c_str(), NULL, 0, 0) < 0)
     ELOG << "Error setting new width!";

 if (avfilter_graph_send_command(filter_graph_, "Parsed_scale_1", "height",
to_string(img_.Height()).c_str(), NULL, 0, 0) < 0)
     ELOG << "Error setting new height!";


2017-02-08 14:22 GMT+01:00 Gabriele Greco <gabriele.greco at wyscout.com>:

> Hello everybody,
>
> I've setup a filter chain in my program to deinterlace and scale the video
> frame before rendering, it works very well, and the code is faster that the
> custom deinterlace/scale that I used before, the problem I have is that I
> need to change the filter when the window is resized, here is the filter,
> as dumped by avfilter_graph_dump:
>
> +----------+
> |    in    |default--[720x576 64:45 yuv420p]--Parsed_yadif_0:default
> | (buffer) |
> +----------+
>
>                                                    +--------------+
> Parsed_scale_1:default--[800x450 1:1 argb]--default|     out      |
>                                                    | (buffersink) |
>                                                    +--------------+
>
>                                             +----------------+
> in:default--[720x576 64:45 yuv420p]--default| Parsed_yadif_0
> |default--[720x576 64:45 yuv420p]--Parsed_scale_1:default
>                                             |    (yadif)     |
>                                             +----------------+
>
>                                                         +----------------+
> Parsed_yadif_0:default--[720x576 64:45 yuv420p]--default| Parsed_scale_1
> |default--[800x450 1:1 argb]--out:default
>                                                         |    (scale)     |
>                                                         +----------------+
>
>
> When a resize event occurs I'm trying to change it in this way:
>
>     if (AVFilterContext *ctx = avfilter_graph_get_filter(filter_graph_,
> "Parsed_scale_1")) {
>         std::ostringstream os;
>         os << "w=" << img_.Width() << ":h=" << img_.Height() << ":eval";
>         // passes w=XXX:h=YYY:eval to the filter
>         if (avfilter_init_str(ctx, os.str().c_str()) < 0) {
>             ELOG << "Unable to reinit filter!";
>         }
>          }
>     else
>         ELOG << "Unable to find filter!";
>
> ... no error is reported but the filter is not changed after the call...
>
> Note that I added to the filter the "eval" option since I read in the
> filter documentation that otherwise the size is evaluated only for the
> first frame...
>
> I've tried to read through the avfilter documentation but I cannot find a
> specific function to do that, I hope that the only way to do that is not to
> delete all the filtergraph and rebuild it, I can do it if needed but I've a
> few concerns about the AVFilterInOut inputs/outputs, if they need to be
> freed or not, avfilter_graph_parse_ptr says it should not be freed by user,
> avfilter_graph_parse says it should...
>
> Thanks in advance!
>
> --
> *Bye,*
> *Gabriele Greco*
>
>


-- 
*Gabriele Greco*

*Senior Software Engineer - Mobile Division*Mobile: *+39 3391941700*
Website:  www.wyscout.com
[image: Descrizione: Descrizione: Descrizione: Descrizione:
Logo_Wyscout_Nero_firma]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20170208/09570adf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: application/octet-stream
Size: 2845 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20170208/09570adf/attachment.obj>


More information about the Libav-user mailing list