From 9f768665d28676c83f6c2a9deb44e4bfba4cc1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Tue, 13 Aug 2024 09:08:26 -0400 Subject: [PATCH] Continuing to fix audio on MP4 containers --- src/mp4/moof.c | 8 ++++++++ src/mp4/mp4.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mp4/moof.c b/src/mp4/moof.c index ce39198..abd7a98 100644 --- a/src/mp4/moof.c +++ b/src/mp4/moof.c @@ -281,6 +281,7 @@ enum BufError write_trun( const bool first_sample_flags_present = false; const bool sample_duration_present = true; const bool sample_size_present = true; + const bool sample_flags_present = true; { uint64_t flags = 0x0; if (data_offset_present) { @@ -295,6 +296,9 @@ enum BufError write_trun( if (sample_size_present) { flags = flags | 0x000200; } // 0x000200 sample-size-present + if (sample_flags_present) { + flags = flags | 0x000400; + } // 0x000400 sample-flags-present err = put_u8(ptr, flags >> 16); chk_err; @@ -330,6 +334,10 @@ enum BufError write_trun( err = put_u32_be(ptr, sample_info.size); chk_err; // 4 sample_size } + if (sample_flags_present) { + err = put_u32_be(ptr, sample_info.flags); + chk_err; // 4 sample_flags + } } err = put_u32_be_to_offset(ptr, start_atom, ptr->offset - start_atom); diff --git a/src/mp4/mp4.c b/src/mp4/mp4.c index aabc355..0281e56 100644 --- a/src/mp4/mp4.c +++ b/src/mp4/mp4.c @@ -106,7 +106,8 @@ enum BufError mp4_set_slice(const char *nal_data, const uint32_t nal_len, samples_info[0].duration = default_sample_size; samples_info[0].flags = is_iframe ? 0 : 65536; samples_info[1].size = buf_aud.offset; - samples_info[1].duration = 1152 * buf_aud.offset / aud_framesize; + samples_info[1].duration = 40000.f * + (buf_aud.offset / (aud_bitrate * 25 / 6.f)); buf_moof.offset = 0; err = write_moof(