avidemux: check video stream framerate against avi header frame duration
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Wed, 29 Jul 2009 13:25:38 +0000 (15:25 +0200)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Mon, 10 Aug 2009 12:41:09 +0000 (14:41 +0200)
The former might be bogus in silly cases, and the latter seems to
carry more weight.

gst/avi/gstavidemux.c

index b6e2242..3bbdbdf 100644 (file)
@@ -1502,8 +1502,25 @@ gst_avi_demux_parse_stream (GstAviDemux * avi, GstBuffer * buf)
           GST_WARNING_OBJECT (avi, "Failed to parse strh chunk");
           goto fail;
         }
-        /* determine duration as indicated by header */
         strh = stream->strh;
+        /* sanity check; stream header frame rate matches global header
+         * frame duration */
+        if (stream->strh->type == GST_RIFF_FCC_vids) {
+          GstClockTime s_dur;
+          GstClockTime h_dur = avi->avih->us_frame * GST_USECOND;
+
+          s_dur = gst_util_uint64_scale (GST_SECOND, strh->scale, strh->rate);
+          GST_DEBUG_OBJECT (avi, "verifying stream framerate %d/%d, "
+              "frame duration = %d ms", strh->rate, strh->scale,
+              s_dur / GST_MSECOND);
+          if (h_dur > (10 * GST_MSECOND) && (s_dur > 10 * h_dur)) {
+            strh->rate = GST_SECOND / GST_USECOND;
+            strh->scale = h_dur / GST_USECOND;
+            GST_DEBUG_OBJECT (avi, "correcting stream framerate to %d/%d",
+                strh->rate, strh->scale);
+          }
+        }
+        /* determine duration as indicated by header */
         stream->hdr_duration = gst_util_uint64_scale ((guint64) strh->length *
             strh->scale, GST_SECOND, (guint64) strh->rate);
         GST_INFO ("Stream duration according to header: %" GST_TIME_FORMAT,