mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Fix AudioData to AudioBuffer conversion
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
<input type="file" accept="video/mp4">
|
<input type="file" accept="video/mp4,video/quicktime,audio/x-m4a,video/x-m4v">
|
||||||
|
|
||||||
<div id="player"
|
<div id="player"
|
||||||
style="display: none; flex-direction: column; align-items: center;
|
style="display: none; flex-direction: column; align-items: center;
|
||||||
|
|||||||
Vendored
+4
-8
@@ -6214,9 +6214,7 @@ ${cue.notes ?? ""}`;
|
|||||||
}
|
}
|
||||||
decoderConfig = null;
|
decoderConfig = null;
|
||||||
async createDecoder(onFrame) {
|
async createDecoder(onFrame) {
|
||||||
if (!this.decoderConfig) {
|
this.decoderConfig ??= await this.videoTrack.getDecoderConfig();
|
||||||
this.decoderConfig = await this.videoTrack.getDecoderConfig();
|
|
||||||
}
|
|
||||||
const decoder = new VideoDecoder({
|
const decoder = new VideoDecoder({
|
||||||
output: onFrame,
|
output: onFrame,
|
||||||
error: (error) => console.error(error)
|
error: (error) => console.error(error)
|
||||||
@@ -6265,9 +6263,7 @@ ${cue.notes ?? ""}`;
|
|||||||
}
|
}
|
||||||
decoderConfig = null;
|
decoderConfig = null;
|
||||||
async createDecoder(onData) {
|
async createDecoder(onData) {
|
||||||
if (!this.decoderConfig) {
|
this.decoderConfig ??= await this.audioTrack.getDecoderConfig();
|
||||||
this.decoderConfig = await this.audioTrack.getDecoderConfig();
|
|
||||||
}
|
|
||||||
const decoder = new AudioDecoder({
|
const decoder = new AudioDecoder({
|
||||||
output: onData,
|
output: onData,
|
||||||
error: (error) => console.error(error)
|
error: (error) => console.error(error)
|
||||||
@@ -6303,9 +6299,9 @@ ${cue.notes ?? ""}`;
|
|||||||
length: data.numberOfFrames,
|
length: data.numberOfFrames,
|
||||||
sampleRate: data.sampleRate
|
sampleRate: data.sampleRate
|
||||||
});
|
});
|
||||||
|
const dataBytes = new Float32Array(data.allocationSize({ planeIndex: 0, format: "f32-planar" }) / 4);
|
||||||
for (let i = 0; i < data.numberOfChannels; i++) {
|
for (let i = 0; i < data.numberOfChannels; i++) {
|
||||||
const dataBytes = new Float32Array(data.allocationSize({ planeIndex: i }));
|
data.copyTo(dataBytes, { planeIndex: i, format: "f32-planar" });
|
||||||
data.copyTo(dataBytes, { planeIndex: i });
|
|
||||||
audioBuffer.copyToChannel(dataBytes, i);
|
audioBuffer.copyToChannel(dataBytes, i);
|
||||||
}
|
}
|
||||||
const sampleDuration = 1 / data.sampleRate;
|
const sampleDuration = 1 / data.sampleRate;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+4
-8
@@ -6149,9 +6149,7 @@ var VideoFrameDrain = class extends BaseMediaFrameDrain {
|
|||||||
}
|
}
|
||||||
decoderConfig = null;
|
decoderConfig = null;
|
||||||
async createDecoder(onFrame) {
|
async createDecoder(onFrame) {
|
||||||
if (!this.decoderConfig) {
|
this.decoderConfig ??= await this.videoTrack.getDecoderConfig();
|
||||||
this.decoderConfig = await this.videoTrack.getDecoderConfig();
|
|
||||||
}
|
|
||||||
const decoder = new VideoDecoder({
|
const decoder = new VideoDecoder({
|
||||||
output: onFrame,
|
output: onFrame,
|
||||||
error: (error) => console.error(error)
|
error: (error) => console.error(error)
|
||||||
@@ -6200,9 +6198,7 @@ var AudioDataDrain = class extends BaseMediaFrameDrain {
|
|||||||
}
|
}
|
||||||
decoderConfig = null;
|
decoderConfig = null;
|
||||||
async createDecoder(onData) {
|
async createDecoder(onData) {
|
||||||
if (!this.decoderConfig) {
|
this.decoderConfig ??= await this.audioTrack.getDecoderConfig();
|
||||||
this.decoderConfig = await this.audioTrack.getDecoderConfig();
|
|
||||||
}
|
|
||||||
const decoder = new AudioDecoder({
|
const decoder = new AudioDecoder({
|
||||||
output: onData,
|
output: onData,
|
||||||
error: (error) => console.error(error)
|
error: (error) => console.error(error)
|
||||||
@@ -6238,9 +6234,9 @@ var AudioBufferDrain = class {
|
|||||||
length: data.numberOfFrames,
|
length: data.numberOfFrames,
|
||||||
sampleRate: data.sampleRate
|
sampleRate: data.sampleRate
|
||||||
});
|
});
|
||||||
|
const dataBytes = new Float32Array(data.allocationSize({ planeIndex: 0, format: "f32-planar" }) / 4);
|
||||||
for (let i = 0; i < data.numberOfChannels; i++) {
|
for (let i = 0; i < data.numberOfChannels; i++) {
|
||||||
const dataBytes = new Float32Array(data.allocationSize({ planeIndex: i }));
|
data.copyTo(dataBytes, { planeIndex: i, format: "f32-planar" });
|
||||||
data.copyTo(dataBytes, { planeIndex: i });
|
|
||||||
audioBuffer.copyToChannel(dataBytes, i);
|
audioBuffer.copyToChannel(dataBytes, i);
|
||||||
}
|
}
|
||||||
const sampleDuration = 1 / data.sampleRate;
|
const sampleDuration = 1 / data.sampleRate;
|
||||||
|
|||||||
+6
-8
@@ -305,9 +305,7 @@ export class VideoFrameDrain extends BaseMediaFrameDrain<EncodedVideoChunk, Vide
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createDecoder(onFrame: (frame: VideoFrame) => unknown) {
|
async createDecoder(onFrame: (frame: VideoFrame) => unknown) {
|
||||||
if (!this.decoderConfig) {
|
this.decoderConfig ??= await this.videoTrack.getDecoderConfig();
|
||||||
this.decoderConfig = await this.videoTrack.getDecoderConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
const decoder = new VideoDecoder({
|
const decoder = new VideoDecoder({
|
||||||
output: onFrame,
|
output: onFrame,
|
||||||
@@ -369,9 +367,7 @@ export class AudioDataDrain extends BaseMediaFrameDrain<EncodedAudioChunk, Audio
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createDecoder(onData: (data: AudioData) => unknown) {
|
async createDecoder(onData: (data: AudioData) => unknown) {
|
||||||
if (!this.decoderConfig) {
|
this.decoderConfig ??= await this.audioTrack.getDecoderConfig();
|
||||||
this.decoderConfig = await this.audioTrack.getDecoderConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
const decoder = new AudioDecoder({
|
const decoder = new AudioDecoder({
|
||||||
output: onData,
|
output: onData,
|
||||||
@@ -422,9 +418,11 @@ export class AudioBufferDrain {
|
|||||||
sampleRate: data.sampleRate,
|
sampleRate: data.sampleRate,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// All user agents are required to support conversion to f32-planar
|
||||||
|
const dataBytes = new Float32Array(data.allocationSize({ planeIndex: 0, format: 'f32-planar' }) / 4);
|
||||||
|
|
||||||
for (let i = 0; i < data.numberOfChannels; i++) {
|
for (let i = 0; i < data.numberOfChannels; i++) {
|
||||||
const dataBytes = new Float32Array(data.allocationSize({ planeIndex: i }));
|
data.copyTo(dataBytes, { planeIndex: i, format: 'f32-planar' });
|
||||||
data.copyTo(dataBytes, { planeIndex: i });
|
|
||||||
audioBuffer.copyToChannel(dataBytes, i);
|
audioBuffer.copyToChannel(dataBytes, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user