Video Resizing With ffmpeg
For a recent work project, I had to downscale a video to a fixed size to
fit into our application as designed. Though I didn’t know the exact
options, I new this was a perfect task for my good friend ffmpeg
.
ffmpeg -i input.mp4 -vf "scale=400:600:force_original_aspect_ratio=decrease,pad=400:600:(ow-iw)/2:(oh-ih)/2:0xEFEFEF" output.mp4
Below is an explanation of each of the options in the above command:
scale=400:600
- Scales the video to 400px wide by 600px tall.force_original_aspect_ratio=decrease
- Downscales the video to the specified size while maintaining the original aspect ratio.pad=400:600
- Adds padding to the video to achieve the target resolution, filling the extra space with a specified color.(ow-iw)/2:(oh-ih)/2
- Centers the video horizontally and vertically.ow
is the output width,iw
is the input width, etc.color=0x0000FF
- Specifies the padding color.