[FFmpeg-devel] movenc.c: Allow MPEG2.mov playable under QuickTime Player

Takashi Mochizuki mochi
Sat Feb 5 23:17:58 CET 2011


Hi,

I have made a tiny patch to movenc, for MPEG-2 OpenGOP stream.

This patch forces first sample as Sync flag on OpenGOP stream.

It allows QuickTime Player + Perian combination to play remuxed mpeg2.mov
without stuttering effect.

ffmpeg -i mpeg2.ts -vcodec copy -an mpeg2.mov

Takashi Mochizuki

//

diff -ur 27518.org/libavformat/movenc.c 27518/libavformat/movenc.c
--- 27518.org/libavformat/movenc.c      2011-02-05 19:23:44.000000000 +0900
+++ 27518/libavformat/movenc.c  2011-02-06 07:00:03.000000000 +0900
@@ -147,7 +147,7 @@
     put_be32(pb, 0); // version & flags
     entryPos = url_ftell(pb);
     put_be32(pb, track->entry); // entry count
-    for (i=0; i<track->entry; i++) {
+    for (i=1; i<track->entry; i++) {
         if (track->cluster[i].flags & flag) {
             put_be32(pb, i+1);
             index++;
@@ -160,6 +160,17 @@
     return updateSize(pb, pos);
 }
 
+/* Dummy stts atom for OpenGOP stream */
+static int mov_write_stss_tag_dummy(ByteIOContext *pb, MOVTrack *track)
+{
+    put_be32(pb, 0x14); /* size */
+    put_tag(pb, "stss");
+    put_be32(pb, 0); /* decoder version + flag */
+    put_be32(pb, 0x01); /* Numbers of sync sample table */
+    put_be32(pb, 0x01); /* Sample table number. First atom should be sync. */
+    return 0x14;
+}
+
 static int mov_write_amr_tag(ByteIOContext *pb, MOVTrack *track)
 {
     put_be32(pb, 0x11); /* size */
@@ -986,8 +997,10 @@
          track->enc->codec_tag == MKTAG('r','t','p',' ')) &&
         track->hasKeyframes && track->hasKeyframes < track->entry)
         mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE);
-    if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS)
+    if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS) {
+        mov_write_stss_tag_dummy(pb, track);
         mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE);
+    }
     if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO &&
         track->flags & MOV_TRACK_CTTS)
         mov_write_ctts_tag(pb, track);




More information about the ffmpeg-devel mailing list