[FFmpeg-devel] [PATCH] fix MOV aspect ratio handling with 'pasp'

Andrew Wason rectalogic
Sat Feb 27 21:15:45 CET 2010

Commit r21301 broke MOV aspect ratio handling when the video has a
'pasp' atom. See the bug report for a more detailed discussion and
sample video:

The patch I attached to issue1754 wasn't very good. Attached here is a
much cleaner, simpler patch. If the aspect ratio implied by the track
dimensions differs from what was set by 'pasp' or the track matrix,
then multiply them - otherwise use the track dimensions aspect.

This gets correct results with all the samples I tested with.

-------------- next part --------------
Index: libavformat/mov.c
--- libavformat/mov.c	(revision 22094)
+++ libavformat/mov.c	(working copy)
@@ -1656,7 +1656,8 @@
         if (st->codec->width != sc->width || st->codec->height != sc->height) {
             AVRational r = av_d2q(((double)st->codec->height * sc->width) /
                                   ((double)st->codec->width * sc->height), INT_MAX);
-            if (st->sample_aspect_ratio.num)
+            if (st->sample_aspect_ratio.num &&
+                st->sample_aspect_ratio.num != r.num && st->sample_aspect_ratio.den != r.den)
                 st->sample_aspect_ratio = av_mul_q(st->sample_aspect_ratio, r);
                 st->sample_aspect_ratio = r;

More information about the ffmpeg-devel mailing list