This commit is contained in:
Vanilagy
2026-01-05 11:41:32 +01:00
parent 8f43086e3d
commit f363fe50e2
3 changed files with 77 additions and 8 deletions
+24 -1
View File
@@ -30,6 +30,7 @@ import { MAX_FRAME_HEADER_SIZE, MIN_FRAME_HEADER_SIZE, readFrameHeader } from '.
import { AdtsDemuxer } from './adts/adts-demuxer';
import { readAscii } from './reader';
import { FlacDemuxer } from './flac/flac-demuxer';
import { MpegTsDemuxer } from './mpeg-ts/mpeg-ts-demuxer';
/**
* Base class representing an input media file format.
@@ -476,6 +477,26 @@ export class AdtsInputFormat extends InputFormat {
}
}
export class MpegTsInputFormat extends InputFormat {
/** @internal */
async _canReadInput(input: Input) {
return true; // TEMP
}
/** @internal */
_createDemuxer(input: Input) {
return new MpegTsDemuxer(input);
}
get name() {
return 'MPEG Transport Stream';
}
get mimeType() {
return 'video/MP2T'; // todo correct?
}
}
/**
* MP4 input format singleton.
* @group Input formats
@@ -532,10 +553,12 @@ export const ADTS = /* #__PURE__ */ new AdtsInputFormat();
*/
export const FLAC = /* #__PURE__ */ new FlacInputFormat();
export const MPEG_TS = /* #__PURE__ */ new MpegTsInputFormat();
/**
* List of all input format singletons. If you don't need to support all input formats, you should specify the
* formats individually for better tree shaking.
* @group Input formats
* @public
*/
export const ALL_FORMATS: InputFormat[] = [MP4, QTFF, MATROSKA, WEBM, WAVE, OGG, FLAC, MP3, ADTS];
export const ALL_FORMATS: InputFormat[] = [MP4, QTFF, MATROSKA, WEBM, WAVE, OGG, FLAC, MP3, ADTS, MPEG_TS];
+51
View File
@@ -0,0 +1,51 @@
import { Demuxer } from "../demuxer";
import { Input } from "../input";
import { InputTrack } from "../input-track";
import { Bitstream } from "../misc";
import { readBytes, Reader, readU24Be, readU8 } from "../reader";
export class MpegTsDemuxer extends Demuxer {
reader: Reader;
metadataPromise: Promise<void> | null = null;
constructor(input: Input) {
super(input);
this.reader = input._reader;
}
async readMetadata() {
return this.metadataPromise ??= (async () => {
for (let i = 0; i < 2; i++) {
this.readPacket(188 * i);
}
})();
}
async getTracks(): Promise<InputTrack[]> {
await this.readMetadata();
return [];
}
async readPacket(pos: number) {
let slice = this.reader.requestSlice(pos, 188);
if (slice instanceof Promise) slice = await slice;
if (!slice) {
return null;
}
const bitstream = new Bitstream(readBytes(slice, 3));
const syncByte = bitstream.readBits(8);
const transportErrorIndicator = bitstream.readBits(1);
const payloadUnitStartIndicator = bitstream.readBits(1);
const transportPriority = bitstream.readBits(1);
const pid = bitstream.readBits(13);
const transportScramblingControl = bitstream.readBits(2);
const adaptationFieldControl = bitstream.readBits(2);
const continuityCounter = bitstream.readBits(4);
console.log(syncByte, transportErrorIndicator, payloadUnitStartIndicator, transportPriority, pid, transportScramblingControl, adaptationFieldControl, continuityCounter);
}
}