mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Make FLAC encoder bit depth depend on input sample format, add sampleFormat audio transformation option, fix incorrect bitrate validation for FLAC (closes #357)
This commit is contained in:
+26
-1
@@ -50,7 +50,13 @@ import {
|
||||
customAudioEncoders,
|
||||
} from './custom-coder';
|
||||
import { EncodedPacket, EncodedPacketSideData } from './packet';
|
||||
import { AudioSample, clampCropRectangle, VideoSample } from './sample';
|
||||
import {
|
||||
AudioSample,
|
||||
audioSampleToInterleavedFormat,
|
||||
clampCropRectangle,
|
||||
toInterleavedAudioFormat,
|
||||
VideoSample,
|
||||
} from './sample';
|
||||
import {
|
||||
AudioEncodingConfig,
|
||||
buildAudioEncoderConfig,
|
||||
@@ -1888,6 +1894,21 @@ class AudioEncoderWrapper {
|
||||
private async processAndEncode(audioSample: AudioSample, shouldClose: boolean) {
|
||||
const config = this.encodingConfig;
|
||||
|
||||
if (
|
||||
config.transform?.sampleFormat !== undefined
|
||||
&& toInterleavedAudioFormat(audioSample.format) !== config.transform.sampleFormat
|
||||
) {
|
||||
// Do a sample format conversion
|
||||
const newSample = audioSampleToInterleavedFormat(audioSample, config.transform.sampleFormat);
|
||||
|
||||
if (shouldClose) {
|
||||
audioSample.close();
|
||||
}
|
||||
|
||||
audioSample = newSample;
|
||||
shouldClose = true;
|
||||
}
|
||||
|
||||
if (config.transform?.process) {
|
||||
let processed = config.transform.process(audioSample);
|
||||
if (processed instanceof Promise) {
|
||||
@@ -1910,6 +1931,10 @@ class AudioEncoderWrapper {
|
||||
}
|
||||
await this.encodeSample(sample, true);
|
||||
}
|
||||
|
||||
if (shouldClose) {
|
||||
audioSample.close();
|
||||
}
|
||||
} else {
|
||||
await this.encodeSample(audioSample, shouldClose);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user