diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-01-14 01:09:13 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-01-19 11:37:39 +0100 |
commit | dc555de823ac7e9be73dddafda26e4b15ea1cc3f (patch) | |
tree | 6549f60fdb0a45fe6e79c0527812c424c84643ce | |
parent | 0148e85c3ca143a3b7ae56e21f221cd78c334740 (diff) | |
download | ffmpeg-dc555de823ac7e9be73dddafda26e4b15ea1cc3f.tar.gz |
avformat/matroskaenc: Don't waste bytes on AttachedFiles' length fields
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r-- | libavformat/matroskaenc.c | 21 | ||||
-rw-r--r-- | tests/ref/lavf/mkv_attachment | 4 |
2 files changed, 15 insertions, 10 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 7bda9fdb6b..53016d34ec 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2057,30 +2057,35 @@ static int mkv_write_attachments(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { const AVStream *st = s->streams[i]; mkv_track *track = &mkv->tracks[i]; - ebml_master attached_file; + EBML_WRITER(6); const AVDictionaryEntry *t; const char *mimetype; if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT) continue; - attached_file = start_ebml_master(dyn_cp, MATROSKA_ID_ATTACHEDFILE, 0); + ebml_writer_open_master(&writer, MATROSKA_ID_ATTACHEDFILE); if (t = av_dict_get(st->metadata, "title", NULL, 0)) - put_ebml_string(dyn_cp, MATROSKA_ID_FILEDESC, t->value); + ebml_writer_add_string(&writer, MATROSKA_ID_FILEDESC, t->value); if (!(t = av_dict_get(st->metadata, "filename", NULL, 0))) { av_log(s, AV_LOG_ERROR, "Attachment stream %d has no filename tag.\n", i); ffio_free_dyn_buf(&dyn_cp); return AVERROR(EINVAL); } - put_ebml_string(dyn_cp, MATROSKA_ID_FILENAME, t->value); + ebml_writer_add_string(&writer, MATROSKA_ID_FILENAME, t->value); mimetype = get_mimetype(st); av_assert0(mimetype); - put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype); - put_ebml_binary(dyn_cp, MATROSKA_ID_FILEDATA, st->codecpar->extradata, st->codecpar->extradata_size); - put_ebml_uid(dyn_cp, MATROSKA_ID_FILEUID, track->uid); - end_ebml_master(dyn_cp, attached_file); + ebml_writer_add_string(&writer, MATROSKA_ID_FILEMIMETYPE, mimetype); + ebml_writer_add_bin(&writer, MATROSKA_ID_FILEDATA, + st->codecpar->extradata, st->codecpar->extradata_size); + ebml_writer_add_uid(&writer, MATROSKA_ID_FILEUID, track->uid); + ret = ebml_writer_write(&writer, dyn_cp); + if (ret < 0) { + ffio_free_dyn_buf(&dyn_cp); + return ret; + } } return end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_ATTACHMENTS, 0, 0, 1); diff --git a/tests/ref/lavf/mkv_attachment b/tests/ref/lavf/mkv_attachment index 0149bf2010..4a2f9eb7f1 100644 --- a/tests/ref/lavf/mkv_attachment +++ b/tests/ref/lavf/mkv_attachment @@ -1,3 +1,3 @@ -6a77b40186840d596bd584182ac3a283 *tests/data/lavf/lavf.mkv_attachment -472579 tests/data/lavf/lavf.mkv_attachment +32b24b97956f1fbcfbc1a94aac8f6202 *tests/data/lavf/lavf.mkv_attachment +472574 tests/data/lavf/lavf.mkv_attachment tests/data/lavf/lavf.mkv_attachment CRC=0xec6c3c68 |