How to Change Video SAR with FFmpeg setsar

This article provides a quick guide on how to change the Sample Aspect Ratio (SAR) of a video file using the FFmpeg setsar video filter. You will learn the precise command-line syntax, understand how the filter affects video dimensions, and see practical examples for setting custom pixel ratios.

Understanding SAR

The Sample Aspect Ratio (SAR) defines the ratio of a single pixel’s width to its height. Unlike the Display Aspect Ratio (DAR), which defines the overall proportions of the displayed image (like 16:9 or 4:3), SAR dictates how the individual pixels should be stretched during playback to achieve the correct DAR.

Basic Command Syntax

To change the SAR of a video using FFmpeg, you use the video filter flag (-vf) followed by the setsar filter.

The basic syntax is:

ffmpeg -i input.mp4 -vf "setsar=ratio" output.mp4

You can define the ratio as a single float, an integer, or a fractional expression (e.g., num/den or num:den).

Practical Examples

1. Setting SAR to Square Pixels (1:1)

Standard modern video formats typically use square pixels (a ratio of 1:1). To set the SAR to 1:1, use either of the following commands:

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

Or simply:

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

2. Setting a Specific Non-Square Pixel Aspect Ratio

If you are working with anamorphic video or legacy formats like DVD, you may need a non-square pixel ratio. For example, to set the SAR to 12:11:

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

3. Using Variables in setsar

The setsar filter allows you to use variables to calculate ratios dynamically. For example, you can use the input sample aspect ratio (sar) and modify it:

ffmpeg -i input.mp4 -vf "setsar=sar*2" output.mp4

Note on Re-encoding

Because setsar is a video filter, using this command forces FFmpeg to re-encode the video stream. You should define your desired video codec (such as -c:v libx264) and quality settings (such as -crf 23) to maintain quality during the conversion, while copying the audio stream to save time.

Example with encoding settings:

ffmpeg -i input.mp4 -vf "setsar=1:1" -c:v libx264 -crf 23 -c:a copy output.mp4