Change Video Aspect Ratio Without Re-encoding with FFmpeg
This article explains how to quickly change the display aspect ratio (DAR) of a video file using FFmpeg without undergoing a time-consuming and quality-losing re-encoding process. By modifying only the container or bitstream metadata, you can instantly alter how media players stretch and display the video frames.
Method 1: Container-Level Aspect Ratio Modification
The fastest way to change the aspect ratio is by setting the
-aspect flag while using the stream copy
(-c copy) command. This instructs FFmpeg to copy the video
and audio streams exactly as they are, but rewrite the aspect ratio
metadata in the output container.
Run the following command in your terminal:
ffmpeg -i input.mp4 -aspect 16:9 -c copy output.mp4Replace 16:9 with your desired aspect ratio (e.g.,
4:3, 2.39:1, or 1:1) and update
the filenames accordingly. Because the video is not re-encoded, this
process takes only a fraction of a second.
Note: While this method is highly effective, some older or less compliant hardware players ignore container-level metadata and default to the raw pixel dimensions.
Method 2: Bitstream-Level Aspect Ratio Modification (H.264/H.265)
If your media player ignores container-level metadata, you can inject
the aspect ratio directly into the video stream’s bitstream metadata
using a bitstream filter (-bsf:v). This method also avoids
re-encoding.
To do this, you must set the Sample Aspect Ratio (SAR). The formula to find your desired SAR is:
\[\text{SAR} = \text{Desired DAR} \times \frac{\text{Height}}{\text{Width}}\]
For example, to display a \(1920 \times 1080\) video (which has square pixels, SAR 1:1) as 4:3, use the following command for an H.264 video:
ffmpeg -i input.mp4 -c copy -bsf:v h264_metadata=sample_aspect_ratio=3/4 output.mp4For H.265 (HEVC) videos, use the hevc_metadata filter
instead:
ffmpeg -i input.mp4 -c copy -bsf:v hevc_metadata=sample_aspect_ratio=3/4 output.mp4This permanently embeds the scaling instructions inside the video stream itself, ensuring much wider compatibility across strict media players and web browsers without sacrificing video quality.