How to Fix Stretched Video Using FFmpeg
When a video displays as stretched or squished on certain media players, the issue is usually a mismatch between the video’s pixel dimensions and its Display Aspect Ratio (DAR) metadata. This article provides a straightforward guide on how to use FFmpeg to correct this metadata or physically rescale the video, fixing the stretching issue without losing quality or wasting time on unnecessary re-encoding.
Understanding the Issue
Videos have two types of aspect ratios: * SAR (Sample Aspect Ratio): The shape of the individual pixels. * DAR (Display Aspect Ratio): The final shape of the video player screen (e.g., 16:9 or 4:3).
If a media player ignores the SAR or reads corrupted DAR metadata, it will stretch the pixels, causing the video to look distorted.
Solution 1: Change the Aspect Ratio Metadata (No Re-encoding)
The fastest and best way to fix a stretched video is to change the Display Aspect Ratio metadata. This method does not re-encode the video stream, meaning it completes instantly and preserves 100% of the original video quality.
Run the following command in your terminal, replacing
16:9 with your desired target aspect ratio (such as
4:3 or 2.39:1):
ffmpeg -i input.mp4 -aspect 16:9 -c copy output.mp4Command breakdown: * -i input.mp4:
Specifies the distorted input video. * -aspect 16:9: Sets
the new container Display Aspect Ratio. * -c copy: Copies
both video and audio streams directly without re-encoding them.
Solution 2: Force SAR and DAR Using Video Filters (Re-encoding)
Some stubborn media players ignore container-level metadata. If
Solution 1 does not work, you must force the player to recognize the
correct aspect ratio by rewriting the video stream properties using the
setdar (Set Display Aspect Ratio) and setsar
(Set Sample Aspect Ratio) filters.
Because this modifies the video stream itself, you must re-encode the video:
ffmpeg -i input.mp4 -vf "setsar=1,setdar=16:9" -c:v libx264 -crf 23 -c:a copy output.mp4Command breakdown: *
-vf "setsar=1,setdar=16:9": Sets the pixel shape to square
(1:1) and forces the final screen display to 16:9. *
-c:v libx264: Re-encodes the video using the widely
compatible H.264 codec. * -crf 23: Sets the visual quality
(lower values mean higher quality; 18-23 is standard). *
-c:a copy: Copies the audio stream without re-encoding to
save time.
Solution 3: Physically Resize the Video Resolution
If you want to ensure the video plays correctly on every single legacy device and player, you should physically resize the video frame to standard square-pixel dimensions (such as scaling to 1920x1080 or 1280x720).
Use this command to scale the video to a standard 1080p widescreen resolution:
ffmpeg -i input.mp4 -vf scale=1920:1080 -c:v libx264 -crf 23 -c:a copy output.mp4By physically changing the width and height of the pixel grid to match standard aspect ratios, the video will display correctly across all media players, web browsers, and social media platforms.