I am using FFmpeg to convert a video from one format to another. I need to extract the aspect ratio of the video first. How can I find that information?
SAR (Sample Aspect Ratio) is the same as PAR (Pixel Aspect Ratio). These two terms are used interchangeably. They mean the ratio between the width and the height of individual pixels. In contrast, DAR (Display Aspect ratio) is the ratio between the width and the height of the full image.
2:3 Aspect Ratio. 2:3 is the most popular aspect ratio for printing. Print sizes that are a 2:3 aspect ratio and are popular with poster, canvas, and decal printing are 24 x 36 inches and 40 x 60 inches.
The setsar filter sets the Sample (aka Pixel) Aspect Ratio for the filter output video. Note that as a consequence of the application of this filter, the output display aspect ratio will change according to the equation above.
To more directly answer the question that was asked, as well as get the data in the simplest format possible to be used for programmatic purposes (such as a variable):
$ ffprobe -v error -select_streams v:0 -show_entries stream=display_aspect_ratio -of default=noprint_wrappers=1:nokey=1 <yourfilename>
16:9
Unfortunately ffprobe
's syntax is overly verbose, but thankfully that doesn't matter too much when running this sort of command from a script or program to capture the data into a variable or array.
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of json=c=1 'filepath.mov'
this command will get width, height, sar and dar of the first video stream of file in json format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With