What do SAR and DAR mean in FFmpeg video metadata?

I have been working on video transcoding using FFmpeg. When I try to get metadata of transcoded video using ffprobe -show_streams command, I get the following output.
[STREAM]
index=0
codec_name=vp9
codec_long_name=Google VP9
profile=Profile 0
codec_type=video
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1920
height=1080
coded_width=1920
coded_height=1080
closed_captions=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=-99
color_range=tv
color_space=bt709
color_transfer=unknown
color_primaries=unknown
chroma_location=unspecified
field_order=unknown
refs=1
id=N/A
r_frame_rate=30/1
avg_frame_rate=30/1
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng
TAG:DURATION=00:00:47.600000000
[/STREAM]

As you can see in the above metadata, their sample_aspect_ratio and display aspect ratio, i am struggling to understand the difference between those values.

Conceptually, there are three terms DAR (display aspect ratio), PAR (pixel aspect ratio), and SAR (storage aspect ratio), these terms are used interchangeably to refer to/denote video resolution creating confusion sometimes.

DAR: The aspect ratio at which a video should be shown on a screen or monitor is called the Display Aspect Ratio, or DAR. It considers the scaling or display of the video samples (SAR) as well as their requirements. DAR determines how a video will appear on a monitor and is sometimes described as a ratio, such as 16:9 or 4:3.

  • In the event that the SAR and DAR coincide, the video ought to appear blur-free. If they do not match, the video may be shown with black bars (also known as letterboxing or pillarboxing) in order to preserve the desired aspect ratio.

  • When a video has a 4:3 SAR but a 16:9 DAR, for instance, it indicates that the video is meant to be seen in a 16:9 aspect ratio, but the individual video samples are in a 4:3 aspect ratio. To achieve the correct 16:9 aspect ratio, would cause the video to be presented with black bars on the sides.

PAR: Pixel aspect ratio is a mathematical ratio that describes how the width of a pixel in a digital image compares to the height of that pixel. Most digital devices display an image as a grid of tiny, square pixels so for that kind of device PAR will be 1:1. But some devices display an image as a grid of rectangular pixels, in which the pixel width and height are different. The pixel aspect ratio describes this difference.

SAR: Storage aspect ratio is the ratio of pixel dimensions when an image/video is displayed on a particular device. If an image/video is displayed with square pixels then PAR and SAR are the same but for rectangular pixels, the PAR and SAR differ.

  • A video with a SAR of 16:9, for example, indicates that every pixel in the video is meant to be shown in a 16:9 aspect ratio. Depending on the device, this video could appear compressed or stretched if you watched it with square pixels.

FFmpeg denotes PAR as SAR in their metadata information, so what you see as the value of SAR (sample_aspect_ratio) is the PAR (pixel aspect ratio) for the video.

Read this: All about Video aspect ratio

1 Like

Got it!
Thanks, Vatsal!

1 Like

Very interesting discussion. :+1:

In addition to the previous response, it is essential to understand how these ratios interrelate and why they are significant for video transcoding and display.

The relationship between DAR, PAR, and SAR can be expressed with the following equation:

DAR = SAR × PAR

In video transcoding, maintaining the correct aspect ratios is crucial for ensuring proper video playback on different devices and screens.

When scaling or resizing a video, you need to preserve the original aspect ratio, so the displayed video doesn’t appear distorted or stretched.

For instance, when transcoding a video to a different resolution, you may need to adjust the SAR (i.e., the PAR) to maintain the original DAR.

FFmpeg provides various options to manipulate aspect ratios during transcoding. You can set the SAR value explicitly using the ‘-aspect’ option or apply filters like ‘scale’, ‘setdar’, or ‘setsar’ to manipulate the resolution and aspect ratios.

Understanding and maintaining the correct aspect ratios is particularly important for compatibility with various playback devices, which may have different native pixel aspect ratios.

For example, Standard Definition (SD) TV systems like NTSC and PAL use non-square pixels, while High Definition (HD) and modern display systems typically use square pixels.

When transcoding videos between these systems, aspect ratio adjustments become necessary to ensure proper video display.

In summary, the interplay between DAR, SAR (PAR in FFmpeg), and aspect ratio management is essential for video transcoding tasks.

Being aware of these concepts and utilizing FFmpeg’s options and filters for aspect ratio manipulation can help you achieve optimal video playback across different devices and screen resolutions.

1 Like

What are some typical situations where non-square pixels may appear in videos, and how can FFmpeg manage these situations utilizing SAR?

2 Likes

There are several social and technical factors that can lead to non-square pixel videos. Typical circumstances where non-square pixels appear in videos include:

1. Legacy Video Formats

Because of historical technical constraints, earlier video formats, including those used for analog television broadcasts, frequently contained non-square pixels.

2. Anamorphic Video

Widescreen footage is stored using the anamorphic video method within a standard-definition frame. To fit a wider aspect ratio, the image is stretched horizontally, resulting in pixels that are not square.

3. Pixel Aspect Ratio Conversion

Video content may occasionally be transcoded or converted between various aspect ratios or resolutions, resulting in pixels that aren’t square.

4. Digital cameras and camcorders

To support particular resolutions and aspect ratios, some digital cameras and camcorders capture video using non-square pixels.

The Sample Aspect Ratio (SAR) in the video metadata is used by FFmpeg to deal with videos that have non-square pixels. The SAR parameter specifies how each pixel’s width and height are related in a video frame. The SAR is taken into consideration by FFmpeg when playing or processing such videos to guarantee proper aspect ratio display.

  1. Media players that use FFmpeg (or FFmpeg-based libraries) change the pixel aspect ratio based on the SAR value while playing a video with non-square pixels. This guarantees that the video is shown with the proper aspect ratio, preventing any visual distortions.

  2. While processing videos, FFmpeg makes the necessary adjustments for resizing, cropping, and other actions according to the SAR data. Taking into consideration the non-square pixels, this guarantees that the produced video maintains the proper aspect ratio.

  3. When encoding or transcoding video files, FFmpeg preserves the SAR information in the video metadata. The original aspect ratio must be preserved to prevent problems during playback or additional processing.

Within the processing pipeline, FFmpeg provides an accurate aspect ratio display and upholds the visual integrity of the content by taking into account the Sample Aspect Ratio (SAR) of films with non-square pixels.

1 Like