[FFmpeg-user] Changing the crop filter's output width over time?

Gyan Doshi ffmpeg at gyani.pro
Sun Apr 26 16:44:36 EEST 2020

On 26-04-2020 06:07 pm, John Hawkinson wrote:
> Gyan Doshi <ffmpeg at gyani.pro> wrote on Sun, 26 Apr 2020
> at 02:03:23 EDT in <76dff16c-331a-534c-fe28-558dae8a8d5b at gyani.pro>:
>> The temporal parameters t, n and pos are only applicable for x and y
>> expressions. At present, the only way to vary w and h over time is by
>> sending commands with varying constants for w/h. Not very convenient, I
>> know. Open a ticket if you want an enhancement for the crop filter.
> Thanks, that's clear enough.
> It would appear that there is both a documentation bug (the crop filter's doc says "The out_w, out_h, x, y parameters are expressions containing the following constants" and includes a list with n, pos, and t), and also either bugs or odd limitations in the error reporting.
> These errors don't seem to make sense:
>    Undefined constant or missing '(' in 'T'
>      Error when evaluating the expression '1146+T'
>    Unknown function in 'T*(1920-1146)'
>      Error when evaluating the expression '1146+T*(1920-1146)'
>    Error when evaluating the expression '1146+t'
There is a generic expression evaluator which can be used by clients 
such as a filter. It basically carries out two tasks:  1) accept a 
string and an array of symbols and generate a parsed expression which is 
ready to be mathematically evaluated when values have been provided that 
correspond to those symbols. 2) accept a parsed expression and an array 
of values and generate a numerical value (when possible, else return 
value of NaN and an error). The first task matches by literals so it is 
case-sensitive. Crop uses 't' for time, not 'T'. The evaluator does not 
know the specific semantics so all it can complain about is that a 
symbol is not recognized.

> As for code enhancements, it seems to me that it would be more valuable to focus on the zoompan filter?
> For instance, I would like to:
> * give it a duration for the entire zoom effect (in frames or seconds, just like fade and oher filters
> * specify a starting and ending zoom factor, rather than the current zoom factor and calculate an expression to
> parameterize steps, which needs clip() or max() and other awkward functions
> * Not force me hard-code the fps. Since fps isn't available in the expression parser, there seesm no way to make zoompan operate properly on video input without a preprocessing step to check the fps of the input video.
> * Similarly, a way to not hard-code the resolution, although I assume s=(iw)x(ih) might work, although maybe the parser wouldn't be happy?
> It also seems the filter could use a clearer definition than "Apply Zoom & Pan effect."

zoompan is maintained by Paul Mahol. Best to ask him about it.

> Philosophically, I kind of wonder why "crop", "scale", and "zoompan" are 3 separate filters. It would seem that "zoompan" could do the same work as a chain of crop and scale, so I have to imagine one method is more efficeint than the other, but the arbitrary differences in parameters and evaluable expressions just feel odd.

All filters were independently written at different times by different 
devs. And typically, the idea is to let each module do one thing.  
zoompan does do scaling post-zoom but that's because the filtering 
framework doesn't allow filters to "insert" a filter within the graph, 
so Paul added a direct call to the scaling library with limited options 
as compared to the scale filter.


More information about the ffmpeg-user mailing list