Skip to content

Commit

Permalink
Finally got the MP4 audio working fine
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 13, 2024
1 parent 693cfe1 commit fc426fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
18 changes: 5 additions & 13 deletions src/mp4/moof.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ enum BufError write_tfhd(
uint64_t flags = 0x0;
const bool base_data_offset_present = false;
const bool sample_description_index_present = false;
const bool default_sample_duration_present = true;
const bool default_sample_duration_present = false;
const bool default_sample_size_present = true;
const bool default_sample_flags_present = true;
const bool duration_is_empty = false;
const bool default_base_is_moof = false;
const bool default_base_is_moof = true;

if (base_data_offset_present) {
flags = flags | 0x000001;
Expand Down Expand Up @@ -278,10 +278,9 @@ enum BufError write_trun(
err = put_u8(ptr, 0);
chk_err; // 1 version
bool data_offset_present = true;
bool first_sample_flags_present = false;
bool sample_duration_present = !is_audio;
bool sample_size_present = !is_audio;
bool sample_flags_present = !is_audio;
bool first_sample_flags_present = true;
bool sample_duration_present = true;
bool sample_size_present = true;
{
uint64_t flags = 0x0;
if (data_offset_present) {
Expand All @@ -296,9 +295,6 @@ 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;

Expand Down Expand Up @@ -334,10 +330,6 @@ 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);
Expand Down
6 changes: 4 additions & 2 deletions src/mp4/mp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ enum BufError mp4_set_slice(const char *nal_data, const uint32_t nal_len,
char is_iframe) {
enum BufError err;

struct SampleInfo samples_info[9];
struct SampleInfo samples_info[2];
memset(samples_info, 0, sizeof(samples_info));
samples_info[0].size = nal_len + 4; // add size of sample
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 = default_sample_size *
buf_aud.offset / (aud_bitrate * 25 / 6.f);

buf_moof.offset = 0;
err = write_moof(
&buf_moof, 0, 0, 0, default_sample_size, samples_info,
1, samples_info + 1, buf_aud.offset / aud_framesize);
1, samples_info + 1, 1);
chk_err;

buf_mdat.offset = 0;
Expand Down

0 comments on commit fc426fe

Please sign in to comment.