Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg: scale output cropped width/height doesn't work [closed]

Tags:

scale

ffmpeg

crop

I'm trying to crop video frames with ffmpeg, and I would like to scale the cropped image automatically. I saw an option at 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 receive an error: Error when evaluating the expression 'oh'

like image 577
Mauro Gerenstadt Avatar asked Aug 07 '11 10:08

Mauro Gerenstadt


2 Answers

Try this:

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

Above code will first scale the video to 640 and maintain the aspect ratio height, then crop to 640x480.

like image 138
Won Yee How Avatar answered Nov 14 '22 10:11

Won Yee How


I assume you're getting:

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

Because you try to set the output w/h to the output w/h?! 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, setting the output w/h to what the input width (iw) and input height (ih) was.

Note that you will get an error if the source video is smaller than what you try to crop to (640:480). You may use ffmpeg's expression syntax to first check if a crop/scale is necessary to avoid this error.

like image 44
MyGGaN Avatar answered Nov 14 '22 10:11

MyGGaN