diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-07-19 22:52:16 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-07-19 23:32:04 +0200 |
commit | 07704c61dd70daaa4c1a5dec7892f127881106b6 (patch) | |
tree | be7613b7906a99d9939d1c93c0d68394a2772b9e /libavformat/matroskaenc.c | |
parent | 122536e01a0a016a2a9751baa6d5678353ec191a (diff) | |
download | ffmpeg-07704c61dd70daaa4c1a5dec7892f127881106b6.tar.gz |
avformat/matroskaenc: Only change chapter ids if needed.
This also fixes the case where negative chapter ids where input
And fixes the case where remuxing from mkv changed chapter ids
Found-by: Luca Barbato
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r-- | libavformat/matroskaenc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index dabef55daf..8078cc745b 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -104,6 +104,8 @@ typedef struct MatroskaMuxContext { int reserve_cues_space; int64_t cues_pos; + + uint32_t chapter_id_offset; } MatroskaMuxContext; @@ -790,7 +792,7 @@ static int mkv_write_chapters(AVFormatContext *s) AVDictionaryEntry *t = NULL; chapteratom = start_ebml_master(pb, MATROSKA_ID_CHAPTERATOM, 0); - put_ebml_uint(pb, MATROSKA_ID_CHAPTERUID, c->id + 1); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERUID, c->id + mkv->chapter_id_offset); put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMESTART, av_rescale_q(c->start, c->time_base, scale)); put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMEEND, @@ -882,6 +884,7 @@ static int mkv_check_tag(AVDictionary *m) static int mkv_write_tags(AVFormatContext *s) { + MatroskaMuxContext *mkv = s->priv_data; ebml_master tags = {0}; int i, ret; @@ -908,7 +911,7 @@ static int mkv_write_tags(AVFormatContext *s) if (!mkv_check_tag(ch->metadata)) continue; - ret = mkv_write_tag(s, ch->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID, ch->id + 1, &tags); + ret = mkv_write_tag(s, ch->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID, ch->id + mkv->chapter_id_offset, &tags); if (ret < 0) return ret; } @@ -1087,6 +1090,9 @@ static int mkv_write_header(AVFormatContext *s) ret = mkv_write_tracks(s); if (ret < 0) return ret; + for (i = 0; i < s->nb_chapters; i++) + mkv->chapter_id_offset = FFMAX(mkv->chapter_id_offset, 1LL - s->chapters[i]->id); + if (mkv->mode != MODE_WEBM) { ret = mkv_write_chapters(s); if (ret < 0) return ret; |