[FFmpeg-devel] [PATCH] movenc: Fix muxing of Apple Quicktime chapters.

Philip Langdale philipl at overt.org
Sun May 13 18:22:41 CEST 2012


There is basic support for muxing chapter information into the
Apple Quicktime format already, but there are two errors which
prevent correct detection on the player side.

1) A special apple 'text' atom needs to be included inside the
gmhd atom.

2) The *different* 'text' atom inside the 'stsd' atom needs a
proper header.

With these changes, the chapters are now picked up by Apple
players and reported correctly by tools like mediainfo and mp4chaps.
---
 libavformat/movenc.c |   45 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 8dc6ada..e35cf46 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1002,6 +1002,27 @@ static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track)
 
     if (track->enc->extradata_size)
         avio_write(pb, track->enc->extradata, track->enc->extradata_size);
+    else {
+        // Stub header (usually for Quicktime chapter track)
+        avio_wb32(pb, 0x01); // displayFlags
+        avio_wb32(pb, 0x01); // text justification
+        avio_wb16(pb, 0x00); // bgColourRed
+        avio_wb16(pb, 0x00); // bgColourGreen
+        avio_wb16(pb, 0x00); // bgColourBlue
+        avio_wb16(pb, 0x00); // defTextBoxTop
+        avio_wb16(pb, 0x00); // defTextBoxLeft
+        avio_wb16(pb, 0x00); // defTextBoxBottom
+        avio_wb16(pb, 0x00); // defTextBoxRight
+        avio_wb32(pb, 0x00); // Reserved
+        avio_wb32(pb, 0x00); // Reserved
+        avio_wb16(pb, 0x00); // fontNumber
+        avio_wb16(pb, 0x00); // fontFace
+        avio_w8(pb, 0x00);   // Reserved
+        avio_wb16(pb, 0x00); // Reserved
+        avio_wb16(pb, 0x00); // foreColourRed
+        avio_wb16(pb, 0x00); // foreColourGreen
+        avio_wb16(pb, 0x00); // foreColourBlue
+    }
 
     return update_size(pb, pos);
 }
@@ -1260,7 +1281,7 @@ static int mov_write_nmhd_tag(AVIOContext *pb)
 
 static int mov_write_gmhd_tag(AVIOContext *pb)
 {
-    avio_wb32(pb, 0x20);   /* size */
+    avio_wb32(pb, 0x4C);   /* size */
     ffio_wfourcc(pb, "gmhd");
     avio_wb32(pb, 0x18);   /* gmin size */
     ffio_wfourcc(pb, "gmin");/* generic media info */
@@ -1271,7 +1292,27 @@ static int mov_write_gmhd_tag(AVIOContext *pb)
     avio_wb16(pb, 0x8000); /* opColor (b?) */
     avio_wb16(pb, 0);      /* balance */
     avio_wb16(pb, 0);      /* reserved */
-    return 0x20;
+
+    /*
+     * This special text atom is required for
+     * Apple Quicktime chapters. The contents
+     * don't appear to be documented, so the
+     * bytes are copied verbatim.
+     */
+    avio_wb32(pb, 0x2C);   /* size */
+    ffio_wfourcc(pb, "text");
+    avio_wb16(pb, 0x01);
+    avio_wb32(pb, 0x00);
+    avio_wb32(pb, 0x00);
+    avio_wb32(pb, 0x00);
+    avio_wb32(pb, 0x01);
+    avio_wb32(pb, 0x00);
+    avio_wb32(pb, 0x00);
+    avio_wb32(pb, 0x00);
+    avio_wb32(pb, 0x00004000);
+    avio_wb16(pb, 0x0000);
+
+    return 0x4C;
 }
 
 static int mov_write_smhd_tag(AVIOContext *pb)
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list