1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avformat/matroskaenc: Only write Tracks if there is a track

The Matroska muxer does not write every stream as a Matroska track;
some streams are written as AttachedFile. But should no stream be
written as a Matroska track, the Matroska muxer would nevertheless
write a Tracks element without a TrackEntry. This is against the spec.
This commit changes this and only writes a Tracks if there is a Matroska
track.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2019-12-29 03:26:05 +01:00
parent ef45cccc81
commit a9844341f7

View File

@ -128,7 +128,7 @@ typedef struct MatroskaMuxContext {
AVPacket cur_audio_pkt;
int have_attachments;
unsigned nb_attachments;
int have_video;
int reserve_cues_space;
@ -1113,7 +1113,6 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
AVDictionaryEntry *tag;
if (par->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
mkv->have_attachments = 1;
return 0;
}
@ -1370,6 +1369,9 @@ static int mkv_write_tracks(AVFormatContext *s)
AVIOContext *pb = s->pb;
int i, ret, default_stream_exists = 0;
if (mkv->nb_attachments == s->nb_streams)
return 0;
mkv_add_seekhead_entry(mkv, MATROSKA_ID_TRACKS, avio_tell(pb));
ret = start_ebml_master_crc32(&mkv->tracks_bc, mkv);
@ -1619,7 +1621,7 @@ static int mkv_write_tags(AVFormatContext *s)
}
}
if (mkv->have_attachments && mkv->mode != MODE_WEBM) {
if (mkv->nb_attachments && mkv->mode != MODE_WEBM) {
for (i = 0; i < s->nb_streams; i++) {
mkv_track *track = &mkv->tracks[i];
AVStream *st = s->streams[i];
@ -1653,7 +1655,7 @@ static int mkv_write_attachments(AVFormatContext *s)
AVIOContext *dyn_cp = NULL, *pb = s->pb;
int i, ret;
if (!mkv->have_attachments)
if (!mkv->nb_attachments)
return 0;
mkv_add_seekhead_entry(mkv, MATROSKA_ID_ATTACHMENTS, avio_tell(pb));
@ -2499,9 +2501,12 @@ static int mkv_write_trailer(AVFormatContext *s)
put_ebml_float(mkv->info_bc, MATROSKA_ID_DURATION, mkv->duration);
end_ebml_master_crc32(pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO, 0, 0);
// write tracks master
avio_seek(pb, mkv->tracks_pos, SEEK_SET);
end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS, 0, 0);
if (mkv->tracks_bc) {
// write Tracks master
avio_seek(pb, mkv->tracks_pos, SEEK_SET);
end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv,
MATROSKA_ID_TRACKS, 0, 0);
}
// update stream durations
if (mkv->tags_bc) {
@ -2649,6 +2654,7 @@ static int mkv_init(struct AVFormatContext *s)
av_log(s, AV_LOG_WARNING, "Stream %d will be ignored "
"as WebM doesn't support attachments.\n", i);
}
mkv->nb_attachments++;
continue;
}