MKV output bugfixes

This commit is contained in:
mid 2025-10-12 11:19:11 +03:00
parent fb6b0dd492
commit d77ae15b46

View File

@ -272,7 +272,7 @@ struct Internal {
size_t videoTrack, audioTrack; size_t videoTrack, audioTrack;
size_t currentClusterTimecode; size_t currentClusterTimecode;
bool beforeFirstCluster;
bool codecPrivatesFound; bool codecPrivatesFound;
CHiBSFrames *audioBacklog; CHiBSFrames *audioBacklog;
@ -315,12 +315,13 @@ static int muxmkv_perform(CHiPubNode *pubn) {
size_t nextTimestamp = next_timestamp(this); 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(shouldUpdateCluster) {
if(this->currentClusterTimecode != 0) { if(!this->beforeFirstCluster) {
ebml_writer_pop(&this->wr); ebml_writer_pop(&this->wr);
} }
this->beforeFirstCluster = false;
// Cluster // Cluster
ebml_writer_push(&this->wr, 0x1F43B675); 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); 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"}); ebml_writer_put(&this->wr, 0x86, EBML_STRING, (EBMLPrimitive) {.string = "A_OPUS"});
CHiBSFrame *opusHead = &this->audioBacklog->data[0]; CHiBSFrame *opusHead = &this->audioBacklog->data[0];
// CodecPrivate // CodecPrivate
ebml_writer_put(&this->wr, 0x63A2, EBML_BINARY, (EBMLPrimitive) {.binary = {.length = opusHead->sz, .ptr = opusHead->ptr}}); 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"}); 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->currentClusterTimecode = 0;
this->codecPrivatesFound = false; this->codecPrivatesFound = false;
this->beforeFirstCluster = true;
int trackNum = 1; int trackNum = 1;