From fd39084e8885ca26db9cbc6ba10756d0e6062c5b Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Thu, 19 Mar 2026 15:08:29 +0100 Subject: [PATCH] Simplify/fix 3d matrix rotation extraction (#330) --- src/isobmff/isobmff-demuxer.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/isobmff/isobmff-demuxer.ts b/src/isobmff/isobmff-demuxer.ts index d52e160..02be3fb 100644 --- a/src/isobmff/isobmff-demuxer.ts +++ b/src/isobmff/isobmff-demuxer.ts @@ -3177,22 +3177,16 @@ const offsetFragmentTrackDataByTimestamp = (trackData: FragmentTrackData, timest /** Extracts the rotation component from a transformation matrix, in degrees. */ const extractRotationFromMatrix = (matrix: TransformationMatrix) => { - const [m11, , , m21] = matrix; + const [a, b] = matrix; // (1, 0) projects onto (a, b), so that's all we need - const scaleX = Math.hypot(m11, m21); + const radians = Math.atan2(b, a); - const cosTheta = m11 / scaleX; - const sinTheta = m21 / scaleX; - - // Invert the rotation because matrices are post-multiplied in ISOBMFF - const result = -Math.atan2(sinTheta, cosTheta) * (180 / Math.PI); - - if (!Number.isFinite(result)) { + if (!Number.isFinite(radians)) { // Can happen if the entire matrix is 0, for example return 0; } - return result; + return radians * (180 / Math.PI); }; const sampleTableIsEmpty = (sampleTable: SampleTable) => {