changeset 5745:c31eb582165d libavformat

Simplify starting and ending clusters
author conrad
date Thu, 04 Mar 2010 08:53:08 +0000
parents a656843c86aa
children 89acf6c8fe9f
files matroskaenc.c
diffstat 1 files changed, 9 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/matroskaenc.c	Thu Mar 04 08:53:04 2010 +0000
+++ b/matroskaenc.c	Thu Mar 04 08:53:08 2010 +0000
@@ -725,14 +725,6 @@
     ret = mkv_write_chapters(s);
     if (ret < 0) return ret;
 
-    ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb));
-    if (ret < 0) return ret;
-
-    mkv->cluster_pos = url_ftell(pb);
-    mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0);
-    put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0);
-    mkv->cluster_pts = 0;
-
     if (url_is_streamed(s->pb))
         mkv_write_seekhead(pb, mkv->main_seekhead);
 
@@ -849,12 +841,7 @@
     int duration = pkt->duration;
     int ret;
 
-    // start a new cluster every 5 MB or 5 sec
-    if (url_ftell(pb) > mkv->cluster_pos + 5*1024*1024 || pkt->pts > mkv->cluster_pts + 5000) {
-        av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64
-               " bytes, pts %" PRIu64 "\n", url_ftell(pb), pkt->pts);
-        end_ebml_master(pb, mkv->cluster);
-
+    if (!mkv->cluster_pos) {
         ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb));
         if (ret < 0) return ret;
 
@@ -882,6 +869,14 @@
         if (ret < 0) return ret;
     }
 
+    // start a new cluster every 5 MB or 5 sec
+    if (url_ftell(pb) > mkv->cluster_pos + 5*1024*1024 || pkt->pts > mkv->cluster_pts + 5000) {
+        av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64
+               " bytes, pts %" PRIu64 "\n", url_ftell(pb), pkt->pts);
+        end_ebml_master(pb, mkv->cluster);
+        mkv->cluster_pos = 0;
+    }
+
     mkv->duration = FFMAX(mkv->duration, pkt->pts + duration);
     return 0;
 }