16

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?

4 Answers 4

20

Just run

ffmpeg -i <yourfilename>

and details about the video stream/s contained in the file will be printed to the screen. Two of the parameters listed for each video stream will be the PAR (Pixel Aspect Ratio) and DAR(Display Aspect Ratio). You'll see something like this:

 Stream #0.10[0x258]: Video: mpeg2video, yuv420p, 720x576 [PAR 64:45 DAR 16:9], 4350 kb/s, 27.97 fps, 25 tbr, 90k tbn, 50 tbc

The DAR is what ratio the final displayed video will have. The PAR indicates how the pixels have to be sized to achieve this. For example, in the case I just showed, (720*64)/(576*45) = 16/9.

Many times, PAR will be equal to 1:1, which means that the DAR should be equal to the ratio of the video resolution.

20

ffprobe is preferable for getting media information. When using ffmpeg -i file and no other arguments, ffmpeg returns an error status.

2
  • 7
    ffprobe -i <filename> -show_streams will also output a list of key=value for the video and audio streams. ex: ... sample_aspect_ratio=1:1 display_aspect_ratio=8:5 ... may be easier to parse the result programatically
    – brita_
    Commented Apr 22, 2014 at 8:11
  • 6
    another note: there are several options for printing, such as -print_format json to get the output in the most usable format possible for any situation
    – brita_
    Commented Apr 22, 2014 at 11:43
5
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.

4

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 the command from a script and capturing the data into a variable or array.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.