Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate silent aac frame based on original codec #6123

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/demux/audio/adts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type AudioConfig = {
samplerate: number;
channelCount: number;
codec: string;
parsedCodec: string;
manifestCodec: string;
};

Expand All @@ -32,6 +33,7 @@ export function getAudioConfig(
audioCodec: string,
): AudioConfig | void {
let adtsObjectType: number;
let originalAdtsObjectType: number;
let adtsExtensionSamplingIndex: number;
let adtsChannelConfig: number;
let config: number[];
Expand All @@ -42,7 +44,8 @@ export function getAudioConfig(
8000, 7350,
];
// byte 2
adtsObjectType = ((data[offset + 2] & 0xc0) >>> 6) + 1;
adtsObjectType = originalAdtsObjectType =
((data[offset + 2] & 0xc0) >>> 6) + 1;
const adtsSamplingIndex = (data[offset + 2] & 0x3c) >>> 2;
if (adtsSamplingIndex > adtsSamplingRates.length - 1) {
const error = new Error(`invalid ADTS sampling index:${adtsSamplingIndex}`);
Expand Down Expand Up @@ -167,6 +170,7 @@ export function getAudioConfig(
samplerate: adtsSamplingRates[adtsSamplingIndex],
channelCount: adtsChannelConfig,
codec: 'mp4a.40.' + adtsObjectType,
parsedCodec: 'mp4a.40.' + originalAdtsObjectType,
manifestCodec,
};
}
Expand Down Expand Up @@ -244,8 +248,9 @@ export function initTrackConfig(
track.channelCount = config.channelCount;
track.codec = config.codec;
track.manifestCodec = config.manifestCodec;
track.parsedCodec = config.parsedCodec;
logger.log(
`parsed codec:${track.codec}, rate:${config.samplerate}, channels:${config.channelCount}`,
`parsed codec:${track.parsedCodec}, codec:${track.codec}, rate:${config.samplerate}, channels:${config.channelCount}`,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/remux/mp4-remuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ export default class MP4Remuxer implements Remuxer {
for (let j = 0; j < missing; j++) {
const newStamp = Math.max(nextPts as number, 0);
let fillFrame = AAC.getSilentFrame(
track.manifestCodec || track.codec,
track.parsedCodec || track.manifestCodec || track.codec,
track.channelCount,
);
if (!fillFrame) {
Expand Down Expand Up @@ -1077,7 +1077,7 @@ export default class MP4Remuxer implements Remuxer {
const nbSamples: number = Math.ceil((endDTS - startDTS) / frameDuration);
// silent frame
const silentFrame: Uint8Array | undefined = AAC.getSilentFrame(
track.manifestCodec || track.codec,
track.parsedCodec || track.manifestCodec || track.codec,
track.channelCount,
);

Expand Down
1 change: 1 addition & 0 deletions src/types/demuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface DemuxedAudioTrack extends DemuxedTrack {
segmentCodec?: string;
channelCount?: number;
manifestCodec?: string;
parsedCodec?: string;
samples: AudioSample[];
}

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/demuxer/adts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('getAudioConfig', function () {
samplerate: 96000,
channelCount: 0,
codec: 'mp4a.40.2',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.29',
});
});
Expand All @@ -61,6 +62,7 @@ describe('getAudioConfig', function () {
samplerate: 11025,
channelCount: 0,
codec: 'mp4a.40.5',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.29',
});
});
Expand All @@ -78,6 +80,7 @@ describe('getAudioConfig', function () {
samplerate: 11025,
channelCount: 0,
codec: 'mp4a.40.2',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.29',
});
});
Expand All @@ -95,6 +98,7 @@ describe('getAudioConfig', function () {
samplerate: 11025,
channelCount: 0,
codec: 'mp4a.40.5',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.29',
});
});
Expand All @@ -112,6 +116,7 @@ describe('getAudioConfig', function () {
samplerate: 11025,
channelCount: 0,
codec: 'mp4a.40.5',
parsedCodec: 'mp4a.40.1',
manifestCodec: undefined,
});
});
Expand All @@ -129,6 +134,7 @@ describe('getAudioConfig', function () {
samplerate: 64000,
channelCount: 0,
codec: 'mp4a.40.5',
parsedCodec: 'mp4a.40.1',
manifestCodec: undefined,
});
});
Expand All @@ -146,6 +152,7 @@ describe('getAudioConfig', function () {
samplerate: 11025,
channelCount: 0,
codec: 'mp4a.40.5',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.5',
});
});
Expand All @@ -164,6 +171,7 @@ describe('getAudioConfig', function () {
samplerate: 11025,
channelCount: 1,
codec: 'mp4a.40.2',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.2',
});
});
Expand All @@ -181,6 +189,7 @@ describe('getAudioConfig', function () {
samplerate: 64000,
channelCount: 0,
codec: 'mp4a.40.2',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.2',
});
});
Expand Down Expand Up @@ -350,6 +359,7 @@ describe('initTrackConfig', function () {
samplerate: 11025,
channelCount: 0,
codec: 'mp4a.40.5',
parsedCodec: 'mp4a.40.1',
manifestCodec: 'mp4a.40.29',
});
});
Expand Down
Loading