From d77ae15b461e8add21d5d8a4f187d2936fb9334a Mon Sep 17 00:00:00 2001 From: mid <> Date: Sun, 12 Oct 2025 11:19:11 +0300 Subject: [PATCH] MKV output bugfixes --- hi/mkv.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hi/mkv.c b/hi/mkv.c index 795e505..9c4ff11 100644 --- a/hi/mkv.c +++ b/hi/mkv.c @@ -272,7 +272,7 @@ struct Internal { size_t videoTrack, audioTrack; size_t currentClusterTimecode; - + bool beforeFirstCluster; bool codecPrivatesFound; CHiBSFrames *audioBacklog; @@ -315,12 +315,13 @@ static int muxmkv_perform(CHiPubNode *pubn) { size_t nextTimestamp = next_timestamp(this); - bool shouldUpdateCluster = (this->videoBacklog && this->videoBacklog->count && (this->videoBacklog->data[0].flags & CUTIHI_BS_FLAG_KEY)) || (nextTimestamp - this->currentClusterTimecode > 15000); + bool shouldUpdateCluster = this->beforeFirstCluster || (this->videoBacklog && this->videoBacklog->count && (this->videoBacklog->data[0].flags & CUTIHI_BS_FLAG_KEY)) || (nextTimestamp - this->currentClusterTimecode > 15000); if(shouldUpdateCluster) { - if(this->currentClusterTimecode != 0) { + if(!this->beforeFirstCluster) { ebml_writer_pop(&this->wr); } + this->beforeFirstCluster = false; // Cluster ebml_writer_push(&this->wr, 0x1F43B675); @@ -493,14 +494,14 @@ static int muxmkv_perform(CHiPubNode *pubn) { assert(this->audioBacklog->data[0].flags & CUTIHI_BS_SETUP_PACKET); - if(CHi_Crawl(&pubn->sinks[0])->type == CUTIHI_VAL_OPUSBS) { + if(CHi_Crawl(&pubn->sinks[1])->type == CUTIHI_VAL_OPUSBS) { ebml_writer_put(&this->wr, 0x86, EBML_STRING, (EBMLPrimitive) {.string = "A_OPUS"}); CHiBSFrame *opusHead = &this->audioBacklog->data[0]; // CodecPrivate ebml_writer_put(&this->wr, 0x63A2, EBML_BINARY, (EBMLPrimitive) {.binary = {.length = opusHead->sz, .ptr = opusHead->ptr}}); - } else if(CHi_Crawl(&pubn->sinks[0])->type == CUTIHI_VAL_AACBS) { + } else if(CHi_Crawl(&pubn->sinks[1])->type == CUTIHI_VAL_AACBS) { ebml_writer_put(&this->wr, 0x86, EBML_STRING, (EBMLPrimitive) {.string = "A_AAC/MPEG2/LC"}); } @@ -547,6 +548,7 @@ static int muxmkv_start(CHiPubNode *pubn) { this->currentClusterTimecode = 0; this->codecPrivatesFound = false; + this->beforeFirstCluster = true; int trackNum = 1;