Skip to content

Commit

Permalink
Merge pull request #62 from iknow/fix-hardcoded-preskip
Browse files Browse the repository at this point in the history
Read preskip and gain from codec private
  • Loading branch information
Vanilagy authored Sep 2, 2024
2 parents d572599 + cc8fa1d commit ad79ab4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 40 deletions.
37 changes: 23 additions & 14 deletions build/mp4-muxer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build/mp4-muxer.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/mp4-muxer.min.mjs

Large diffs are not rendered by default.

37 changes: 23 additions & 14 deletions build/mp4-muxer.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 23 additions & 8 deletions src/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,29 @@ export const esds = (track: Track) => {
};

/** Opus Specific Box. */
export const dOps = (track: AudioTrack) => box('dOps', [
u8(0), // Version
u8(track.info.numberOfChannels), // OutputChannelCount
u16(3840), // PreSkip, should be at least 80 milliseconds worth of playback, measured in 48000 Hz samples
u32(track.info.sampleRate), // InputSampleRate
fixed_8_8(0), // OutputGain
u8(0) // ChannelMappingFamily
]);
export const dOps = (track: AudioTrack) => {
// Default PreSkip, should be at least 80 milliseconds worth of playback, measured in 48000 Hz samples
let preskip = 3840;
let gain = 0;

// Read preskip and from codec private data from the encoder
// https://www.rfc-editor.org/rfc/rfc7845#section-5
const description = track.info.decoderConfig.description;
if (description) {
const view = new DataView(ArrayBuffer.isView(description) ? description.buffer : description);
preskip = view.getUint16(10, true);
gain = view.getInt16(14, true);
}

return box('dOps', [
u8(0), // Version
u8(track.info.numberOfChannels), // OutputChannelCount
u16(preskip),
u32(track.info.sampleRate), // InputSampleRate
fixed_8_8(gain), // OutputGain
u8(0) // ChannelMappingFamily
]);
};

/**
* Time-To-Sample Box: Stores duration information for a media's samples, providing a mapping from a time in a media
Expand Down

0 comments on commit ad79ab4

Please sign in to comment.