Simplify/fix 3d matrix rotation extraction (#330)

This commit is contained in:
Vanilagy
2026-03-19 15:08:29 +01:00
parent 0d50526ff6
commit fd39084e88
+4 -10
View File
@@ -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) => {