mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 11:23:45 +02:00
Add InputTrack.number
This commit is contained in:
@@ -146,6 +146,10 @@ class AdtsAudioTrackBacking implements InputAudioTrackBacking {
|
||||
return 1;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
async getFirstTimestamp() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-2
@@ -66,7 +66,8 @@ export type ConversionOptions = {
|
||||
* Video-specific options. When passing an object, the same options are applied to all video tracks. When passing a
|
||||
* function, it will be invoked for each video track and is expected to return or resolve to the options
|
||||
* for that specific track. The function is passed an instance of {@link InputVideoTrack} as well as a number `n`,
|
||||
* which is the 1-based index of the track in the list of all video tracks.
|
||||
* which is the 1-based index of the track in the list of all video tracks. Using `n` is deprecated, prefer the
|
||||
* identical `track.number` instead.
|
||||
*/
|
||||
video?: ConversionVideoOptions
|
||||
| ((track: InputVideoTrack, n: number) => MaybePromise<ConversionVideoOptions | undefined>);
|
||||
@@ -75,7 +76,8 @@ export type ConversionOptions = {
|
||||
* Audio-specific options. When passing an object, the same options are applied to all audio tracks. When passing a
|
||||
* function, it will be invoked for each audio track and is expected to return or resolve to the options
|
||||
* for that specific track. The function is passed an instance of {@link InputAudioTrack} as well as a number `n`,
|
||||
* which is the 1-based index of the track in the list of all audio tracks.
|
||||
* which is the 1-based index of the track in the list of all audio tracks. Using `n` is deprecated, prefer the
|
||||
* identical `track.number` instead.
|
||||
*/
|
||||
audio?: ConversionAudioOptions
|
||||
| ((track: InputAudioTrack, n: number) => MaybePromise<ConversionAudioOptions | undefined>);
|
||||
|
||||
@@ -529,6 +529,10 @@ class FlacAudioTrackBacking implements InputAudioTrackBacking {
|
||||
return 1;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
getCodec() {
|
||||
return 'flac' as const;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ export type PacketStats = {
|
||||
|
||||
export interface InputTrackBacking {
|
||||
getId(): number;
|
||||
getNumber(): number;
|
||||
getCodec(): MediaCodec | null;
|
||||
getInternalCodecId(): string | number | Uint8Array | null;
|
||||
getName(): string | null;
|
||||
@@ -94,6 +95,15 @@ export abstract class InputTrack {
|
||||
return this._backing.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The 1-based index of this track among all tracks of the same type in the input file. For example, the first
|
||||
* video track has number 1, the second video track has number 2, and so on. The index refers to the order in
|
||||
* which the tracks are returned by {@link Input.getTracks()}.
|
||||
*/
|
||||
get number() {
|
||||
return this._backing.getNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* The identifier of the codec used internally by the container. It is not homogenized by Mediabunny
|
||||
* and depends entirely on the container format.
|
||||
|
||||
@@ -2335,6 +2335,25 @@ abstract class IsobmffTrackBacking implements InputTrackBacking {
|
||||
return this.internalTrack.id;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
const demuxer = this.internalTrack.demuxer;
|
||||
const inputTrack = this.internalTrack.inputTrack!;
|
||||
const trackType = inputTrack.type;
|
||||
|
||||
let number = 0;
|
||||
for (const track of demuxer.tracks) {
|
||||
if (track.inputTrack!.type === trackType) {
|
||||
number++;
|
||||
}
|
||||
|
||||
if (track === this.internalTrack) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
getCodec(): MediaCodec | null {
|
||||
throw new Error('Not implemented on base class.');
|
||||
}
|
||||
|
||||
@@ -1859,6 +1859,27 @@ abstract class MatroskaTrackBacking implements InputTrackBacking {
|
||||
return this.internalTrack.id;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
const demuxer = this.internalTrack.demuxer;
|
||||
const inputTrack = this.internalTrack.inputTrack!;
|
||||
const trackType = inputTrack.type;
|
||||
|
||||
let number = 0;
|
||||
for (const segment of demuxer.segments) {
|
||||
for (const track of segment.tracks) {
|
||||
if (track.inputTrack!.type === trackType) {
|
||||
number++;
|
||||
}
|
||||
|
||||
if (track === this.internalTrack) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
getCodec(): MediaCodec | null {
|
||||
throw new Error('Not implemented on base class.');
|
||||
}
|
||||
|
||||
@@ -217,6 +217,10 @@ class Mp3AudioTrackBacking implements InputAudioTrackBacking {
|
||||
return 1;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
async getFirstTimestamp() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -746,6 +746,25 @@ export abstract class MpegTsTrackBacking implements InputTrackBacking {
|
||||
return this.elementaryStream.pid;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
const demuxer = this.elementaryStream.demuxer;
|
||||
const trackType = this.elementaryStream.info.type;
|
||||
|
||||
let number = 0;
|
||||
for (const track of demuxer.tracks) {
|
||||
if (track.type === trackType) {
|
||||
number++;
|
||||
}
|
||||
|
||||
assert(track._backing instanceof MpegTsTrackBacking);
|
||||
if (track._backing.elementaryStream === this.elementaryStream) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
getCodec(): MediaCodec | null {
|
||||
throw new Error('Not implemented on base class.');
|
||||
}
|
||||
|
||||
@@ -428,6 +428,16 @@ class OggAudioTrackBacking implements InputAudioTrackBacking {
|
||||
return this.bitstream.serialNumber;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
// All Ogg tracks are audio, so the track's index + 1 is its number
|
||||
const index = this.demuxer.tracks.findIndex(
|
||||
t => (t._backing as OggAudioTrackBacking).bitstream === this.bitstream,
|
||||
);
|
||||
assert(index !== -1);
|
||||
|
||||
return index + 1;
|
||||
}
|
||||
|
||||
getNumberOfChannels() {
|
||||
return this.bitstream.numberOfChannels;
|
||||
}
|
||||
|
||||
@@ -356,6 +356,10 @@ class WaveAudioTrackBacking implements InputAudioTrackBacking {
|
||||
return 1;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
getCodec() {
|
||||
return this.demuxer.getCodec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user