FFmpeg SAR DAR and Storage Dimensions Explained

This article explains the fundamental relationship between Storage Aspect Ratio (SAR), Display Aspect Ratio (DAR), and storage dimensions (pixel width and height) in digital video. You will learn the mathematical formula that connects these three properties, how they affect how a video is displayed, and how to inspect and manipulate them using FFmpeg commands.

The Three Core Components

To understand how video dimensions work in FFmpeg, you must distinguish between the physical pixels stored in the file and how those pixels are stretched when rendered on a screen.

The Mathematical Relationship

The relationship between these three variables is governed by a simple formula:

\[\text{DAR} = \left( \frac{\text{Storage Width}}{\text{Storage Height}} \right) \times \text{SAR}\]

If you know any two of these values, you can always calculate the third.

Example: NTSC DVD Widescreen

An NTSC DVD has storage dimensions of 720x480 pixels. If you display this using square pixels, the aspect ratio is \(720 / 480 = 1.5\) (or 3:2).

To display this video in a standard 16:9 (1.777) widescreen format, the player must stretch the pixels horizontally. This is achieved by setting a non-square Sample Aspect Ratio (SAR):

\[\text{DAR} = \left( \frac{720}{480} \right) \times \left( \frac{32}{27} \right) = 1.5 \times 1.185 = 1.777 \text{ (which is 16:9)}\]

In this scenario, FFmpeg reads the storage dimensions (720x480) and the SAR (32:27), then instructs the video player to render the video at a DAR of 16:9.

Inspecting SAR and DAR with FFmpeg

You can view the SAR, DAR, and storage dimensions of a video file using ffprobe, which is packaged with FFmpeg. Run the following command:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 input.mp4

This will output the specific dimensions and ratios of your video file:

width=720
height=480
sample_aspect_ratio=32:27
display_aspect_ratio=16:9

How to Modify SAR and DAR in FFmpeg

Sometimes a video file has incorrect metadata, causing it to display stretched or squished. You can use FFmpeg video filters to change the SAR or DAR without altering the underlying storage dimensions (pixels), or scale the video and reset the aspect ratios.

1. Set a Specific Display Aspect Ratio (DAR)

To force a video to display in 16:9 widescreen format without changing the actual pixel dimensions, use the setdar filter:

ffmpeg -i input.mp4 -vf "setdar=16/9" output.mp4

FFmpeg will automatically recalculate and write the correct SAR to the output file’s metadata so that the math balances.

2. Set a Specific Sample Aspect Ratio (SAR)

To force the pixels to be square (1:1), which is ideal for web playback, use the setsar filter:

ffmpeg -i input.mp4 -vf "setsar=1/1" output.mp4

3. Scale Video and Keep Square Pixels

If you want to resize a video to a specific resolution (e.g., 1280x720) and ensure the pixels are perfectly square (SAR 1:1), combine the scale and setsar filters:

ffmpeg -i input.mp4 -vf "scale=1280:720,setsar=1/1" output.mp4