summaryrefslogtreecommitdiffstats
path: root/contrib/ffmpeg
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ffmpeg')
-rw-r--r--contrib/ffmpeg/A05-mkv-chapters.patch57
-rw-r--r--contrib/ffmpeg/A06-mkv-default-subtitle.patch30
-rw-r--r--contrib/ffmpeg/A07-mp4-chapters.patch60
-rw-r--r--contrib/ffmpeg/A08-mp4-faststart.patch301
-rw-r--r--contrib/ffmpeg/A09-mp4-64bit.patch46
-rw-r--r--contrib/ffmpeg/A10-mp4-track-enable.patch142
-rw-r--r--contrib/ffmpeg/A11-mp4-chapter-properties.patch47
-rw-r--r--contrib/ffmpeg/module.defs10
8 files changed, 693 insertions, 0 deletions
diff --git a/contrib/ffmpeg/A05-mkv-chapters.patch b/contrib/ffmpeg/A05-mkv-chapters.patch
new file mode 100644
index 000000000..f4082be1d
--- /dev/null
+++ b/contrib/ffmpeg/A05-mkv-chapters.patch
@@ -0,0 +1,57 @@
+From c4d83dfad34d69a86bf04ded97ae3fda087bfa25 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 08:45:55 -0700
+Subject: [PATCH 1/9] matroskaenc: Allow chapters to be written in trailer
+
+This allows creation of frame accurate chapter marks from sources like
+DVD and BD where the precise chapter location is not known until the
+chapter mark has been reached during reading.
+---
+ libavformat/matroskaenc.c | 10 +++++++++-
+ 1 file changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
+index b37d10c..99de151 100644
+--- a/libavformat/matroskaenc.c
++++ b/libavformat/matroskaenc.c
+@@ -94,6 +94,7 @@ typedef struct MatroskaMuxContext {
+ AVPacket cur_audio_pkt;
+
+ int have_attachments;
++ int wrote_chapters;
+ } MatroskaMuxContext;
+
+
+@@ -688,7 +689,7 @@ static int mkv_write_chapters(AVFormatContext *s)
+ AVRational scale = {1, 1E9};
+ int i, ret;
+
+- if (!s->nb_chapters)
++ if (!s->nb_chapters || mkv->wrote_chapters)
+ return 0;
+
+ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CHAPTERS, avio_tell(pb));
+@@ -721,6 +722,8 @@ static int mkv_write_chapters(AVFormatContext *s)
+ }
+ end_ebml_master(pb, editionentry);
+ end_ebml_master(pb, chapters);
++
++ mkv->wrote_chapters = 1;
+ return 0;
+ }
+
+@@ -1259,6 +1262,11 @@ static int mkv_write_trailer(AVFormatContext *s)
+ end_ebml_master(pb, mkv->cluster);
+ }
+
++ if (mkv->mode != MODE_WEBM) {
++ ret = mkv_write_chapters(s);
++ if (ret < 0) return ret;
++ }
++
+ if (pb->seekable) {
+ if (mkv->cues->num_entries) {
+ cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams);
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A06-mkv-default-subtitle.patch b/contrib/ffmpeg/A06-mkv-default-subtitle.patch
new file mode 100644
index 000000000..9074a3443
--- /dev/null
+++ b/contrib/ffmpeg/A06-mkv-default-subtitle.patch
@@ -0,0 +1,30 @@
+From f1febbdddc573c7684e1761abfe568ebfcfcdcd1 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 08:49:58 -0700
+Subject: [PATCH 3/9] matroskaenc: Fix writing TRACKDEFAULTFLAG
+
+The element was only being written when the value == 1. But the default
+value of this element is 1, so this has no useful effect. This element
+needs to be written when the value == 0.
+---
+ libavformat/matroskaenc.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
+index 4858af5..358ba66 100644
+--- a/libavformat/matroskaenc.c
++++ b/libavformat/matroskaenc.c
+@@ -568,7 +568,9 @@ static int mkv_write_tracks(AVFormatContext *s)
+ tag = av_dict_get(st->metadata, "language", NULL, 0);
+ put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag ? tag->value:"und");
+
+- if (st->disposition)
++ // The default value for TRACKFLAGDEFAULT is 1, so add element
++ // if we need to clear it.
++ if (!(st->disposition & AV_DISPOSITION_DEFAULT))
+ put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
+
+ // look for a codec ID string specific to mkv to use,
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A07-mp4-chapters.patch b/contrib/ffmpeg/A07-mp4-chapters.patch
new file mode 100644
index 000000000..0fec0eaf9
--- /dev/null
+++ b/contrib/ffmpeg/A07-mp4-chapters.patch
@@ -0,0 +1,60 @@
+From 36bdd52964ef68532eea50a81431c0c4c9f329e5 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 08:51:46 -0700
+Subject: [PATCH 4/9] movenc: Allow chapters to be written in trailer
+
+This allows creation of frame accurate chapter marks from sources
+like DVD and BD where the precise chapter location is not known until
+the chapter mark has been reached during reading.
+---
+ libavformat/movenc.c | 19 ++++++++++++++++---
+ 1 file changed, 16 insertions(+), 3 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 496158c..f41f8d7 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -3038,7 +3038,7 @@ static int mov_write_header(AVFormatContext *s)
+ }
+
+ mov->nb_streams = s->nb_streams;
+- if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters)
++ if (mov->mode & (MODE_MP4|MODE_MOV|MODE_IPOD) && s->nb_chapters)
+ mov->chapter_track = mov->nb_streams++;
+
+ if (mov->flags & FF_MOV_FLAG_RTP_HINT) {
+@@ -3053,7 +3053,9 @@ static int mov_write_header(AVFormatContext *s)
+ }
+ }
+
+- mov->tracks = av_mallocz(mov->nb_streams*sizeof(*mov->tracks));
++ // Reserve an extra stream for chapters for the case where chapters
++ // are written in the trailer
++ mov->tracks = av_mallocz((mov->nb_streams+1)*sizeof(*mov->tracks));
+ if (!mov->tracks)
+ return AVERROR(ENOMEM);
+
+@@ -3189,8 +3191,19 @@ static int mov_write_trailer(AVFormatContext *s)
+ AVIOContext *pb = s->pb;
+ int res = 0;
+ int i;
++ int64_t moov_pos;
++
++ // If there were no chapters when the header was written, but there
++ // are chapters now, write them in the trailer. This only works
++ // when we are not doing fragments.
++ if (!mov->chapter_track && !(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
++ if (mov->mode & (MODE_MP4|MODE_MOV|MODE_IPOD) && s->nb_chapters) {
++ mov->chapter_track = mov->nb_streams++;
++ mov_create_chapter_track(s, mov->chapter_track);
++ }
++ }
+
+- int64_t moov_pos = avio_tell(pb);
++ moov_pos = avio_tell(pb);
+
+ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
+ /* Write size of mdat tag */
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A08-mp4-faststart.patch b/contrib/ffmpeg/A08-mp4-faststart.patch
new file mode 100644
index 000000000..c4d8d706b
--- /dev/null
+++ b/contrib/ffmpeg/A08-mp4-faststart.patch
@@ -0,0 +1,301 @@
+From 650a3dbf0cb6e38011bd6ea3ccec7148c7e9adb9 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:01:45 -0700
+Subject: [PATCH 5/9] movenc: allow placing moov atom at beginning of file
+
+Adds option to reserve space for moov.
+---
+ libavformat/movenc.c | 22 ++++++++++++++++++++--
+ libavformat/movenc.h | 3 +++
+ 2 files changed, 23 insertions(+), 2 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index f41f8d7..684f8d6 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -51,6 +51,7 @@ static const AVOption options[] = {
+ { "separate_moof", "Write separate moof/mdat atoms for each track", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "frag_custom", "Flush fragments on caller requests", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FRAG_CUSTOM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "isml", "Create a live smooth streaming feed (for pushing to a publishing point)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_ISML}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
++ { "moov_size", "maximum moov size so it can be placed at the begin", offsetof(MOVMuxContext, reserved_moov_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
+ FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
+ { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+ { "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM},
+@@ -3146,8 +3147,13 @@ static int mov_write_header(AVFormatContext *s)
+ FF_MOV_FLAG_FRAGMENT;
+ }
+
+- if (!(mov->flags & FF_MOV_FLAG_FRAGMENT))
++ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
++ if(mov->reserved_moov_size) {
++ mov->reserved_moov_pos= avio_tell(pb);
++ avio_skip(pb, mov->reserved_moov_size);
++ }
+ mov_write_mdat_tag(pb, mov);
++ }
+
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ mov->time = ff_iso8601_to_unix_time(t->value);
+@@ -3219,9 +3225,21 @@ static int mov_write_trailer(AVFormatContext *s)
+ ffio_wfourcc(pb, "mdat");
+ avio_wb64(pb, mov->mdat_size + 16);
+ }
+- avio_seek(pb, moov_pos, SEEK_SET);
++ avio_seek(pb, mov->reserved_moov_size ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
+
+ mov_write_moov_tag(pb, mov, s);
++ if (mov->reserved_moov_size) {
++ int64_t size= mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
++ if(size < 8){
++ av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %"PRId64" additional\n", 8-size);
++ return -1;
++ }
++ avio_wb32(pb, size);
++ ffio_wfourcc(pb, "free");
++ for(i=0; i<size; i++)
++ avio_w8(pb, 0);
++ avio_seek(pb, moov_pos, SEEK_SET);
++ }
+ } else {
+ mov_flush_fragment(s);
+ mov_write_mfra_tag(pb, mov);
+diff --git a/libavformat/movenc.h b/libavformat/movenc.h
+index e20ef14..f91fc5f 100644
+--- a/libavformat/movenc.h
++++ b/libavformat/movenc.h
+@@ -153,6 +153,9 @@ typedef struct MOVMuxContext {
+ int max_fragment_size;
+ int ism_lookahead;
+ AVIOContext *mdat_buf;
++
++ int reserved_moov_size;
++ int64_t reserved_moov_pos;
+ } MOVMuxContext;
+
+ #define FF_MOV_FLAG_RTP_HINT 1
+--
+1.8.1.4
+
+From 256ce14e2492ccdcb987afd6fb66ef590e58f02e Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:11:32 -0700
+Subject: [PATCH 6/9] movenc: add faststart option for web streaming
+
+Faststart moves moov atom to beginning of file and rewrites the reset of
+the file after muxing is complete.
+---
+ libavformat/movenc.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++--
+ libavformat/movenc.h | 3 +-
+ 2 files changed, 137 insertions(+), 6 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 684f8d6..7348cf8 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -51,6 +51,7 @@ static const AVOption options[] = {
+ { "separate_moof", "Write separate moof/mdat atoms for each track", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "frag_custom", "Flush fragments on caller requests", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FRAG_CUSTOM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "isml", "Create a live smooth streaming feed (for pushing to a publishing point)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_ISML}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
++ { "faststart", "Run a second pass to put the moov at the beginning of the file", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FASTSTART}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "moov_size", "maximum moov size so it can be placed at the begin", offsetof(MOVMuxContext, reserved_moov_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
+ FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
+ { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+@@ -3007,6 +3008,14 @@ static int mov_write_header(AVFormatContext *s)
+ FF_MOV_FLAG_FRAG_CUSTOM))
+ mov->flags |= FF_MOV_FLAG_FRAGMENT;
+
++ /* faststart: moov at the beginning of the file, if supported */
++ if (mov->flags & FF_MOV_FLAG_FASTSTART) {
++ if (mov->flags & FF_MOV_FLAG_FRAGMENT)
++ mov->flags &= ~FF_MOV_FLAG_FASTSTART;
++ else
++ mov->reserved_moov_size = -1;
++ }
++
+ /* Non-seekable output is ok if using fragmentation. If ism_lookahead
+ * is enabled, we don't support non-seekable output at all. */
+ if (!s->pb->seekable &&
+@@ -3150,7 +3159,8 @@ static int mov_write_header(AVFormatContext *s)
+ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
+ if(mov->reserved_moov_size) {
+ mov->reserved_moov_pos= avio_tell(pb);
+- avio_skip(pb, mov->reserved_moov_size);
++ if(mov->reserved_moov_size > 0)
++ avio_skip(pb, mov->reserved_moov_size);
+ }
+ mov_write_mdat_tag(pb, mov);
+ }
+@@ -3191,6 +3201,115 @@ static int mov_write_header(AVFormatContext *s)
+ return -1;
+ }
+
++static int get_moov_size(AVFormatContext *s)
++{
++ int ret;
++ uint8_t *buf;
++ AVIOContext *moov_buf;
++ MOVMuxContext *mov = s->priv_data;
++
++ if ((ret = avio_open_dyn_buf(&moov_buf)) < 0)
++ return ret;
++ mov_write_moov_tag(moov_buf, mov, s);
++ ret = avio_close_dyn_buf(moov_buf, &buf);
++ av_free(buf);
++ return ret;
++}
++
++/**
++ * This function gets the moov size if moved to the top of the file: the chunk
++ * offset table can switch between stco (32-bit entries) to co64 (64-bit
++ * entries) when the moov is moved to the top, so the size of the moov would
++ * change. It also updates the chunk offset tables.
++ */
++static int compute_moov_size(AVFormatContext *s)
++{
++ int i, moov_size, moov_size2;
++ MOVMuxContext *mov = s->priv_data;
++
++ moov_size = get_moov_size(s);
++ if (moov_size < 0)
++ return moov_size;
++
++ for (i = 0; i < mov->nb_streams; i++)
++ mov->tracks[i].data_offset += moov_size;
++
++ moov_size2 = get_moov_size(s);
++ if (moov_size2 < 0)
++ return moov_size2;
++
++ /* if the size changed, we just switched from stco to co64 and needs to
++ * update the offsets */
++ if (moov_size2 != moov_size)
++ for (i = 0; i < mov->nb_streams; i++)
++ mov->tracks[i].data_offset += moov_size2 - moov_size;
++
++ return moov_size2;
++}
++
++static int shift_data(AVFormatContext *s)
++{
++ int ret = 0, moov_size;
++ MOVMuxContext *mov = s->priv_data;
++ int64_t pos, pos_end = avio_tell(s->pb);
++ uint8_t *buf, *read_buf[2];
++ int read_buf_id = 0;
++ int read_size[2];
++ AVIOContext *read_pb;
++
++ moov_size = compute_moov_size(s);
++ if (moov_size < 0)
++ return moov_size;
++
++ buf = av_malloc(moov_size * 2);
++ if (!buf)
++ return AVERROR(ENOMEM);
++ read_buf[0] = buf;
++ read_buf[1] = buf + moov_size;
++
++ /* Shift the data: the AVIO context of the output can only be used for
++ * writing, so we re-open the same output, but for reading. It also avoids
++ * a read/seek/write/seek back and forth. */
++ avio_flush(s->pb);
++ ret = avio_open(&read_pb, s->filename, AVIO_FLAG_READ);
++ if (ret < 0) {
++ av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for "
++ "the second pass (faststart)\n", s->filename);
++ goto end;
++ }
++
++ /* mark the end of the shift to up to the last data we wrote, and get ready
++ * for writing */
++ pos_end = avio_tell(s->pb);
++ avio_seek(s->pb, mov->reserved_moov_pos + moov_size, SEEK_SET);
++
++ /* start reading at where the new moov will be placed */
++ avio_seek(read_pb, mov->reserved_moov_pos, SEEK_SET);
++ pos = avio_tell(read_pb);
++
++#define READ_BLOCK do { \
++ read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
++ read_buf_id ^= 1; \
++} while (0)
++
++ /* shift data by chunk of at most moov_size */
++ READ_BLOCK;
++ do {
++ int n;
++ READ_BLOCK;
++ n = read_size[read_buf_id];
++ if (n <= 0)
++ break;
++ avio_write(s->pb, read_buf[read_buf_id], n);
++ pos += n;
++ } while (pos < pos_end);
++ avio_close(read_pb);
++
++end:
++ av_free(buf);
++ return ret;
++}
++
+ static int mov_write_trailer(AVFormatContext *s)
+ {
+ MOVMuxContext *mov = s->priv_data;
+@@ -3225,11 +3344,20 @@ static int mov_write_trailer(AVFormatContext *s)
+ ffio_wfourcc(pb, "mdat");
+ avio_wb64(pb, mov->mdat_size + 16);
+ }
+- avio_seek(pb, mov->reserved_moov_size ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
+
+- mov_write_moov_tag(pb, mov, s);
+- if (mov->reserved_moov_size) {
+- int64_t size= mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
++ avio_seek(pb, mov->reserved_moov_size > 0 ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
++
++ if (mov->reserved_moov_size == -1) {
++ av_log(s, AV_LOG_INFO, "Starting second pass: moving header on top of the file\n");
++ res = shift_data(s);
++ if (res == 0) {
++ avio_seek(s->pb, mov->reserved_moov_pos, SEEK_SET);
++ mov_write_moov_tag(pb, mov, s);
++ }
++ } else if (mov->reserved_moov_size > 0) {
++ int64_t size;
++ mov_write_moov_tag(pb, mov, s);
++ size = mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
+ if(size < 8){
+ av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %"PRId64" additional\n", 8-size);
+ return -1;
+@@ -3239,6 +3367,8 @@ static int mov_write_trailer(AVFormatContext *s)
+ for(i=0; i<size; i++)
+ avio_w8(pb, 0);
+ avio_seek(pb, moov_pos, SEEK_SET);
++ } else {
++ mov_write_moov_tag(pb, mov, s);
+ }
+ } else {
+ mov_flush_fragment(s);
+diff --git a/libavformat/movenc.h b/libavformat/movenc.h
+index f91fc5f..3ea0dd5 100644
+--- a/libavformat/movenc.h
++++ b/libavformat/movenc.h
+@@ -154,7 +154,7 @@ typedef struct MOVMuxContext {
+ int ism_lookahead;
+ AVIOContext *mdat_buf;
+
+- int reserved_moov_size;
++ int reserved_moov_size; ///< 0 for disabled, -1 for automatic, size otherwise
+ int64_t reserved_moov_pos;
+ } MOVMuxContext;
+
+@@ -165,6 +165,7 @@ typedef struct MOVMuxContext {
+ #define FF_MOV_FLAG_SEPARATE_MOOF 16
+ #define FF_MOV_FLAG_FRAG_CUSTOM 32
+ #define FF_MOV_FLAG_ISML 64
++#define FF_MOV_FLAG_FASTSTART 128
+
+ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
+
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A09-mp4-64bit.patch b/contrib/ffmpeg/A09-mp4-64bit.patch
new file mode 100644
index 000000000..04fec6032
--- /dev/null
+++ b/contrib/ffmpeg/A09-mp4-64bit.patch
@@ -0,0 +1,46 @@
+From 68f89a1ec9ccef22268158640c1f62f0370f48ba Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:12:54 -0700
+Subject: [PATCH 7/9] movenc: fix detection of 64bit offset requirement
+
+The old method doesn't work when moov is relocated to beginning of file
+---
+ libavformat/movenc.c | 16 +++++++++++++---
+ 1 file changed, 13 insertions(+), 3 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 7348cf8..2f6c003 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -83,15 +83,25 @@ static int64_t update_size(AVIOContext *pb, int64_t pos)
+ return curpos - pos;
+ }
+
++static int is_co64_required(const MOVTrack *track)
++{
++ int i;
++
++ for (i = 0; i < track->entry; i++) {
++ if (track->cluster[i].pos + track->data_offset > UINT32_MAX)
++ return 1;
++ }
++ return 0;
++}
++
+ /* Chunk offset atom */
+ static int mov_write_stco_tag(AVIOContext *pb, MOVTrack *track)
+ {
+ int i;
+- int mode64 = 0; // use 32 bit size variant if possible
++ int mode64 = is_co64_required(track); // use 32 bit size variant if possible
+ int64_t pos = avio_tell(pb);
+ avio_wb32(pb, 0); /* size */
+- if (pos > UINT32_MAX) {
+- mode64 = 1;
++ if (mode64) {
+ ffio_wfourcc(pb, "co64");
+ } else
+ ffio_wfourcc(pb, "stco");
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A10-mp4-track-enable.patch b/contrib/ffmpeg/A10-mp4-track-enable.patch
new file mode 100644
index 000000000..282326157
--- /dev/null
+++ b/contrib/ffmpeg/A10-mp4-track-enable.patch
@@ -0,0 +1,142 @@
+From 25a0ee27bb5d2bb46781ea4a2a3c88581ad75fde Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:16:08 -0700
+Subject: [PATCH 8/9] movenc: Make tkhd "enabled" flag QuickTime compatible
+
+QuickTime will play multiple audio tracks concurrently if this flag is
+set for multiple audio tracks. And if no subtitle track has this flag
+set QuickTime will show no subtitles in the subtitle menu.
+---
+ libavformat/mov.c | 4 +++-
+ libavformat/movenc.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++-
+ libavformat/movenc.h | 1 +
+ 3 files changed, 63 insertions(+), 2 deletions(-)
+
+diff --git a/libavformat/mov.c b/libavformat/mov.c
+index 7fe0548..cb0e395 100644
+--- a/libavformat/mov.c
++++ b/libavformat/mov.c
+@@ -2129,6 +2129,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+ AVStream *st;
+ MOVStreamContext *sc;
+ int version;
++ int flags;
+
+ if (c->fc->nb_streams < 1)
+ return 0;
+@@ -2136,13 +2137,14 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+ sc = st->priv_data;
+
+ version = avio_r8(pb);
+- avio_rb24(pb); /* flags */
++ flags = avio_rb24(pb); /* flags */
+ /*
+ MOV_TRACK_ENABLED 0x0001
+ MOV_TRACK_IN_MOVIE 0x0002
+ MOV_TRACK_IN_PREVIEW 0x0004
+ MOV_TRACK_IN_POSTER 0x0008
+ */
++ st->disposition |= (flags & 0x1) ? AV_DISPOSITION_DEFAULT : 0;
+
+ if (version == 1) {
+ avio_rb64(pb);
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 2f6c003..bc77a6f 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -1387,7 +1387,13 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
+ (version == 1) ? avio_wb32(pb, 104) : avio_wb32(pb, 92); /* size */
+ ffio_wfourcc(pb, "tkhd");
+ avio_w8(pb, version);
+- avio_wb24(pb, 0xf); /* flags (track enabled) */
++ avio_wb24(pb, (track->flags & MOV_TRACK_ENABLED) ? 0x3 : 0x2); /* flags */
++ /*
++ MOV_TRACK_ENABLED 0x0001
++ MOV_TRACK_IN_MOVIE 0x0002
++ MOV_TRACK_IN_PREVIEW 0x0004
++ MOV_TRACK_IN_POSTER 0x0008
++ */
+ if (version == 1) {
+ avio_wb64(pb, track->time);
+ avio_wb64(pb, track->time);
+@@ -3003,6 +3009,56 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
+ }
+ }
+
++// st->disposition controls the "enabled" flag in the tkhd tag.
++// QuickTime will not play a track if it is not enabled. So make sure
++// that one track of each type (audio, video, subtitle) is enabled.
++//
++// Subtitles are special. For audio and video, setting "enabled" also
++// makes the track "default" (i.e. it is rendered when played). For
++// subtitles, an "enabled" subtitle is not rendered by default, but
++// if no subtitle is enabled, the subtitle menu in QuickTime will be
++// empty!
++static void enable_tracks(AVFormatContext *s)
++{
++ MOVMuxContext *mov = s->priv_data;
++ int i;
++ uint8_t enabled[AVMEDIA_TYPE_NB];
++ int first[AVMEDIA_TYPE_NB];
++
++ for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
++ enabled[i] = 0;
++ first[i] = -1;
++ }
++
++ for (i = 0; i < s->nb_streams; i++) {
++ AVStream *st = s->streams[i];
++
++ if (st->codec->codec_type <= AVMEDIA_TYPE_UNKNOWN ||
++ st->codec->codec_type >= AVMEDIA_TYPE_NB)
++ continue;
++
++ if (first[st->codec->codec_type] < 0)
++ first[st->codec->codec_type] = i;
++ if (st->disposition & AV_DISPOSITION_DEFAULT) {
++ mov->tracks[i].flags |= MOV_TRACK_ENABLED;
++ enabled[st->codec->codec_type] = 1;
++ }
++ }
++
++ for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
++ switch (i) {
++ case AVMEDIA_TYPE_VIDEO:
++ case AVMEDIA_TYPE_AUDIO:
++ case AVMEDIA_TYPE_SUBTITLE:
++ if (!enabled[i] && first[i] >= 0)
++ mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED;
++ break;
++ default:
++ break;
++ }
++ }
++}
++
+ static int mov_write_header(AVFormatContext *s)
+ {
+ AVIOContext *pb = s->pb;
+@@ -3156,6 +3212,8 @@ static int mov_write_header(AVFormatContext *s)
+ }
+ }
+
++ enable_tracks(s);
++
+ if (mov->mode == MODE_ISM) {
+ /* If no fragmentation options have been set, set a default. */
+ if (!(mov->flags & (FF_MOV_FLAG_FRAG_KEYFRAME |
+diff --git a/libavformat/movenc.h b/libavformat/movenc.h
+index 3ea0dd5..9bb8a78 100644
+--- a/libavformat/movenc.h
++++ b/libavformat/movenc.h
+@@ -84,6 +84,7 @@ typedef struct MOVIndex {
+ int has_keyframes;
+ #define MOV_TRACK_CTTS 0x0001
+ #define MOV_TRACK_STPS 0x0002
++#define MOV_TRACK_ENABLED 0x0004
+ uint32_t flags;
+ int language;
+ int track_id;
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A11-mp4-chapter-properties.patch b/contrib/ffmpeg/A11-mp4-chapter-properties.patch
new file mode 100644
index 000000000..9f64af2cb
--- /dev/null
+++ b/contrib/ffmpeg/A11-mp4-chapter-properties.patch
@@ -0,0 +1,47 @@
+From 9393762b54c17abd736f8d5dd96cd22c334989da Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:19:16 -0700
+Subject: [PATCH 9/9] movenc: Make chapter track QuickTime compatible
+
+QuickTime requires that the stsd.text box be completely filled in.
+---
+ libavformat/movenc.c | 9 ++++++++-
+ 1 file changed, 8 insertions(+), 1 deletion(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index bc77a6f..96adfd7 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -2982,12 +2982,17 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
+ MOVTrack *track = &mov->tracks[tracknum];
+ AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
+ int i, len;
++ // These properties are required to make QT recognize the chapter track
++ uint8_t chapter_properties[43] = {0, 0, 0, 0, 0, 0, 0, 1,};
+
+ track->mode = mov->mode;
+ track->tag = MKTAG('t','e','x','t');
+ track->timescale = MOV_TIMESCALE;
+ track->enc = avcodec_alloc_context3(NULL);
+ track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
++ track->enc->extradata = av_malloc(43);
++ track->enc->extradata_size = 43;
++ memcpy(track->enc->extradata, chapter_properties, 43);
+
+ for (i = 0; i < s->nb_chapters; i++) {
+ AVChapter *c = s->chapters[i];
+@@ -3443,8 +3448,10 @@ static int mov_write_trailer(AVFormatContext *s)
+ mov_write_mfra_tag(pb, mov);
+ }
+
+- if (mov->chapter_track)
++ if (mov->chapter_track) {
++ av_free(mov->tracks[mov->chapter_track].enc->extradata);
+ av_freep(&mov->tracks[mov->chapter_track].enc);
++ }
+
+ for (i=0; i<mov->nb_streams; i++) {
+ if (mov->tracks[i].tag == MKTAG('r','t','p',' '))
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/module.defs b/contrib/ffmpeg/module.defs
index f906631cc..fdce86fde 100644
--- a/contrib/ffmpeg/module.defs
+++ b/contrib/ffmpeg/module.defs
@@ -39,6 +39,16 @@ FFMPEG.CONFIGURE.extra += \
--enable-encoder=libfdk_aac
endif
+ifeq (1,$(FEATURE.avformat))
+FFMPEG.CONFIGURE.extra += \
+ --enable-muxer=matroska \
+ --enable-muxer=webm \
+ --enable-muxer=mov \
+ --enable-muxer=mp4 \
+ --enable-muxer=psp \
+ --enable-muxer=ipod
+endif
+
## check against tuple: B-SYSTEM where B is { 0 | 1 } for cross-compiling flag
ifeq (0-cygwin,$(BUILD.cross)-$(BUILD.system))
FFMPEG.CONFIGURE.extra += --enable-pthreads --enable-memalign-hack