[FFmpeg-devel] [PATCH] fix playback of partial DV files

Reimar Döffinger Reimar.Doeffinger
Sun Feb 8 14:01:32 CET 2009


Hello,
currently libavformat handles it badly or not at all when you cut out a
part of the dv file in the middle.
This is because it does not checks at all if the headers are actually at
the place where it expects them.
Proper error concealment needs more modifications, but attached patch at
least makes it search for a DV header in dv_read_header, which is enough
for simple cases like http://multimedia.cx/dv/spacejam-title.40MB.dv
I also think that based on this a proper auto-detection of DV should be
possible - for my pet project (http://sourceforge.net/projects/extractor-gtk)
I implemented it by search for the bytes 1f 07 00 3f or 0x1f 07 00 bf,
skipping the next four bytes and then checking that the next 8 bytes are all
ff.

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/dv.c
===================================================================
--- libavformat/dv.c	(revision 17031)
+++ libavformat/dv.c	(working copy)
@@ -399,12 +399,23 @@
 static int dv_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
 {
+    uint32_t state;
     RawDVContext *c = s->priv_data;
 
     c->dv_demux = dv_init_demux(s);
     if (!c->dv_demux)
         return -1;
 
+    state = get_be32(s->pb);
+    while (state != 0x1f07003f && state != 0x1f0700bf) {
+        if (url_feof(s->pb)) {
+            av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n");
+            return -1;
+        }
+        state = (state << 8) | get_byte(s->pb);
+    }
+    url_fseek(s->pb, -4, SEEK_CUR);
+
     if (get_buffer(s->pb, c->buf, DV_PROFILE_BYTES) <= 0 ||
         url_fseek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0)
         return AVERROR(EIO);



More information about the ffmpeg-devel mailing list