From 91e90817d241e95f9b13be3a75b35f7b61c30ab6 Mon Sep 17 00:00:00 2001 From: derrod Date: Mon, 30 Dec 2024 15:08:15 +0100 Subject: [PATCH] obs-outputs: Fix tkhd/mvhd box version with 64-bit timestamps --- plugins/obs-outputs/mp4-mux.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/obs-outputs/mp4-mux.c b/plugins/obs-outputs/mp4-mux.c index 1f253cc41..a88a626d1 100644 --- a/plugins/obs-outputs/mp4-mux.c +++ b/plugins/obs-outputs/mp4-mux.c @@ -157,10 +157,12 @@ static size_t mp4_write_mvhd(struct mp4_mux *mux) break; } } + bool extended_ts = duration > UINT32_MAX || mux->creation_time > UINT32_MAX; + uint8_t version = extended_ts ? 1 : 0; - write_fullbox(s, 0, "mvhd", 0, 0); + write_fullbox(s, 0, "mvhd", version, 0); - if (duration > UINT32_MAX || mux->creation_time > UINT32_MAX) { + if (extended_ts) { s_wb64(s, mux->creation_time); // creation time s_wb64(s, mux->creation_time); // modification time s_wb32(s, 1000); // timescale @@ -203,12 +205,14 @@ static size_t mp4_write_tkhd(struct mp4_mux *mux, struct mp4_track *track) size_t start = serializer_get_pos(s); uint64_t duration = util_mul_div64(track->duration, 1000, track->timebase_den); + bool extended_ts = duration > UINT32_MAX || mux->creation_time > UINT32_MAX; + uint8_t version = extended_ts ? 1 : 0; /* Flags are 0x1 (enabled) | 0x2 (in movie) */ static const uint32_t flags = 0x1 | 0x2; - write_fullbox(s, 0, "tkhd", 0, flags); + write_fullbox(s, 0, "tkhd", version, flags); - if (duration > UINT32_MAX || mux->creation_time > UINT32_MAX) { + if (extended_ts) { s_wb64(s, mux->creation_time); // creation time s_wb64(s, mux->creation_time); // modification time s_wb32(s, track->track_id); // track_id