Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center crop a video thumbnail (Square thumbnail) in ffmpeg?

I am new to ffmpeg and I want to create a square thumbnail of size 500x500 by cropping the center of the video, irrespective of width and height. How can I achieve this? Thanks in advance.

like image 942
WebDiva Avatar asked Sep 11 '20 16:09

WebDiva


People also ask

How do I crop an image in ffmpeg?

"crop=w:h:x:y" specifies that we are using the crop video filter where w is the width you want after cropping the image, h is the height of the cropped image, x is the horizontal position from where the cropping starts and y is the horizontal position from where the image cropping starts.

How do I crop an image using FFmpeg?

1 Answer 1 ActiveOldestVotes 457 Use the cropfilter: ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4 Where the options are as follows: out_wis the width of the output rectangle out_his the height of the output rectangle xand yspecify the top left corner of the output rectangle Original image

How to take thumbnails and screenshots using FFmpeg?

Thumbnails & Screenshots using FFmpeg – 3 Efficient Techniques 1 Periodic Screenshot/Thumbnail with Resizing. Here is another common use case that FFmpeg can solve easily – how do you take screenshots/thumbnails at regular intervals, and store them to JPG files ... 2 Screenshot/Thumbnail every 10 seconds. ... 3 Conclusion. ...

How to scale an image using FFmpeg?

1) Image Scaling For reducing or increasing size of an image we can use ffmpeg by this command 1. ffmpeg-i input. png-vf scale=w:h output. png 2. //where-i is input parameter, w is width of image in pixels, h is height of image in pixels and output. png output file name 3. eg. ffmpeg-i input. png-vf scale=310:240 output. png.

How to crop 100x100 pixels from the top left of video?

FFmpeg crop example: crop a section of 100x100 from the top left of the video. To crop a section of 100x100 pixels from the top left (so the x and y are 0) of a video, use: ffmpeg -i input.mp4 -filter:v "crop=100:100:0:0" output.mp4 FFmpeg crop example: crop the 100x100 pixels top right section of a video.


Video Answer


1 Answers

First crop, then scale.

ffmpeg -i in -vf "crop=w='min(min(iw\,ih)\,500)':h='min(min(iw\,ih)\,500)',scale=500:500,setsar=1" -vframes 1 thumbnail.jpg

x and y for crop aren't set as they default to center crop.


ffmpeg -i in -vf "crop=w='min(iw\,ih)':h='min(iw\,ih)',scale=500:500,setsar=1" -vframes 1 thumbnail.jpg

This will select the largest square possible and scalethat to 500x500.

like image 61
Gyan Avatar answered Oct 16 '22 02:10

Gyan