Multiple miscellaneous fixes

This commit is contained in:
Vanilagy
2025-02-18 22:13:21 +01:00
parent 3848a59ec3
commit 7988b6c2f8
9 changed files with 50 additions and 39 deletions
+11 -12
View File
@@ -27,7 +27,6 @@ import {
COLOR_PRIMARIES_MAP_INVERSE,
MATRIX_COEFFICIENTS_MAP_INVERSE,
TRANSFER_CHARACTERISTICS_MAP_INVERSE,
rotationMatrix,
binarySearchLessOrEqual,
binarySearchExact,
Rotation,
@@ -38,6 +37,8 @@ import {
TransformationMatrix,
extractRotationFromMatrix,
roundToPrecision,
isIso639Dash2LanguageCode,
roundToMultiple,
} from '../misc';
import { Reader } from '../reader';
import { EncodedAudioSample, EncodedVideoSample, PLACEHOLDER_DATA, SampleType } from '../sample';
@@ -175,8 +176,6 @@ type Fragment = {
isKnownToBeFirstFragment: boolean;
};
const knownMatrixes = [rotationMatrix(0), rotationMatrix(90), rotationMatrix(180), rotationMatrix(270)];
export class IsobmffDemuxer extends Demuxer {
metadataReader: IsobmffReader;
currentTrack: InternalTrack | null = null;
@@ -657,16 +656,11 @@ export class IsobmffDemuxer extends Demuxer {
this.metadataReader.readFixed_2_30(),
];
const rotation = extractRotationFromMatrix(matrix);
const comparisonMatrix = rotationMatrix(rotation);
const rotation = (roundToMultiple(extractRotationFromMatrix(matrix), 90) + 360) % 360 as Rotation;
assert(rotation === 0 || rotation === 90 || rotation === 180 || rotation === 270);
const matrixIndex = knownMatrixes.findIndex(mat => mat.every((y, i) => y === comparisonMatrix[i]));
if (matrixIndex === -1) {
console.warn(`Wacky rotation matrix ${comparisonMatrix.join(',')}; sticking with no rotation.`);
track.rotation = 0;
} else {
track.rotation = (90 * matrixIndex) as Rotation;
}
// Flip clockwise to counter-clockwise
track.rotation = (-rotation + 360) % 360 as Rotation;
}; break;
case 'elst': {
@@ -739,6 +733,11 @@ export class IsobmffDemuxer extends Demuxer {
track.languageCode = String.fromCharCode(0x60 + (language & 0b11111)) + track.languageCode;
language >>= 5;
}
if (!isIso639Dash2LanguageCode(track.languageCode)) {
// Sometimes the bytes are garbage
track.languageCode = UNDETERMINED_LANGUAGE;
}
}
}; break;
+5 -3
View File
@@ -13,7 +13,7 @@ import {
validateSubtitleMetadata,
validateVideoChunkMetadata,
} from '../codec';
import { EncodedAudioSample, EncodedVideoSample } from '../sample';
import { EncodedAudioSample, EncodedVideoSample, SampleType } from '../sample';
import { BufferTarget } from '../target';
export const GLOBAL_TIMESCALE = 1000;
@@ -25,7 +25,7 @@ export type Sample = {
duration: number;
data: Uint8Array | null;
size: number;
type: 'key' | 'delta';
type: SampleType;
timescaleUnitsToNextSample: number;
};
@@ -492,7 +492,7 @@ export class IsobmffMuxer extends Muxer {
data: Uint8Array,
timestamp: number,
duration: number,
type: 'key' | 'delta',
type: SampleType,
) {
const sample: Sample = {
timestamp,
@@ -564,6 +564,8 @@ export class IsobmffMuxer extends Muxer {
const timescaleUnits = intoTimescale(sample.decodeTimestamp, trackData.timescale, false);
const delta = Math.round(timescaleUnits - trackData.lastTimescaleUnits);
assert(delta >= 0);
trackData.lastTimescaleUnits += delta;
trackData.lastSample.timescaleUnitsToNextSample = delta;