aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-12-29 03:26:05 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-04-21 07:49:39 +0200
commita9844341f78e6eba78a9bb503e71a5d9e3ceea81 (patch)
treee69ccb800507302853225b6b0eae62b4d4ed70e6 /libavformat
parentef45cccc81d5f0deff2c69d223bf0bd7c0012294 (diff)
downloadffmpeg-a9844341f78e6eba78a9bb503e71a5d9e3ceea81.tar.gz
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>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/matroskaenc.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 936dfba2ee..6796ac4747 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -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;
}