Comparing version 2.2.2 to 2.3.0
@@ -19,9 +19,13 @@ /** | ||
/** | ||
* The width of the video, in pixels. | ||
* The width of the video in pixels. | ||
*/ | ||
width: number, | ||
/** | ||
* The height of the video, in pixels. | ||
* The height of the video in pixels. | ||
*/ | ||
height: number | ||
height: number, | ||
/** | ||
* The clockwise rotation of the video in degrees. | ||
*/ | ||
rotation?: 0 | 90 | 180 | 270 | ||
}, | ||
@@ -42,3 +46,3 @@ | ||
/** | ||
* The sample rate in the audio rate, in samples per second per channel. | ||
* The sample rate of the audio track in samples per second per channel. | ||
*/ | ||
@@ -45,0 +49,0 @@ sampleRate: number |
@@ -94,12 +94,14 @@ "use strict"; | ||
}; | ||
var fixed16 = (value) => { | ||
view.setUint8(0, value); | ||
view.setUint8(1, value << 8); | ||
var fixed_8_8 = (value) => { | ||
view.setInt16(0, __pow(2, 8) * value, false); | ||
return [bytes[0], bytes[1]]; | ||
}; | ||
var fixed32 = (value) => { | ||
view.setUint16(0, value, false); | ||
view.setUint16(2, value << 16, false); | ||
var fixed_16_16 = (value) => { | ||
view.setInt32(0, __pow(2, 16) * value, false); | ||
return [bytes[0], bytes[1], bytes[2], bytes[3]]; | ||
}; | ||
var fixed_2_30 = (value) => { | ||
view.setInt32(0, __pow(2, 30) * value, false); | ||
return [bytes[0], bytes[1], bytes[2], bytes[3]]; | ||
}; | ||
var ascii = (text, nullTerminated = false) => { | ||
@@ -118,15 +120,34 @@ let bytes2 = Array(text.length).fill(null).map((_, i) => text.charCodeAt(i)); | ||
}; | ||
var rotationMatrix = (rotationInDegrees) => { | ||
let theta = rotationInDegrees * (Math.PI / 180); | ||
let cosTheta = Math.cos(theta); | ||
let sinTheta = Math.sin(theta); | ||
return [ | ||
cosTheta, | ||
sinTheta, | ||
0, | ||
-sinTheta, | ||
cosTheta, | ||
0, | ||
0, | ||
0, | ||
1 | ||
]; | ||
}; | ||
var IDENTITY_MATRIX = rotationMatrix(0); | ||
var matrixToBytes = (matrix) => { | ||
return [ | ||
fixed_16_16(matrix[0]), | ||
fixed_16_16(matrix[1]), | ||
fixed_2_30(matrix[2]), | ||
fixed_16_16(matrix[3]), | ||
fixed_16_16(matrix[4]), | ||
fixed_2_30(matrix[5]), | ||
fixed_16_16(matrix[6]), | ||
fixed_16_16(matrix[7]), | ||
fixed_2_30(matrix[8]) | ||
]; | ||
}; | ||
// src/box.ts | ||
var IDENTITY_MATRIX = [ | ||
65536, | ||
0, | ||
0, | ||
0, | ||
65536, | ||
0, | ||
0, | ||
0, | ||
1073741824 | ||
].map(u32); | ||
var box = (type, contents, children) => ({ | ||
@@ -187,9 +208,9 @@ type, | ||
// Duration | ||
fixed32(1), | ||
fixed_16_16(1), | ||
// Preferred rate | ||
fixed16(1), | ||
fixed_8_8(1), | ||
// Preferred volume | ||
Array(10).fill(0), | ||
// Reserved | ||
IDENTITY_MATRIX, | ||
matrixToBytes(IDENTITY_MATRIX), | ||
// Matrix | ||
@@ -229,11 +250,11 @@ Array(24).fill(0), | ||
// Alternate group | ||
fixed16(track.info.type === "audio" ? 1 : 0), | ||
fixed_8_8(track.info.type === "audio" ? 1 : 0), | ||
// Volume | ||
u16(0), | ||
// Reserved | ||
IDENTITY_MATRIX, | ||
matrixToBytes(rotationMatrix(track.info.type === "video" ? track.info.rotation : 0)), | ||
// Matrix | ||
fixed32(track.info.type === "video" ? track.info.width : 0), | ||
fixed_16_16(track.info.type === "video" ? track.info.width : 0), | ||
// Track width | ||
fixed32(track.info.type === "video" ? track.info.height : 0) | ||
fixed_16_16(track.info.type === "video" ? track.info.height : 0) | ||
// Track height | ||
@@ -388,3 +409,3 @@ ]); | ||
// Packet size | ||
fixed32(track.info.sampleRate) | ||
fixed_16_16(track.info.sampleRate) | ||
// Sample rate | ||
@@ -439,3 +460,3 @@ ], [ | ||
// InputSampleRate | ||
fixed16(0), | ||
fixed_8_8(0), | ||
// OutputGain | ||
@@ -936,4 +957,9 @@ u8(0) | ||
validateOptions_fn = function(options) { | ||
if (options.video && !SUPPORTED_VIDEO_CODECS2.includes(options.video.codec)) { | ||
throw new Error(`Unsupported video codec: ${options.video.codec}`); | ||
if (options.video) { | ||
if (!SUPPORTED_VIDEO_CODECS2.includes(options.video.codec)) { | ||
throw new Error(`Unsupported video codec: ${options.video.codec}`); | ||
} | ||
if (options.video.rotation !== void 0 && ![0, 90, 180, 270].includes(options.video.rotation)) { | ||
throw new Error(`Invalid video rotation: ${options.video.rotation}. Has to be 0, 90, 180 or 270.`); | ||
} | ||
} | ||
@@ -958,2 +984,3 @@ if (options.audio && !SUPPORTED_AUDIO_CODECS2.includes(options.audio.codec)) { | ||
prepareTracks_fn = function() { | ||
var _a; | ||
if (__privateGet(this, _options).video) { | ||
@@ -966,3 +993,4 @@ __privateSet(this, _videoTrack, { | ||
width: __privateGet(this, _options).video.width, | ||
height: __privateGet(this, _options).video.height | ||
height: __privateGet(this, _options).video.height, | ||
rotation: (_a = __privateGet(this, _options).video.rotation) != null ? _a : 0 | ||
}, | ||
@@ -969,0 +997,0 @@ timescale: 720, |
{ | ||
"name": "mp4-muxer", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.", | ||
@@ -5,0 +5,0 @@ "main": "./build/mp4-muxer.js", |
@@ -89,3 +89,4 @@ # mp4-muxer - JavaScript MP4 multiplexer | ||
width: number, | ||
height: number | ||
height: number, | ||
rotation?: 0 | 90 | 180 | 270 // Adds rotation metadata to the file | ||
}, | ||
@@ -92,0 +93,0 @@ |
Sorry, the diff of this file is not supported yet
97982
2435
277