Support rotation metadata in Matroska muxer

This commit is contained in:
Vanilagy
2025-01-11 20:07:31 +01:00
parent 11d41fcbc7
commit 2d4df211d8
4 changed files with 23 additions and 9 deletions
+1
View File
@@ -99,6 +99,7 @@ export enum EBMLId {
Primaries = 0x55bb,
Range = 0x55b9,
Projection = 0x7670,
ProjectionType = 0x7671,
ProjectionPoseRoll = 0x7675,
}
+19 -2
View File
@@ -230,6 +230,8 @@ export class MatroskaMuxer extends Muxer {
}
private videoSpecificTrackInfo(trackData: MatroskaVideoTrackData) {
const { frameRate, rotation } = trackData.track.metadata;
const elements: EBMLElement['data'] = [
(trackData.info.decoderConfig.description
? {
@@ -237,10 +239,10 @@ export class MatroskaMuxer extends Muxer {
data: toUint8Array(trackData.info.decoderConfig.description),
}
: null),
(trackData.track.metadata.frameRate
(frameRate
? {
id: EBMLId.DefaultDuration,
data: 1e9 / trackData.track.metadata.frameRate,
data: 1e9 / frameRate,
}
: null),
];
@@ -272,6 +274,21 @@ export class MatroskaMuxer extends Muxer {
],
}
: null),
(typeof rotation === 'number' && rotation !== 0
? {
id: EBMLId.Projection,
data: [
{
id: EBMLId.ProjectionType,
data: 0, // rectangular
},
{
id: EBMLId.ProjectionPoseRoll,
data: (rotation + 180) % 360 - 180, // [0, 270] -> [-180, 90]
},
],
}
: null),
] };
elements.push(videoElement);