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

<p><code>-filter_complex "[0:v]crop='if(lt(in_h,in_w),in_h,in_w):in_h'[out]"</code></p>

CC BY-SA 3.0
2018-04-13T08:20:10.750Z
The Q isn't about cropping videos !?
Gyan
CC BY-SA 3.0
2018-04-14T11:01:29.577Z
The question is about using logical conditions in FFMPEG - so this is yet another example that people may find useful
atyachin
CC BY-SA 3.0
2018-04-14T11:37:33.873Z
This a Q and A site, not a wiki, so the As are supposed to be As for the Q posted.
Gyan
CC BY-SA 4.0
2018-08-20T04:42:20.197Z
I actually found it much useful
Jonas
CC BY-SA 3.0
2018-04-12T11:56:28.237Z
2018-04-13T00:59:48.763Z
2018-04-13T00:59:48.763Z
atyachin
<p>FFmpeg uses functions, rather than operators, for conditional execution and comparisons, so <code>t&lt;2</code> is not a valid syntax. </p>

<p>The syntax for your given command would be</p>

<pre><code>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
</code></pre>

<p>where <code>lt(var,value)</code> is the <code>less than</code> function. </p>

CC BY-SA 3.0
2016-05-28T09:50:51.303Z
Sure. How did your earlier project - drawtext - go?
Gyan
CC BY-SA 3.0
2016-05-28T17:29:34.740Z
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
CC BY-SA 3.0
2016-05-28T08:33:43.700Z
2016-05-28T08:33:43.700Z
Gyan
<p>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 </p>

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

<p>and got an error code of :</p>

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

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

<p>[Parsed_overlay_0 @ 0000003f4e1e2ea0] Failed to configure input pad on Parsed_overlay_0</p>

<p>Error configuring complex filters.</p>

<p>Invalid argument</p>

<p>if I remove the "if" part and just leave a formula it works :</p>

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

<p>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 <a href="https://ffmpeg.org/ffmpeg-all.html#Examples-80" rel="nofollow">here</a> , but any attempt at </p>

<p>overlay=x_expr</p>

<p>doesn't really work as well</p>

<p>please help</p>

<p>Thanks in advance</p>

<ffmpeg>
ffmpeg overlay x expression with logical condition
eof
# ffmpeg overlay x expression with logical condition

(Asked by: username_0 on 2016-05-28)

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](https://ffmpeg.org/ffmpeg-all.html#Examples-80) , but any attempt at

overlay=x\_expr

doesn't really work as well

please help

Thanks in advance

**Tags:** ffmpeg


---

## 2 answers

### Answer by username_2 on 2016-05-28. Score: 4 | Accepted answer

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.

> **Comments:**
> **username_2**: Sure. How did your earlier project - drawtext - go?  
> **username_0**: 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.  

---

### Answer by username_1 on 2018-04-12. Score: 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]"`

> **Comments:**
> **username_2**: The Q isn't about cropping videos !?  
> **username_1**: The question is about using logical conditions in FFMPEG - so this is yet another example that people may find useful  
> **username_2**: This a Q and A site, not a wiki, so the As are supposed to be As for the Q posted.  
> **username_3**: I actually found it much useful  

---

