Fix rotation matrix detection

This commit is contained in:
Vanilagy
2025-01-02 17:03:05 +01:00
parent 5dda43959d
commit d476c42424
2 changed files with 9 additions and 7 deletions
+6 -4
View File
@@ -592,12 +592,14 @@ export class IsobmffDemuxer extends Demuxer {
}
this.isobmffReader.pos += 2 * 4 + 2 + 2 + 2 + 2;
const rotationMatrix: number[] = [];
rotationMatrix.push(this.isobmffReader.readFixed_16_16(), this.isobmffReader.readFixed_16_16());
const values: number[] = [];
values.push(this.isobmffReader.readFixed_16_16(), this.isobmffReader.readFixed_16_16());
this.isobmffReader.pos += 4;
rotationMatrix.push(this.isobmffReader.readFixed_16_16(), this.isobmffReader.readFixed_16_16());
values.push(this.isobmffReader.readFixed_16_16(), this.isobmffReader.readFixed_16_16());
const matrixIndex = knownMatrixes.findIndex(x => x.every((y, i) => y === rotationMatrix[i]));
const matrixIndex = knownMatrixes.findIndex((x) => {
return x[0] === values[0] && x[1] === values[1] && x[3] === values[2] && x[4] === values[3];
});
if (matrixIndex === -1) {
// console.warn(`Wacky rotation matrix ${rotationMatrix}; sticking with no rotation.`);
track.rotation = 0;
+3 -3
View File
@@ -127,10 +127,10 @@ export class AsyncMutex {
}
}
export const rotationMatrix = (rotationInDegrees: number): TransformationMatrix => {
export const rotationMatrix = (rotationInDegrees: Rotation): TransformationMatrix => {
const theta = rotationInDegrees * (Math.PI / 180);
const cosTheta = Math.cos(theta);
const sinTheta = Math.sin(theta);
const cosTheta = Math.round(Math.cos(theta));
const sinTheta = Math.round(Math.sin(theta));
// Matrices are post-multiplied in ISOBMFF, meaning this is the transpose of your typical rotation matrix
return [