Skip to content
explainroo
FFmpeg and rendering

How to Resize and Scale a Video with FFmpeg

Updated 4 min read

On this page
  1. Resize while keeping the original shape
  2. Fit a video into exact dimensions
  3. Choose quality and output size
  4. Create a resized explainer with explainroo

Use FFmpeg from the command line when a video is too large, needs to fit a screen, or has the wrong shape for a platform. Resizing changes the number of pixels in each frame. The scale filter does that work, while the dimensions you choose determine whether the image keeps its shape, stretches, or gains borders.

When you resize an existing video, FFmpeg lets you choose whether to preserve its shape, stretch it, or add borders. For narrated explainers made from scratch, explainroo is a free, open-source option that creates videos in wide, tall, portrait, and square formats. It uses FFmpeg to assemble the finished MP4, and its tools create new videos rather than edit existing camera footage.

Resize while keeping the original shape

A video’s aspect ratio is its width-to-height relationship. To preserve the original shape, set one dimension and let FFmpeg calculate the other. This command sets the width and calculates an even height:

ffmpeg -i input.mp4 -vf "scale=WIDTH:-2" -c:v libx264 -crf 18 -preset medium -c:a copy output.mp4

Replace input.mp4 and output.mp4 with your filenames, and replace WIDTH with your desired width. The -vf option applies a video filter, and scale=WIDTH:-2 sets the width while calculating a height that preserves the aspect ratio. The -2 also makes the calculated dimension divisible by two, which avoids common H.264 encoding errors involving odd frame dimensions. FFmpeg’s scale filter supports this kind of resizing.

The remaining options control encoding. -c:v libx264 selects the H.264 video encoder, and -crf 18 sets its quality level. Lower CRF values produce higher quality and larger files; 18 is a common choice for high visual quality. -preset medium sets an encoding speed and compression tradeoff. -c:a copy copies the audio without re-encoding it.

You can also set the height instead of the width. Use scale=-2:HEIGHT, replacing HEIGHT with your desired height. Examples of resizing while preserving the source proportions appear in Mux’s FFmpeg overview.

Fit a video into exact dimensions

Setting both dimensions directly, as in scale=WIDTH:HEIGHT, forces every frame to the chosen width and height. Replace WIDTH and HEIGHT with your target dimensions. If the source has a different aspect ratio, FFmpeg stretches or squashes the image.

To fill a frame of specified dimensions without distorting the video, resize it to fit, then add padding around it:

ffmpeg -i input.mp4 -vf "scale=WIDTH:HEIGHT:force_original_aspect_ratio=decrease,pad=WIDTH:HEIGHT:(ow-iw)/2:(oh-ih)/2:color=black" -c:v libx264 -crf 18 -preset medium -c:a copy output.mp4

force_original_aspect_ratio=decrease fits the image inside the specified dimensions while preserving its shape. The pad filter fills the unused area with black. In its expressions, ow and oh mean the output width and height, while iw and ih mean the scaled video’s width and height. The centered padding keeps the video in the middle of the frame. The aspect-ratio examples show related scale-and-pad approaches.

Padding adds pixels around the image, so the result matches the requested frame size but may have black bars. If you want the video to fill the frame edge to edge, you need to crop some of the picture or accept distortion.

Choose quality and output size

Resizing changes the frame dimensions. The encoder controls the output’s detail and file size. For H.264, -crf sets a constant quality target: lower values preserve more quality and create larger files. The FFmpeg encoding discussion describes CRF 18 as near visually lossless in many cases, though the result depends on the source and viewing conditions.

The -preset option changes encoding speed and compression efficiency. A slower preset takes longer to encode but can produce a smaller file at a similar quality setting. If you do not need to change the audio, -c:a copy avoids another audio-encoding step.

For upscaling, you can choose a scaling algorithm such as Lanczos:

ffmpeg -i input.mp4 -vf "scale=1920:-2:flags=lanczos" -c:v libx264 -crf 18 -preset medium -c:a copy output.mp4

Lanczos affects how FFmpeg interpolates pixels when resizing the image. It cannot restore detail the original video did not capture, so enlarging a low-resolution source does not make it sharper. Mux provides an example using the Lanczos scaling flag.

Create a resized explainer with explainroo

For a narrated explainer or product demo, explainroo can create a new video in the format you need. It works with coding agents that can run shell commands, including Claude Code, Codex, Pi, OpenCode, and Gemini CLI. The project says it works best with Claude Code.

Paste this prompt into your coding agent, replacing the bracketed topic:

Make me a short explainer video about [your topic]. Use explainroo for it: clone explainroo, read its AGENTS.md and follow the steps.

The agent sets up explainroo, creates and checks the video, then provides an MP4 file. You can request a wide format for YouTube. For Shorts, TikTok, or Reels, ask for a tall format. Portrait and square formats are also available. These formats apply to videos explainroo creates; the kit does not resize existing camera recordings.

The agent writes script.md for narration and scenes.js for the visuals. explainroo uses FFmpeg to assemble the video. You can see example videos or read the explainroo documentation.

Free and open source

Let your AI agent make the video

explainroo lets a coding agent like Claude Code or Codex make narrated explainer videos and product demos. The voice, the word timing and the rendering run on your own computer, with no API key and no cost per video.

Copy this into your AI agent

Make me a short explainer video about [your topic]. Use explainroo for it: clone https://github.com/vincentsch/explainroo, read its AGENTS.md and follow the steps.

Getting started Example videos GitHub

Made with explainroo: How a cache makes a website faster

More on ffmpeg and rendering

All guides on ffmpeg and rendering