Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG reports different (wrong) video resolution compared to how it actually plays

Quick question, i have a movie, which was cut and rendered with Sony Vegas from its original format to a .wmv file. Here comes the tricky part, movie when played, either with VLC or WMP, has a resolution of 656x480 ... BUT when i run a ffmpeg -i on it, it says it has a resolution of 600x480 ....

I took the time of actually capturing a frame and croping it with photoshop and its 656 and not 600 like ffmpeg its reporting, why would this could be happening? How could i fix the headers resolution? Would that have any impact on video re-rendering? As i said, VLC and WMP seems not to care about the incorrect headers and are playing it right, BUT, jwplayer seems to be using the header information, which i don't blame him, its correct to do that, but why the video headers could be wrong?

ffmpeg -i trailer.wmv
Input #0, asf, from 'trailer.wmv':
Duration: 00:01:04.93, start: 3.000000, bitrate: 2144 kb/s
Stream #0.0: Audio: wmav2, 44100 Hz, mono, 32 kb/s
Stream #0.1: Video: wmv3, yuv420p, 600x480 [PAR 59:54 DAR 295:216], 2065 kb/
s, 25.00 tb(r)

And yeah, the PAR/DAR parameters are also wrong, but honestly, i don't understand that technical shit, usually watch video and make sure it look good, any feedback would be appreciated :P

Is there a way to change the container information with ffmpeg so applications that actually do use the container information don't render video incorrectly?

like image 412
Emiliano Avatar asked Apr 30 '11 04:04

Emiliano


1 Answers

FFMPEG is 100% correct, that technical stuff is important :D

Your PAR (pixel aspect ratio) and DAR (display aspect ratio) are actually correct, and you proved it by capturing a screenshot and measuring.

What threw you off was the PAR. Not all pixels are square! IE: 1:1, although most downloaded videos will be so you probably never noticed. Some players such as VLC will recognize the PAR value and stretch the video accordingly to meet the DAR. DVD video is a great example of this.

See also: http://en.wikipedia.org/wiki/Pixel_aspect_ratio

So ffmpeg says your video width is 600. Multiply that by the PAR and you'll get "real" width. Meaning as if the pixels were square and not rectangular (horizontally). 600 * (59/54) = 656 (rounded) Number look familiar?

Now take the "real" size: 656 / 480 = 1.366 and look at your DAR: 295 / 216 = 1.366

Magic!

As you found out not all video players are smart enough to recognize the PAR and perform the appropriate stretching. You can change it to a 1:1 using ffmpeg easily using the setsar and scale video filters.

ffmpeg ...stuff... -vf "scale=656:480,setsar=1:1" ...more stuff...

For the curious, it's called setsar because it's also refered to as Sample (aka Pixel) Aspect Ratio: http://ffmpeg.org/ffmpeg.html#setsar-1

Hope this help, I'm sure it confuses many people (including myself) at first.

like image 132
Timeout Avatar answered Sep 27 '22 16:09

Timeout