ffmpeg

Output image with correct aspect with ffmpeg


I have a mkv video with the following properties (obtained with mediainfo):

Width                                    : 718 pixels
Height                                   : 432 pixels
Display aspect ratio                     : 2.35:1
Original display aspect ratio            : 2.35:1

I'd like to take screenshots of it at certain times:

ffmpeg -ss 4212 -i filename.mkv -frames:v 1 -q:v 2 out.jpg

This will produce a 718x432 jpg image, but the aspect ratio is wrong (the image is "squeezed" horizontally). AFAIK, the output image should be 1015*432 (with width=height * DAR). Is this calculation correct?

Is there a way to have ffmpeg output images with the correct size/AR for all videos (i.e. no "hardcoded" values)? I tried playing with the setdar/setsar filters without success.

Also, out of curiosity, trying to obtain SAR and DAR with ffmpeg produces:

Stream #0:0(eng): Video: h264 (High), yuv420p(tv, smpte170m/smpte170m/bt709, progressive),
718x432 [SAR 64:45 DAR 2872:1215], SAR 155:109 DAR 55645:23544, 24.99 fps, 24.99 tbr, 1k tbn, 49.98 tbc (default)

2872/1215 is 2.363, so a slightly different value than what mediainfo reported. Anyone knows why?


Solution

  • Without looking at the file, can't diagnose the reason for the distinct readings, but the generic method to get a square pixel result is

    ffmpeg -ss 4212 -i filename.mkv -vf scale=iw*sar:ih -frames:v 1 -q:v 2 out.jpg