mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Make MPEG-TS muxing tests not rely on AAC encoder
This commit is contained in:
@@ -5,7 +5,7 @@ import { ALL_FORMATS, MPEG_TS } from '../../src/input-format.js';
|
|||||||
import { Output } from '../../src/output.js';
|
import { Output } from '../../src/output.js';
|
||||||
import { MpegTsOutputFormat } from '../../src/output-format.js';
|
import { MpegTsOutputFormat } from '../../src/output-format.js';
|
||||||
import { BufferTarget, StreamTarget, StreamTargetChunk } from '../../src/target.js';
|
import { BufferTarget, StreamTarget, StreamTargetChunk } from '../../src/target.js';
|
||||||
import { AudioBufferSource, CanvasSource, EncodedAudioPacketSource } from '../../src/media-source.js';
|
import { CanvasSource, EncodedAudioPacketSource } from '../../src/media-source.js';
|
||||||
import { QUALITY_HIGH } from '../../src/encode.js';
|
import { QUALITY_HIGH } from '../../src/encode.js';
|
||||||
import { EncodedPacketSink } from '../../src/media-sink.js';
|
import { EncodedPacketSink } from '../../src/media-sink.js';
|
||||||
import { assert } from '../../src/misc.js';
|
import { assert } from '../../src/misc.js';
|
||||||
@@ -63,10 +63,7 @@ test('MPEG-TS muxing with AVC and AAC', async () => {
|
|||||||
});
|
});
|
||||||
output.addVideoTrack(videoSource);
|
output.addVideoTrack(videoSource);
|
||||||
|
|
||||||
const audioSource = new AudioBufferSource({
|
const audioSource = new EncodedAudioPacketSource('aac');
|
||||||
codec: 'aac',
|
|
||||||
bitrate: QUALITY_HIGH,
|
|
||||||
});
|
|
||||||
output.addAudioTrack(audioSource);
|
output.addAudioTrack(audioSource);
|
||||||
|
|
||||||
await output.start();
|
await output.start();
|
||||||
@@ -81,12 +78,27 @@ test('MPEG-TS muxing with AVC and AAC', async () => {
|
|||||||
await videoSource.add(i * frameDuration, frameDuration);
|
await videoSource.add(i * frameDuration, frameDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
const audioBuffer = new AudioBuffer({
|
using aacInput = new Input({
|
||||||
length: 48000 * duration,
|
source: new UrlSource('/video.mp4'),
|
||||||
numberOfChannels: 2,
|
formats: ALL_FORMATS,
|
||||||
sampleRate: 48000,
|
|
||||||
});
|
});
|
||||||
await audioSource.add(audioBuffer);
|
|
||||||
|
const aacTrack = await aacInput.getPrimaryAudioTrack();
|
||||||
|
assert(aacTrack);
|
||||||
|
|
||||||
|
const aacSink = new EncodedPacketSink(aacTrack);
|
||||||
|
|
||||||
|
let isFirst = true;
|
||||||
|
for await (const packet of aacSink.packets()) {
|
||||||
|
if (packet.timestamp >= duration) break;
|
||||||
|
|
||||||
|
await audioSource.add(packet, {
|
||||||
|
decoderConfig: isFirst
|
||||||
|
? (await aacTrack.getDecoderConfig())!
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
|
|
||||||
await output.finalize();
|
await output.finalize();
|
||||||
finalized = true;
|
finalized = true;
|
||||||
@@ -188,7 +200,7 @@ test('MPEG-TS muxing with AVC and AAC', async () => {
|
|||||||
const audioDuration = await audioTrack.computeDuration();
|
const audioDuration = await audioTrack.computeDuration();
|
||||||
|
|
||||||
expect(videoDuration).toBeCloseTo(5, 1);
|
expect(videoDuration).toBeCloseTo(5, 1);
|
||||||
expect(audioDuration).toBeCloseTo(5.077333333333334, 1);
|
expect(audioDuration).toBeCloseTo(5, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('MPEG-TS muxing with HEVC and MP3', async () => {
|
test('MPEG-TS muxing with HEVC and MP3', async () => {
|
||||||
@@ -410,21 +422,34 @@ test('MPEG-TS muxing with audio only', async () => {
|
|||||||
target: new BufferTarget(),
|
target: new BufferTarget(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const audioSource = new AudioBufferSource({
|
const audioSource = new EncodedAudioPacketSource('aac');
|
||||||
codec: 'aac',
|
|
||||||
bitrate: QUALITY_HIGH,
|
|
||||||
});
|
|
||||||
output.addAudioTrack(audioSource);
|
output.addAudioTrack(audioSource);
|
||||||
|
|
||||||
await output.start();
|
await output.start();
|
||||||
|
|
||||||
const duration = 1;
|
const duration = 1;
|
||||||
const audioBuffer = new AudioBuffer({
|
|
||||||
length: 48000 * duration,
|
using aacInput = new Input({
|
||||||
numberOfChannels: 2,
|
source: new UrlSource('/video.mp4'),
|
||||||
sampleRate: 48000,
|
formats: ALL_FORMATS,
|
||||||
});
|
});
|
||||||
await audioSource.add(audioBuffer);
|
|
||||||
|
const aacTrack = await aacInput.getPrimaryAudioTrack();
|
||||||
|
assert(aacTrack);
|
||||||
|
|
||||||
|
const aacSink = new EncodedPacketSink(aacTrack);
|
||||||
|
|
||||||
|
let isFirst = true;
|
||||||
|
for await (const packet of aacSink.packets()) {
|
||||||
|
if (packet.timestamp >= duration) break;
|
||||||
|
|
||||||
|
await audioSource.add(packet, {
|
||||||
|
decoderConfig: isFirst
|
||||||
|
? (await aacTrack.getDecoderConfig())!
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
|
|
||||||
await output.finalize();
|
await output.finalize();
|
||||||
|
|
||||||
@@ -510,8 +535,8 @@ test('MPEG-TS muxing with two audio tracks', async () => {
|
|||||||
target: new BufferTarget(),
|
target: new BufferTarget(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const audioSource1 = new AudioBufferSource({ codec: 'aac', bitrate: QUALITY_HIGH });
|
const audioSource1 = new EncodedAudioPacketSource('aac');
|
||||||
const audioSource2 = new AudioBufferSource({ codec: 'aac', bitrate: QUALITY_HIGH });
|
const audioSource2 = new EncodedAudioPacketSource('aac');
|
||||||
|
|
||||||
output.addAudioTrack(audioSource1);
|
output.addAudioTrack(audioSource1);
|
||||||
output.addAudioTrack(audioSource2);
|
output.addAudioTrack(audioSource2);
|
||||||
@@ -519,19 +544,39 @@ test('MPEG-TS muxing with two audio tracks', async () => {
|
|||||||
await output.start();
|
await output.start();
|
||||||
|
|
||||||
const duration = 1;
|
const duration = 1;
|
||||||
const audioBuffer1 = new AudioBuffer({
|
|
||||||
length: 48000 * duration,
|
using aacInput = new Input({
|
||||||
numberOfChannels: 2,
|
source: new UrlSource('/video.mp4'),
|
||||||
sampleRate: 48000,
|
formats: ALL_FORMATS,
|
||||||
});
|
|
||||||
const audioBuffer2 = new AudioBuffer({
|
|
||||||
length: 44100 * duration,
|
|
||||||
numberOfChannels: 1,
|
|
||||||
sampleRate: 44100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await audioSource1.add(audioBuffer1);
|
const aacTrack = await aacInput.getPrimaryAudioTrack();
|
||||||
await audioSource2.add(audioBuffer2);
|
assert(aacTrack);
|
||||||
|
|
||||||
|
const aacSink = new EncodedPacketSink(aacTrack);
|
||||||
|
|
||||||
|
const decoderConfig = await aacTrack.getDecoderConfig();
|
||||||
|
assert(decoderConfig);
|
||||||
|
|
||||||
|
let isFirst1 = true;
|
||||||
|
for await (const packet of aacSink.packets()) {
|
||||||
|
if (packet.timestamp >= duration) break;
|
||||||
|
|
||||||
|
await audioSource1.add(packet, {
|
||||||
|
decoderConfig: isFirst1 ? decoderConfig : undefined,
|
||||||
|
});
|
||||||
|
isFirst1 = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let isFirst2 = true;
|
||||||
|
for await (const packet of aacSink.packets()) {
|
||||||
|
if (packet.timestamp >= duration) break;
|
||||||
|
|
||||||
|
await audioSource2.add(packet, {
|
||||||
|
decoderConfig: isFirst2 ? decoderConfig : undefined,
|
||||||
|
});
|
||||||
|
isFirst2 = false;
|
||||||
|
}
|
||||||
|
|
||||||
await output.finalize();
|
await output.finalize();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user