diff --git a/src/isobmff/isobmff-demuxer.ts b/src/isobmff/isobmff-demuxer.ts index ed03f46..2677b03 100644 --- a/src/isobmff/isobmff-demuxer.ts +++ b/src/isobmff/isobmff-demuxer.ts @@ -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; diff --git a/src/misc.ts b/src/misc.ts index 0cbf745..a71cdd8 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -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 [