3

I am trying to create a simple overlay graphic where the overlay moves and screen and changes speed according to time. So I tried a simple

ffmpeg -i input.mp4 -vcodec qtrle -i overlay.mov -filter_complex '[0:0][1:0]overlay=x=if(t<2\,t*3\,t*5)[out]' -map '[out]' -y output.mp4

and got an error code of :

[Parsed_overlay_0 @ 0000003f4e1e2ea0] [Eval @ 0000003f4c0fe5b0] Missing ')' or too many args in 'if(t<2,t*3,t*5)'

[Parsed_overlay_0 @ 0000003f4e1e2ea0] Error when evaluating the expression 'if(t<2,t*3,t*5)' for x

[Parsed_overlay_0 @ 0000003f4e1e2ea0] Failed to configure input pad on Parsed_overlay_0

Error configuring complex filters.

Invalid argument

if I remove the "if" part and just leave a formula it works :

-filter_complex '[0:0][1:0]overlay=x=12+t*3[out]'

I tried playing with escaping of the different characters but it doesn't look like its a parsing error. Any ideas of how to use this correctly? The ffmpeg documentation has a sample for doing font color expression with a logical value here , but any attempt at

overlay=x_expr

doesn't really work as well

please help

Thanks in advance

2 Answers 2

4

FFmpeg uses functions, rather than operators, for conditional execution and comparisons, so t<2 is not a valid syntax.

The syntax for your given command would be

ffmpeg -i input.mp4 -i overlay.mov -filter_complex \
       "[0][1]overlay=x=if(lt(t\,2)\,t*3\,t*5)[out]" \
       -map '[out]' -c:v qtrle -y output.mp4

where lt(var,value) is the less than function.

2
  • Sure. How did your earlier project - drawtext - go?
    – Gyan
    May 28, 2016 at 9:50
  • hehe nice that you remembered. We ended doing a fade in fade out on the text, the character by character thing didn't work out. And we ended doing everything in house...not much ffmpeg available for out sourcing.
    – eof
    May 28, 2016 at 17:29
2

Here's an example of how to crop landscape videos to square (1:1 aspect), while not cropping portrait videos:

-filter_complex "[0:v]crop='if(lt(in_h,in_w),in_h,in_w):in_h'[out]"

4
  • The Q isn't about cropping videos !?
    – Gyan
    Apr 13, 2018 at 8:20
  • 1
    The question is about using logical conditions in FFMPEG - so this is yet another example that people may find useful
    – atyachin
    Apr 14, 2018 at 11:01
  • This a Q and A site, not a wiki, so the As are supposed to be As for the Q posted.
    – Gyan
    Apr 14, 2018 at 11:37
  • I actually found it much useful
    – Jonas
    Aug 20, 2018 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.