[FFmpeg-devel] [HACK] mov edl desync fix

Reimar Döffinger Reimar.Doeffinger
Fri Jan 2 10:08:54 CET 2009


Hello,
I am really certain this is wrong (does FFmpeg even allow negative
timestamps? They mean the thing you might naively assume them to mean
in this case, namely parts that are "before" the start of the track/video).
Nevertheless it works quite nicely...
At the very least the debug message should be changed to print the track
and the exact delay in seconds so it can be fixed manually.
A sample currently is available here:
http://www.doppelbauer.name/desync.mov
but I guess there are also some somewhere on samples @mphq.

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/mov.c
===================================================================
--- libavformat/mov.c	(revision 16404)
+++ libavformat/mov.c	(working copy)
@@ -124,6 +124,7 @@
     int *keyframes;
     int time_scale;
     int time_rate;
+    int time_offset;
     int current_sample;
     unsigned int bytes_per_frame;
     unsigned int samples_per_frame;
@@ -1214,7 +1215,7 @@
 {
     MOVStreamContext *sc = st->priv_data;
     int64_t current_offset;
-    int64_t current_dts = 0;
+    int64_t current_dts = -sc->time_offset / sc->time_rate;
     unsigned int stts_index = 0;
     unsigned int stsc_index = 0;
     unsigned int stss_index = 0;
@@ -1730,7 +1733,8 @@
 /* edit list atom */
 static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
 {
-    MOVStreamContext *sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
+    int streamnr = c->fc->nb_streams-1;
+    MOVStreamContext *sc = c->fc->streams[streamnr]->priv_data;
     int i, edit_count;
 
     get_byte(pb); /* version */
@@ -1742,9 +1746,10 @@
         get_be32(pb); /* Track duration */
         time = get_be32(pb); /* Media time */
         get_be32(pb); /* Media rate */
+        sc->time_offset = time;
         if (time != 0)
-            av_log(c->fc, AV_LOG_WARNING, "edit list not starting at 0, "
-                   "a/v desync might occur, patch welcome\n");
+            av_log(c->fc, AV_LOG_WARNING, "edit list %i for track %i not starting at 0 (but %i), "
+                   "a/v desync might occur, patch welcome\n", i, streamnr, time);
     }
     dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, sc->edit_count);
     return 0;



More information about the ffmpeg-devel mailing list