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

Benjamin Larsson banan
Thu Feb 10 15:00:02 CET 2011


On 02/05/2011 11:17 PM, Takashi Mochizuki wrote:
> 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

Hi, I tested your patch and for me it doesn't work. The output file
simply doesn't play. I also tried a slight change of your patch and
while it played, the output was jerky. This on a mac with Quicktime and
FCP installed.


MvH
Benjamin Larsson

--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -143,7 +143,7 @@ static int mov_write_stsc_tag(ByteIOContext *pb,
MOVTrack *track, int est_nb_fra
 }
 
 /* Sync sample atom */
-static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack *track,
uint32_t flag, int est_nb_frames)
+static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack *track,
uint32_t flag, int est_nb_frames, int sync)
 {
     int64_t curpos, entryPos;
     int i, index = 0;
@@ -157,9 +157,10 @@ static int mov_write_stss_tag(ByteIOContext *pb,
MOVTrack *track, uint32_t flag,
         url_fskip(pb, 4 * est_nb_frames);
     else {
     for (i=0; i<track->entry; i++) {
-        if (track->cluster[i].flags & flag) {
+        if ((track->cluster[i].flags & flag) || sync) {
             put_be32(pb, i+1);
             index++;
+            sync = 0;
         }
     }
     curpos = url_ftell(pb);
@@ -1111,9 +1112,10 @@ static int mov_write_stbl_tag(ByteIOContext *pb,
MOVTrack *track, int est_nb_fra
     if ((track->enc->codec_type == AVMEDIA_TYPE_VIDEO ||
          track->enc->codec_tag == MKTAG('r','t','p',' ')) &&
         track->hasKeyframes && track->hasKeyframes < track->entry)
-        mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE, est_nb_frames);
-    if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS)
-        mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE,
est_nb_frames);
+        mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE, est_nb_frames, 0);
+    if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS) {
+        mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE,
est_nb_frames, 1);
+    }
     if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO &&
         track->flags & MOV_TRACK_CTTS)
         mov_write_ctts_tag(pb, track, est_nb_frames);


MvH
Benjamin Larsson



More information about the ffmpeg-devel mailing list