Ffmpeg: scaled output cropped width / height not working

I am trying to crop video frames using ffmpeg and I would like to automatically scale the cropped image. I saw the option in the av filter: http://ffmpeg.org/libavfilter.html#SEC41

./ffmpeg -i video.mp4 -vf "crop = 640: 480, scale = ow: oh " -f mpegts udp: //127.0.0.1: 1234

I get an error: Error evaluating expression 'oh'

+6
source share
3 answers

Try the following:

./ffmpeg -i video.mp4 -vf "scale=640:ih*640/iw, crop=640:480" -f mpegts udp://127.0.0.1:1234 

Above, the code first scales the video to 640 and supports the height of the image format, then we crop it to 640x480.

+19
source

I assume you get:

 Error when evaluating the expression 'oh'. Maybe the expression for out_w:'ow' or for out_h:'oh' is self-referencing. 

Because you are trying to set the w / h output to the w / h output ?! What you want to do is

 ffmpeg -i video.mp4 -vf "crop=640:480,scale=iw:ih" -f mpegts udp://127.0.0.1:1234 

That is, by setting the output w / h to what the input width (iw) and the input height (ih) were.

Please note that you will receive an error message if the original video is less than what you are trying to trim (640: 480). You can use the ffmpeg expression syntax to first check if cropping / scaling is needed to avoid this error.

+2
source

You really need to replace ow and oh with numbers representing the width and height to scale the video accordingly.

0
source

Source: https://habr.com/ru/post/894478/


All Articles