[FFmpeg-devel] [PATCH] account for mov track dimensions when deriving aspect ratio

Andrew Wason rectalogic
Thu Dec 10 15:20:05 CET 2009


This patch is for issue671 (see the bug report for samples). It
accounts for the video track dimensions if different from sample
dimensions when computing aspect ratio.

Final Cut Pro seems to just set the track dimensions to achieve the
correct display aspect ratio as opposed to using 'pasp', so mov files
where the only aspect ratio information is in the track dimensions are
quite common.

Andrew
-------------- next part --------------
Index: libavformat/mov.c
===================================================================
--- libavformat/mov.c	(revision 20787)
+++ libavformat/mov.c	(working copy)
@@ -932,6 +932,16 @@
             st->codec->width = get_be16(pb); /* width */
             st->codec->height = get_be16(pb); /* height */
 
+            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 != 0)
+                    st->sample_aspect_ratio = av_mul_q(st->sample_aspect_ratio, r);
+                else
+                    st->sample_aspect_ratio = r;
+            }
+
             get_be32(pb); /* horiz resolution */
             get_be32(pb); /* vert resolution */
             get_be32(pb); /* data size, always 0 */



More information about the ffmpeg-devel mailing list