[FFmpeg-cvslog] avformat/matroskaenc: Only change chapter ids if needed.
Michael Niedermayer
git at videolan.org
Fri Jul 19 23:33:58 CEST 2013
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Jul 19 22:52:16 2013 +0200| [07704c61dd70daaa4c1a5dec7892f127881106b6] | committer: Michael Niedermayer
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 at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07704c61dd70daaa4c1a5dec7892f127881106b6
---
libavformat/matroskaenc.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index dabef55..8078cc7 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;
More information about the ffmpeg-cvslog
mailing list