mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
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>
This commit is contained in:
parent
122536e01a
commit
07704c61dd
@ -104,6 +104,8 @@ typedef struct MatroskaMuxContext {
|
|||||||
|
|
||||||
int reserve_cues_space;
|
int reserve_cues_space;
|
||||||
int64_t cues_pos;
|
int64_t cues_pos;
|
||||||
|
|
||||||
|
uint32_t chapter_id_offset;
|
||||||
} MatroskaMuxContext;
|
} MatroskaMuxContext;
|
||||||
|
|
||||||
|
|
||||||
@ -790,7 +792,7 @@ static int mkv_write_chapters(AVFormatContext *s)
|
|||||||
AVDictionaryEntry *t = NULL;
|
AVDictionaryEntry *t = NULL;
|
||||||
|
|
||||||
chapteratom = start_ebml_master(pb, MATROSKA_ID_CHAPTERATOM, 0);
|
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,
|
put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMESTART,
|
||||||
av_rescale_q(c->start, c->time_base, scale));
|
av_rescale_q(c->start, c->time_base, scale));
|
||||||
put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMEEND,
|
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)
|
static int mkv_write_tags(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
|
MatroskaMuxContext *mkv = s->priv_data;
|
||||||
ebml_master tags = {0};
|
ebml_master tags = {0};
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
@ -908,7 +911,7 @@ static int mkv_write_tags(AVFormatContext *s)
|
|||||||
if (!mkv_check_tag(ch->metadata))
|
if (!mkv_check_tag(ch->metadata))
|
||||||
continue;
|
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;
|
if (ret < 0) return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1087,6 +1090,9 @@ static int mkv_write_header(AVFormatContext *s)
|
|||||||
ret = mkv_write_tracks(s);
|
ret = mkv_write_tracks(s);
|
||||||
if (ret < 0) return ret;
|
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) {
|
if (mkv->mode != MODE_WEBM) {
|
||||||
ret = mkv_write_chapters(s);
|
ret = mkv_write_chapters(s);
|
||||||
if (ret < 0) return ret;
|
if (ret < 0) return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user