Add media conversion utility function, fix fragment/cluster reading issues, expand color space logic, add qualitative bitrates, & many other fixes and improvements

This commit is contained in:
Vanilagy
2025-01-19 18:55:12 +01:00
parent d323c2be8e
commit 70b88332b2
19 changed files with 1504 additions and 217 deletions
+58 -4
View File
@@ -43,6 +43,10 @@ export class EncodedVideoSample {
}
is(otherSample: EncodedVideoSample) {
if (!(otherSample instanceof EncodedVideoSample)) {
throw new TypeError('otherSample must be an EncodedVideoSample.');
}
return (
this.type === otherSample.type
&& this.timestamp === otherSample.timestamp
@@ -51,9 +55,32 @@ export class EncodedVideoSample {
);
}
clone(options?: {
timestamp?: number;
duration?: number;
}) {
if (options !== undefined && (!options || typeof options !== 'object')) {
throw new TypeError('options, when provided, must be an object.');
}
if (options?.timestamp !== undefined && !Number.isFinite(options.timestamp)) {
throw new TypeError('options.timestamp, when provided, must be a number.');
}
if (options?.duration !== undefined && !Number.isFinite(options.duration)) {
throw new TypeError('options.duration, when provided, must be a number.');
}
return new EncodedVideoSample(
this.data,
this.type,
options?.timestamp ?? this.timestamp,
options?.duration ?? this.duration,
this.byteLength,
);
}
static fromEncodedVideoChunk(chunk: EncodedVideoChunk) {
if (typeof EncodedVideoChunk === 'undefined') {
throw new Error('Your browser does not support EncodedVideoChunk.');
if (!(chunk instanceof EncodedVideoChunk)) {
throw new TypeError('chunk must be an EncodedVideoChunk.');
}
const data = new Uint8Array(chunk.byteLength);
@@ -108,6 +135,10 @@ export class EncodedAudioSample {
}
is(otherSample: EncodedAudioSample) {
if (!(otherSample instanceof EncodedAudioSample)) {
throw new TypeError('otherSample must be an EncodedAudioSample.');
}
return (
this.type === otherSample.type
&& this.timestamp === otherSample.timestamp
@@ -116,9 +147,32 @@ export class EncodedAudioSample {
);
}
clone(options?: {
timestamp?: number;
duration?: number;
}) {
if (options !== undefined && (!options || typeof options !== 'object')) {
throw new TypeError('options, when provided, must be an object.');
}
if (options?.timestamp !== undefined && !Number.isFinite(options.timestamp)) {
throw new TypeError('options.timestamp, when provided, must be a number.');
}
if (options?.duration !== undefined && !Number.isFinite(options.duration)) {
throw new TypeError('options.duration, when provided, must be a number.');
}
return new EncodedAudioSample(
this.data,
this.type,
options?.timestamp ?? this.timestamp,
options?.duration ?? this.duration,
this.byteLength,
);
}
static fromEncodedAudioChunk(chunk: EncodedAudioChunk) {
if (typeof EncodedAudioChunk === 'undefined') {
throw new Error('Your browser does not support EncodedAudioChunk.');
if (!(chunk instanceof EncodedAudioChunk)) {
throw new TypeError('chunk must be an EncodedAudioChunk.');
}
const data = new Uint8Array(chunk.byteLength);