@remotion/media 4.0.373 → 4.0.374
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.mjs +0 -5
- package/dist/media-player.js +0 -6
- package/dist/video-extraction/rotate-frame.d.ts +4 -0
- package/dist/video-extraction/rotate-frame.js +34 -0
- package/dist/video-extraction/to-video-frame-fixed-rotation.d.ts +14 -0
- package/dist/video-extraction/to-video-frame-fixed-rotation.js +41 -0
- package/package.json +3 -3
package/dist/esm/index.mjs
CHANGED
|
@@ -994,11 +994,6 @@ class MediaPlayer {
|
|
|
994
994
|
if (currentPlaybackTime === newTime) {
|
|
995
995
|
return;
|
|
996
996
|
}
|
|
997
|
-
const newAudioSyncAnchor = this.sharedAudioContext.currentTime - newTime / (this.playbackRate * this.globalPlaybackRate);
|
|
998
|
-
const diff = Math.abs(newAudioSyncAnchor - this.audioSyncAnchor);
|
|
999
|
-
if (diff > 0.04) {
|
|
1000
|
-
this.setPlaybackTime(newTime, this.playbackRate * this.globalPlaybackRate);
|
|
1001
|
-
}
|
|
1002
997
|
await this.videoIteratorManager?.seek({
|
|
1003
998
|
newTime,
|
|
1004
999
|
nonce
|
package/dist/media-player.js
CHANGED
|
@@ -228,12 +228,6 @@ export class MediaPlayer {
|
|
|
228
228
|
if (currentPlaybackTime === newTime) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
|
-
const newAudioSyncAnchor = this.sharedAudioContext.currentTime -
|
|
232
|
-
newTime / (this.playbackRate * this.globalPlaybackRate);
|
|
233
|
-
const diff = Math.abs(newAudioSyncAnchor - this.audioSyncAnchor);
|
|
234
|
-
if (diff > 0.04) {
|
|
235
|
-
this.setPlaybackTime(newTime, this.playbackRate * this.globalPlaybackRate);
|
|
236
|
-
}
|
|
237
231
|
await this.videoIteratorManager?.seek({
|
|
238
232
|
newTime,
|
|
239
233
|
nonce,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const rotateFrame = async ({ frame, rotation, }) => {
|
|
2
|
+
if (rotation === 0) {
|
|
3
|
+
const directBitmap = await createImageBitmap(frame);
|
|
4
|
+
frame.close();
|
|
5
|
+
return directBitmap;
|
|
6
|
+
}
|
|
7
|
+
const width = rotation === 90 || rotation === 270
|
|
8
|
+
? frame.displayHeight
|
|
9
|
+
: frame.displayWidth;
|
|
10
|
+
const height = rotation === 90 || rotation === 270
|
|
11
|
+
? frame.displayWidth
|
|
12
|
+
: frame.displayHeight;
|
|
13
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
14
|
+
const ctx = canvas.getContext('2d');
|
|
15
|
+
if (!ctx) {
|
|
16
|
+
throw new Error('Could not get 2d context');
|
|
17
|
+
}
|
|
18
|
+
canvas.width = width;
|
|
19
|
+
canvas.height = height;
|
|
20
|
+
if (rotation === 90) {
|
|
21
|
+
ctx.translate(width, 0);
|
|
22
|
+
}
|
|
23
|
+
else if (rotation === 180) {
|
|
24
|
+
ctx.translate(width, height);
|
|
25
|
+
}
|
|
26
|
+
else if (rotation === 270) {
|
|
27
|
+
ctx.translate(0, height);
|
|
28
|
+
}
|
|
29
|
+
ctx.rotate(rotation * (Math.PI / 180));
|
|
30
|
+
ctx.drawImage(frame, 0, 0);
|
|
31
|
+
const bitmap = await createImageBitmap(canvas);
|
|
32
|
+
frame.close();
|
|
33
|
+
return bitmap;
|
|
34
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { VideoSample } from 'mediabunny';
|
|
2
|
+
/**
|
|
3
|
+
* Once we convert a VideoSample to a VideoFrame, we lose the rotation
|
|
4
|
+
* https://github.com/Vanilagy/mediabunny/pull/212
|
|
5
|
+
* This will be fixed in Mediabunny v2, but for now, we need to manually fix it.
|
|
6
|
+
*
|
|
7
|
+
* I'm actually wondering if your PR is actually a breaking change
|
|
8
|
+
I would say it kinda is actually
|
|
9
|
+
Because, previously only the VideoSample had rotation but the video frame you got from .toVideoFrame() was unrotated. Now, the resulting VideoFrame will be rotated, so drawing it to a canvas will behave differently. To me, this is a breaking change
|
|
10
|
+
People's old code that manually handled the rotation will break here
|
|
11
|
+
So I think this is actually a PR for v2
|
|
12
|
+
And for Remotion, you can do a temporary workaround fix by cloning the VideoFrame and overriding rotation that way, then closing the old frame, then transferring the cloned frame
|
|
13
|
+
*/
|
|
14
|
+
export declare const toVideoFrameFixedRotation: (videoSample: VideoSample) => VideoFrame;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Once we convert a VideoSample to a VideoFrame, we lose the rotation
|
|
3
|
+
* https://github.com/Vanilagy/mediabunny/pull/212
|
|
4
|
+
* This will be fixed in Mediabunny v2, but for now, we need to manually fix it.
|
|
5
|
+
*
|
|
6
|
+
* I'm actually wondering if your PR is actually a breaking change
|
|
7
|
+
I would say it kinda is actually
|
|
8
|
+
Because, previously only the VideoSample had rotation but the video frame you got from .toVideoFrame() was unrotated. Now, the resulting VideoFrame will be rotated, so drawing it to a canvas will behave differently. To me, this is a breaking change
|
|
9
|
+
People's old code that manually handled the rotation will break here
|
|
10
|
+
So I think this is actually a PR for v2
|
|
11
|
+
And for Remotion, you can do a temporary workaround fix by cloning the VideoFrame and overriding rotation that way, then closing the old frame, then transferring the cloned frame
|
|
12
|
+
*/
|
|
13
|
+
export const toVideoFrameFixedRotation = (videoSample) => {
|
|
14
|
+
const frame = videoSample.toVideoFrame();
|
|
15
|
+
if (videoSample.rotation === 0) {
|
|
16
|
+
return frame;
|
|
17
|
+
}
|
|
18
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
19
|
+
const ctx = canvas.getContext('2d');
|
|
20
|
+
if (!ctx) {
|
|
21
|
+
throw new Error('Could not get 2d context');
|
|
22
|
+
}
|
|
23
|
+
canvas.width = width;
|
|
24
|
+
canvas.height = height;
|
|
25
|
+
if (canvasRotationToApply === 90) {
|
|
26
|
+
ctx.translate(width, 0);
|
|
27
|
+
}
|
|
28
|
+
else if (canvasRotationToApply === 180) {
|
|
29
|
+
ctx.translate(width, height);
|
|
30
|
+
}
|
|
31
|
+
else if (canvasRotationToApply === 270) {
|
|
32
|
+
ctx.translate(0, height);
|
|
33
|
+
}
|
|
34
|
+
console.log('sample rotation', videoSample.rotation);
|
|
35
|
+
// @ts-expect-error - rotation is not a known property of VideoFrameInit
|
|
36
|
+
const fixedFrame = new VideoFrame(frame, { rotation: videoSample.rotation });
|
|
37
|
+
frame.close();
|
|
38
|
+
// @ts-expect-error - rotation is not a known property of VideoFrameInit
|
|
39
|
+
console.log('fixed frame rotation', fixedFrame.rotation);
|
|
40
|
+
return fixedFrame;
|
|
41
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotion/media",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.374",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/esm/index.mjs",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"mediabunny": "1.24.3",
|
|
25
|
-
"remotion": "4.0.
|
|
25
|
+
"remotion": "4.0.374"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=16.8.0",
|
|
29
29
|
"react-dom": ">=16.8.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
32
|
+
"@remotion/eslint-config-internal": "4.0.374",
|
|
33
33
|
"@vitest/browser-webdriverio": "4.0.7",
|
|
34
34
|
"eslint": "9.19.0",
|
|
35
35
|
"react": "19.0.0",
|