Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get aspect ratio of video from FFmpeg

Tags:

ffmpeg

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?

like image 489
Rocky Singh Avatar asked Dec 12 '10 15:12

Rocky Singh


People also ask

What is SAR and DAR in ffmpeg?

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.

What is a 2 3 aspect ratio?

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.

What is Setsar in ffmpeg?

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.


2 Answers

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.

like image 139
Hashim Aziz Avatar answered Sep 18 '22 08:09

Hashim Aziz


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.

like image 39
Marko Avatar answered Sep 19 '22 08:09

Marko