Jun 24

How to take Screen Caps from / do Thumbnails of anamorphic video in correct display aspect ratio

Category: Linux,multimedia   — Published by goeszen on June 24, 2015 at 11:16 am

Much of the free floating documentation found on forums and blog posts has been cut off when some developers forked avconv from ffmpeg. I made this
experience when I was looking for advice on how to capture images (screen caps/thumbnails) from an anamorhic video (for example from a DVD) in it's correct display aspect ratio.
You'll have to search for things alternating between avconv and ffmpeg...

Once more, stackexchange's sites were of much help, this question here and the avconv man page.

The video filter syntax and the video filter facility of ffmpeg / avconv are extremely powerful, and you'll surely get what you want. Just check out the
the expression evaluation man page.

For my specific task, I wanted to extract/ grab frames from a 16:9 video.

avconv reported:

Duration: 02:25:47.86, start: 0.000000, bitrate: 1171 kb/s
Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p, 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 50 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 192 kb/s

So one of my first commands was:

  $ avconv -ss 00:08:43 -i <inputfile> -vsync 1 -an -t 70 -vf 'scale=iw*a:ih' '/tmp/video_0%04d.png'

Which gathered images in 900x576 pixels. Which, I thought, was wrong, as my calculation 16 / 9 = 1,7777.. would mean 720 wide * 1,777 = 1280, and the
variable "a" kept giving me 1,25 as aspect ratio. The man pages define it as "the result of if/ih (input width / input height)" and as being equivalent of the
other variable dar. dar holds 1,7777 in the case of this input-video, and a holds 1,25. So dar and a are not always the same.
With this in mind I issued:

  $ avconv -ss 00:08:43 -i <inputfile> -vsync 1 -an -t 70 -vf 'scale=iw*dar:ih' '/tmp/video_0%04d.png'

Which produced images of 1280x576. And from just looking at them, they were stretched far too wide.
By firing up some player and taking a manula screenshot you'll find out that the resulting frame will be 1024x576, and if you calculate 1024/576 you'll
get 1,777, but if you do 1024 / 720 you'll get 1,42222 which is what variable "sar" holds, same as 64/45 (sample aspect ratio, or storage aspect ratio - depending
on how you look at it)

Now, for a conclusion, what I forgot when I assumed I had to scale horizontally with 1,777 instead of 1,4222 was that the anamorhic input-video was not
square pixels (1:1), it already had a slight stretch which only had to be expanded by 1,42 to be the correct display aspect ratio. Read that again: "[SAR 64:45 DAR 16:9]"
so the properly displayed video is a 1024x576 image. So this command produces images in correct aspect ratio:

  $ avconv -ss 00:08:43 -i <inputfile> -vsync 1 -an -t 70 -vf 'scale=iw*sar:ih' '/tmp/video_0%04d.png'

Scaling it with "scale=iw*dar:ih" to 1280x576 would stretch the image too far, so use a command with sar to
produce screen caps in correct video aspect ratio.

Leave a Reply

=