mpegts-stream
v0.0.1-alpha3
Published
Multiplex AAC audio samples and H264/AVC video samples into an MPEG2TS stream ready for transport.
Downloads
36
Maintainers
Readme
mpegts-stream
Multiplex raw AAC audio samples and/or raw H264/AVC video samples into an MPEG2TS transport stream.
Example
//@ts-check
import { createReadStream, createWriteStream } from "fs";
import { MpegTsMuxer } from "./src/muxer.js";
import { Transform } from "stream";
import { TfAudioPacket, TfVideoPacket } from "./src/transforms.js";
const AUDIO_TYPE = 0x0F;
const VIDEO_TYPE = 0x1B;
const AUDIO_PID = 257;
const VIDEO_PID = 256;
const PMT_PID = 100;
const streamPidMap = {
[AUDIO_TYPE]: AUDIO_PID,
[VIDEO_TYPE]: VIDEO_PID
};
// transform used for preparing packets of AAC audio samples with ADTS headers into the object type that MpegTsMuxer expects.
const apTf = new TfAudioPacket();
const muxer = new MpegTsMuxer(streamPidMap, PMT_PID, VIDEO_PID, 0);
const ws = createWriteStream('./out/test.ts');
const aacRs = createReadStream('./in/vid.aac');
// construct our pipeline...
aacRs
// transform chunks of binary audio data into expected packets for the muxer.
.pipe(apTf, { end: false })
// multiplex the data into TS
.pipe(muxer)
// write the resulting data to the file.
.pipe(ws);