Changing the crop filter's output width over time?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing the crop filter's output width over time?

John Hawkinson
I wanted to execute zoom-and-pan out over a few seconds by parametrizing the width and height of the crop filter via sendcmd (the result of which would then be handed to a scale filter), and when I try to do this, I get errors that I don't understand.

When I use:

  sendcmd=c='0-1 crop w 1146+t*(1920-1146), crop h 1080'

I get:

  Error when evaluating the expression '1146+t*(1920-1146)'

When I use

  sendcmd=c='0-1 crop w 1146+T*(1920-1146), crop h 1080'

I get:

  Unknown function in 'T*(1920-1146)'
  Error when evaluating the expression '1146+T*(1920-1146)'

Neither of these seem to make sense to me. The crop filter docs indicate it takes the parameter 't', and the general eval api docs refer to 'T'. I'm not sure which (or both?) applies, but both fail in odd ways.

Same problem with a simpler exmpression like '1146+T'.

What am I doing wrong? Console output below.


I ultimately managed to get the zoompad filter to work for me, but it doesn't really seem designed to work well with video (rather than a still). I ended up using

  zoompan=z=if(eq(pzoom\,1)\,1.8\,max(pzoom-0.0025\,1.01)):x='iw/2-(iw/zoom/2)+60':y='ih/2-(ih/zoom/2)-120':d=1:fps=30,

where if I didn't specify the fps rate, it desynced my audio and video, and the expression necessary to make it work, depending on pzoom, and specifying the zoom steps...just felt fragile. (On the other hand, presumably it's more performant than a crop filter followed by a scale filer).

Thanks you.

--
[hidden email]
John Hawkinson

$ sh -x diag.sh
+ ffplay -i v -vf '
  sendcmd=c='\''0-1 crop w 1146+T, crop h 1080'\'',
  crop=
    1146:644:
    456-clip(t\,0\,1)*456:
     73-clip(t\,0\,1)*73'
ffplay version 4.2.2 Copyright (c) 2003-2019 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libzvbi
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, matroska,webm, from 'v':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    ENCODER         : Lavf58.29.100
  Duration: 00:04:30.30, start: -0.007000, bitrate: 2977 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
    Metadata:
      HANDLER_NAME    : ISO Media file produced by Google Inc.
      DURATION        : 00:04:30.270000000
    Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:04:30.301000000
[Parsed_crop_1 @ 0x7f7f8d7955c0] [Eval @ 0x7000072cedb0] Undefined constant or missing '(' in 'T'
Error when evaluating the expression '1146+T'
[Parsed_crop_1 @ 0x7f7f8d7955c0] [Eval @ 0x7000072cedb0] Undefined constant or missing '(' in 'T'
Error when evaluating the expression '1146+T'
Switch subtitle stream from #-1 to #-1 vq=  162KB sq=    0B f=0/0  
   2.09 A-V: -0.030 fd=   5 aq=   20KB vq=  143KB sq=    0B f=0/0  
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Changing the crop filter's output width over time?

Gyan Doshi-2


On 26-04-2020 10:51 am, John Hawkinson wrote:

> I wanted to execute zoom-and-pan out over a few seconds by parametrizing the width and height of the crop filter via sendcmd (the result of which would then be handed to a scale filter), and when I try to do this, I get errors that I don't understand.
>
> When I use:
>
>    sendcmd=c='0-1 crop w 1146+t*(1920-1146), crop h 1080'
>
> I get:
>
>    Error when evaluating the expression '1146+t*(1920-1146)'
>
> When I use
>
>    sendcmd=c='0-1 crop w 1146+T*(1920-1146), crop h 1080'
>
> I get:
>
>    Unknown function in 'T*(1920-1146)'
>    Error when evaluating the expression '1146+T*(1920-1146)'
>
> Neither of these seem to make sense to me. The crop filter docs indicate it takes the parameter 't', and the general eval api docs refer to 'T'. I'm not sure which (or both?) applies, but both fail in odd ways.
>
> Same problem with a simpler exmpression like '1146+T'.
>
> What am I doing wrong? Console output below.

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.

Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Changing the crop filter's output width over time?

John Hawkinson
Gyan Doshi <[hidden email]> wrote on Sun, 26 Apr 2020
at 02:03:23 EDT in <[hidden email]>:

> 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'

Upon further review, I wonder if the parser is trying to parse T as the 10^9 SI prefix, although that doesn't quite explain it. And there's not even a detailed error message for the '1146+t' form.


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."

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.

Maybe I'm missing something.

Thanks.

--
[hidden email]
John Hawkinson
+1 617 797 0250
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Changing the crop filter's output width over time?

Gyan Doshi-2


On 26-04-2020 06:07 pm, John Hawkinson wrote:

> Gyan Doshi <[hidden email]> wrote on Sun, 26 Apr 2020
> at 02:03:23 EDT in <[hidden email]>:
>
>> 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.

Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".