Fix Incorrect Video Dimensions on Mobile Using FFmpeg
When videos are played on mobile devices, they sometimes display with incorrect dimensions, stretched aspect ratios, or improper rotations. This article provides a straightforward guide on how to use the command-line tool FFmpeg to fix these dimension issues. You will learn how to reset the aspect ratio, bake in the correct orientation, and scale or crop your video so it displays perfectly on both iOS and Android screens.
1. Fix the Display Aspect Ratio (DAR)
If your video appears stretched or squished, the issue is likely a mismatch between the container’s Display Aspect Ratio (DAR) and the video’s actual pixel dimensions. You can force a specific aspect ratio without re-encoding the video stream.
To force a standard widescreen (16:9) aspect ratio:
ffmpeg -i input.mp4 -aspect 16:9 -c copy output.mp4To force a vertical (9:16) aspect ratio for mobile-first viewing:
ffmpeg -i input.mp4 -aspect 9:16 -c copy output.mp4Note: Using -c copy is extremely fast because it
changes the metadata without re-encoding the video.
2. Hardcode the Video Rotation
Mobile devices use metadata tags to tell players which way to rotate
a video. However, some mobile web browsers and players ignore this
metadata, causing portrait videos to play sideways. To fix this, you
must “bake” the rotation directly into the video frames using the
transpose filter.
To rotate a video 90 degrees clockwise (converting landscape to portrait):
ffmpeg -i input.mp4 -vf "transpose=1" -c:a copy output.mp4To rotate 90 degrees counter-clockwise:
ffmpeg -i input.mp4 -vf "transpose=2" -c:a copy output.mp43. Scale and Pad Video to Fit Mobile Screens (Letterboxing)
If you want to fit a widescreen video onto a mobile vertical screen (9:16) without cropping any of the content, you can scale the video and add black bars (padding) to the top and bottom.
To scale and pad a video to a standard 1080x1920 mobile resolution:
ffmpeg -i input.mp4 -vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2" -c:a copy output.mp4force_original_aspect_ratio=decreaseensures the video scales down to fit within the 1080x1920 box without stretching.pad=1080:1920:(ow-iw)/2:(oh-ih)/2centers the scaled video on a black 1080x1920 canvas.
4. Crop Landscape Video to Vertical (9:16)
If you want a widescreen video to fill a mobile screen completely without black bars, you must crop the sides of the video.
To crop a 16:9 landscape video into a center-aligned 9:16 vertical video:
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih" -c:a copy output.mp4ih*9/16calculates the target width based on the input height to maintain a perfect 9:16 ratio, automatically cropping equal parts from the left and right sides.