]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/matroskaenc.c
nutdec: check chapter creation in decode_info_header
[ffmpeg] / libavformat / matroskaenc.c
index 6b2e390e90e03127bfdea9ca431e772933ea1cda..6f55c690439ff4fcfba2950373baff12d78f5eb0 100644 (file)
@@ -120,6 +120,7 @@ typedef struct MatroskaMuxContext {
     int64_t cluster_time_limit;
     int is_dash;
     int dash_track_number;
+    int is_live;
 
     uint32_t chapter_id_offset;
     int wrote_chapters;
@@ -1270,6 +1271,11 @@ static int mkv_write_attachments(AVFormatContext *s)
                     mimetype = ff_mkv_mime_tags[i].str;
                     break;
                 }
+            for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++)
+                if (ff_mkv_image_mime_tags[i].id == st->codec->codec_id) {
+                    mimetype = ff_mkv_image_mime_tags[i].str;
+                    break;
+                }
         }
         if (!mimetype) {
             av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and "
@@ -1407,7 +1413,9 @@ static int mkv_write_header(AVFormatContext *s)
     // reserve space for the duration
     mkv->duration = 0;
     mkv->duration_offset = avio_tell(pb);
-    put_ebml_void(pb, 11);                  // assumes double-precision float to be written
+    if (!mkv->is_live) {
+        put_ebml_void(pb, 11);              // assumes double-precision float to be written
+    }
     end_ebml_master(pb, segment_info);
 
     ret = mkv_write_tracks(s);
@@ -1431,7 +1439,7 @@ static int mkv_write_header(AVFormatContext *s)
             return ret;
     }
 
-    if (!s->pb->seekable)
+    if (!s->pb->seekable && !mkv->is_live)
         mkv_write_seekhead(pb, mkv->main_seekhead);
 
     mkv->cues = mkv_start_cues(mkv->segment_offset);
@@ -1950,7 +1958,9 @@ static int mkv_write_trailer(AVFormatContext *s)
         avio_seek(pb, currentpos, SEEK_SET);
     }
 
-    end_ebml_master(pb, mkv->segment);
+    if (!mkv->is_live) {
+        end_ebml_master(pb, mkv->segment);
+    }
     av_freep(&mkv->tracks);
     av_freep(&mkv->cues->entries);
     av_freep(&mkv->cues);
@@ -2014,6 +2024,7 @@ static const AVOption options[] = {
     { "cluster_time_limit",  "Store at most the provided number of milliseconds in a cluster.",                               OFFSET(cluster_time_limit), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, FLAGS },
     { "dash", "Create a WebM file conforming to WebM DASH specification", OFFSET(is_dash), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
     { "dash_track_number", "Track number for the DASH stream", OFFSET(dash_track_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 127, FLAGS },
+    { "live", "Write files assuming it is a live stream.", OFFSET(is_live), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
     { "allow_raw_vfw", "allow RAW VFW mode", OFFSET(allow_raw_vfw), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
     { NULL },
 };