[FFmpeg-devel,17/23] avformat/matroskaenc: Allow empty filename for attachments

Submitted by Andreas Rheinhardt on Nov. 6, 2019, 2:49 a.m.

Details

Message ID 20191106024922.19228-17-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Nov. 6, 2019, 2:49 a.m.
The EBML as well as the Matroska specifications allow empty strings, yet
the Matroska muxer enforced the requirement that a filename tag exists
for attachments and errored out if it didn't. This has been changed: In
the absence of a filename, an empty string is used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/matroskaenc.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index f84e50f94e..e64e1e1036 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1677,6 +1677,7 @@  static int mkv_write_attachments(AVFormatContext *s)
         ebml_master attached_file;
         AVDictionaryEntry *t;
         const char *mimetype = NULL;
+        const char *filename;
 
         if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT)
             continue;
@@ -1685,11 +1686,11 @@  static int mkv_write_attachments(AVFormatContext *s)
 
         if (t = av_dict_get(st->metadata, "title", NULL, 0))
             put_ebml_string(dyn_cp, 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);
-            return AVERROR(EINVAL);
-        }
-        put_ebml_string(dyn_cp, MATROSKA_ID_FILENAME, t->value);
+        if (t = av_dict_get(st->metadata, "filename", NULL, 0)) {
+            filename = t->value;
+        } else
+            filename = "";
+        put_ebml_string(dyn_cp, MATROSKA_ID_FILENAME, filename);
         if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
             mimetype = t->value;
         else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) {