Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For creating a video thumbnail with ffmpeg I'm using this command:

ffmpeg -itsoffset -4 -i video.mp4 -vframes 1 thumb.jpg

This gives me a thumbnail with the same size of the video (which has an unknown size, e.g. 960x540). But what I need is a square (cropped) thumbnail with a given size (e.g. 200x200). The result must not be resized, but cropped from the center, and the aspect ratio should not change.

How can this be accomplished?

share|improve this question

migrated from stackoverflow.com Jun 28 '13 at 0:24

This question came from our site for professional and enthusiast programmers.

    
Why use -itsoffset instead of -ss? I've seen an increased usage of this lately by users making image outputs from videos. – LordNeckbeard Jun 27 '13 at 17:58
    
@LordNeckbeard: Sorry, mixed up the options. Found this for more info about -itsoffset vs. -ss: superuser.com/questions/538031/… – Georg Ledermann Jun 28 '13 at 5:12
up vote 7 down vote accepted

You can use the crop video filter:

ffmpeg -ss 4 -i video.mp4 -vf crop=200:200 -vframes 1 output.jpg
  • By default the crop will be centered.

  • Use -ss instead of -itsoffset to choose your offset time.

  • You can control JPEG output quality with -qscale:v. Using a value of 2-5 is usually good; a lower value is a higher quality.

  • The crop filter can also accept the input and output width and height as values: iw, ih, ow, oh. This allows more flexible and creative filtering: crop=iw-100:ih-50.

You can test with ffplay to get a preview:

ffplay video.mp4 -vf crop=200:200

Original image (generated with the testsrc source filter:

ffmpeg -f lavfi -i testsrc -vframes 1 output.jpg 

original image

Cropped image:
cropped image

share|improve this answer
    
Great answer. Works fine, thanks a lot! – Georg Ledermann Jun 28 '13 at 5:22

You can scale it first and then crop it for better output ;)

ffmpeg -ss 10 -i "Ali_Video.mp4" -vframes 1 -filter "scale=-1:300,crop=400:300" "output.jpg"

input video at 0:49 output image

ffmpeg -ss 10 -i "Ali_Video.mp4" -vframes 1 -filter "scale=-1:150,crop=200:150" "output.jpg"

another thumbnail

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .