diff options
author | John Stebbins <stebbins@jetheaddev.com> | 2013-08-19 16:05:30 -0700 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2013-08-20 15:18:42 +0100 |
commit | 6c786765cd5eb794dedd4a0970dfe689b16dfeeb (patch) | |
tree | bd9833358bf9aac74b9e1808001f76aac6942953 | |
parent | db03cb37fd9650b4a7c752d24a2e84ff27508ee8 (diff) | |
download | ffmpeg-6c786765cd5eb794dedd4a0970dfe689b16dfeeb.tar.gz |
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.
Signed-off-by: Martin Storsjö <martin@martin.st>
-rw-r--r-- | libavformat/movenc.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 3338f46e26..39d4e44a44 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -3074,7 +3074,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); @@ -3212,8 +3214,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 */ |