Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg image scale then crop not working

Tags:

ffmpeg

I want to generate an image from a video, but first i want to scale it to a certain width/height then crop it to a set square size, the problem is that my new version ffmpeg doesnt seem to work with scaling first.

ffmpeg version 2.8.6-1ubuntu2

fails:

ffmpeg -y -i input.mp4 -an -ss 5 -s 150x150 -vf scale=-1:150,crop=150:150 -vframes 1 output-small.jpg

Invalid too big or non positive size for width '150' or height '150'

works:

ffmpeg -y -i input.mp4 -an -ss 5 -s 150x150 -vf crop=150:150,scale=-1:150 -vframes 1 output-small.jpg

However i cannot settle for the second command because i am generating images that could be larger then the original size (i'm creating a few different sizes for each image), therefore scale MUST come first. Anybody have any idea what changed or what i am doing wrong here?

like image 764
justin shores Avatar asked Aug 20 '16 23:08

justin shores


Video Answer


1 Answers

This may be happening because your video is portrait, and so the scaled image has width smaller than 150px. Hence the crop fails.

Also, you should skip the -s option, otherwise you're triggering two scaler executions.

Try

ffmpeg -y -i input.mp4 -ss 5 -vf scale='if(gt(iw,ih),-1,150)':'if(gt(iw,ih),150,-1)',crop=150:150 -vframes 1 output-small.jpg
like image 153
Gyan Avatar answered Oct 04 '22 23:10

Gyan