Resize Video
Scale, crop, and change the aspect ratio of videos.
Resize Video
FFmpeg's video filters give you precise control over dimensions, cropping, and padding. These operations are common when preparing video for different screen sizes, social media platforms, or embedding in web pages.
Scale to specific dimensions
Resize a video to exactly 1280x720 pixels.
ffmpeg -i {{in_video}} -vf "scale=1280:720" {{out_video}}This stretches or squeezes the video to fit the target dimensions. If the source has a different aspect ratio, the output will appear distorted.
Scale width with automatic height
Set the width and let FFmpeg calculate the height to preserve the original aspect ratio. Using -2 instead of -1 ensures the height is divisible by 2, which is required by H.264 and most other codecs.
ffmpeg -i {{in_video}} -vf "scale=1280:-2" {{out_video}}You can also fix the height and auto-calculate width:
ffmpeg -i {{in_video}} -vf "scale=-2:720" {{out_video}}Crop to a square
Extract a square region from the center of the video, using the height as both dimensions. This is useful for Instagram posts and profile pictures.
ffmpeg -i {{in_video}} -vf "crop=ih:ih" {{out_video}}You can crop to any size and position with crop=width:height:x:y. For example, to crop a 640x480 region from the top-left corner:
ffmpeg -i {{in_video}} -vf "crop=640:480:0:0" {{out_video}}Pad to 16:9 aspect ratio
Add black bars (letterboxing) to fit a video into a 16:9 frame without cropping. The video is centered horizontally.
ffmpeg -i {{in_video}} -vf "pad=ih*16/9:ih:(ow-iw)/2:0" {{out_video}}In the pad filter expression:
ih*16/9sets the output width to 16:9 ratio based on the input heightihkeeps the output height the same(ow-iw)/2centers the video horizontally0places the video at the top vertically
Full API example
Scale a video to 1280 pixels wide with automatic height, maintaining aspect ratio.
curl -X POST https://renderio.dev/api/v1/run-ffmpeg-command \
-H "Content-Type: application/json" \
-H "X-API-KEY: ffsk_your_api_key_here" \
-d '{
"input_files": {
"in_video": "https://example.com/source.mp4"
},
"output_files": {
"out_video": "resized.mp4"
},
"ffmpeg_command": "ffmpeg -i {{in_video}} -vf \"scale=1280:-2\" -c:v libx264 -c:a aac {{out_video}}"
}'The API returns a command_id immediately. Poll GET /api/v1/commands/:commandId to check when the resize is complete, then download the output from the storage_url in the response.
Tips and variations
- Divisibility by 2: H.264 requires both width and height to be even numbers. Use
-2instead of-1in scale expressions to guarantee this. If you specify exact dimensions, make sure both numbers are even. - Chaining filters: Combine scale, crop, and pad in a single filter chain by separating them with commas:
-vf "scale=1920:-2,crop=1920:1080". - Upscaling quality: FFmpeg defaults to bilinear scaling. For better quality when upscaling, add a scaling algorithm:
-vf "scale=1920:1080:flags=lanczos". - Social media sizes: Common targets are 1080x1080 (Instagram square), 1080x1920 (Instagram/TikTok story), 1280x720 (YouTube 720p), and 1920x1080 (YouTube 1080p).
- Filter variables: In FFmpeg filters,
iw/ihrefer to the input width/height, andow/ohrefer to the output width/height of the current filter.
Related guides
- Compress Video -- combine resizing with compression for smaller files
- Add Watermark -- overlay branding after resizing
Further reading
- FFmpeg Commands List with API Examples -- resizing commands with matching API calls
- FFmpeg Cheat Sheet: 50 Commands -- quick reference including all resize operations