@remotion/media 4.0.351

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.
Files changed (94) hide show
  1. package/LICENSE.md +49 -0
  2. package/README.md +18 -0
  3. package/dist/audio/audio-for-rendering.d.ts +3 -0
  4. package/dist/audio/audio-for-rendering.js +99 -0
  5. package/dist/audio/audio.d.ts +3 -0
  6. package/dist/audio/audio.js +60 -0
  7. package/dist/audio/props.d.ts +29 -0
  8. package/dist/audio/props.js +1 -0
  9. package/dist/audio-extraction/audio-cache.d.ts +11 -0
  10. package/dist/audio-extraction/audio-cache.js +58 -0
  11. package/dist/audio-extraction/audio-iterator.d.ts +24 -0
  12. package/dist/audio-extraction/audio-iterator.js +106 -0
  13. package/dist/audio-extraction/audio-manager.d.ts +64 -0
  14. package/dist/audio-extraction/audio-manager.js +83 -0
  15. package/dist/audio-extraction/extract-audio.d.ts +10 -0
  16. package/dist/audio-extraction/extract-audio.js +77 -0
  17. package/dist/audio-for-rendering.d.ts +3 -0
  18. package/dist/audio-for-rendering.js +94 -0
  19. package/dist/audio.d.ts +3 -0
  20. package/dist/audio.js +60 -0
  21. package/dist/audiodata-to-array.d.ts +0 -0
  22. package/dist/audiodata-to-array.js +1 -0
  23. package/dist/caches.d.ts +86 -0
  24. package/dist/caches.js +15 -0
  25. package/dist/convert-audiodata/combine-audiodata.d.ts +2 -0
  26. package/dist/convert-audiodata/combine-audiodata.js +40 -0
  27. package/dist/convert-audiodata/convert-audiodata.d.ts +16 -0
  28. package/dist/convert-audiodata/convert-audiodata.js +53 -0
  29. package/dist/convert-audiodata/data-types.d.ts +1 -0
  30. package/dist/convert-audiodata/data-types.js +22 -0
  31. package/dist/convert-audiodata/is-planar-format.d.ts +1 -0
  32. package/dist/convert-audiodata/is-planar-format.js +3 -0
  33. package/dist/convert-audiodata/log-audiodata.d.ts +1 -0
  34. package/dist/convert-audiodata/log-audiodata.js +8 -0
  35. package/dist/convert-audiodata/resample-audiodata.d.ts +10 -0
  36. package/dist/convert-audiodata/resample-audiodata.js +72 -0
  37. package/dist/convert-audiodata/trim-audiodata.d.ts +0 -0
  38. package/dist/convert-audiodata/trim-audiodata.js +1 -0
  39. package/dist/deserialized-audiodata.d.ts +15 -0
  40. package/dist/deserialized-audiodata.js +26 -0
  41. package/dist/esm/index.mjs +14487 -0
  42. package/dist/extract-audio.d.ts +7 -0
  43. package/dist/extract-audio.js +98 -0
  44. package/dist/extract-frame-and-audio.d.ts +15 -0
  45. package/dist/extract-frame-and-audio.js +28 -0
  46. package/dist/extract-frame-via-broadcast-channel.d.ts +15 -0
  47. package/dist/extract-frame-via-broadcast-channel.js +104 -0
  48. package/dist/extract-frame.d.ts +27 -0
  49. package/dist/extract-frame.js +21 -0
  50. package/dist/extrct-audio.d.ts +7 -0
  51. package/dist/extrct-audio.js +94 -0
  52. package/dist/get-frames-since-keyframe.d.ts +22 -0
  53. package/dist/get-frames-since-keyframe.js +41 -0
  54. package/dist/index.d.ts +4 -0
  55. package/dist/index.js +2 -0
  56. package/dist/keyframe-bank.d.ts +25 -0
  57. package/dist/keyframe-bank.js +120 -0
  58. package/dist/keyframe-manager.d.ts +23 -0
  59. package/dist/keyframe-manager.js +170 -0
  60. package/dist/log.d.ts +10 -0
  61. package/dist/log.js +33 -0
  62. package/dist/new-video-for-rendering.d.ts +3 -0
  63. package/dist/new-video-for-rendering.js +108 -0
  64. package/dist/new-video.d.ts +3 -0
  65. package/dist/new-video.js +37 -0
  66. package/dist/props.d.ts +29 -0
  67. package/dist/props.js +1 -0
  68. package/dist/remember-actual-matroska-timestamps.d.ts +4 -0
  69. package/dist/remember-actual-matroska-timestamps.js +19 -0
  70. package/dist/serialize-videoframe.d.ts +0 -0
  71. package/dist/serialize-videoframe.js +1 -0
  72. package/dist/video/props.d.ts +28 -0
  73. package/dist/video/props.js +1 -0
  74. package/dist/video/video-for-rendering.d.ts +3 -0
  75. package/dist/video/video-for-rendering.js +115 -0
  76. package/dist/video/video.d.ts +3 -0
  77. package/dist/video/video.js +37 -0
  78. package/dist/video-extraction/extract-frame-via-broadcast-channel.d.ts +16 -0
  79. package/dist/video-extraction/extract-frame-via-broadcast-channel.js +107 -0
  80. package/dist/video-extraction/extract-frame.d.ts +9 -0
  81. package/dist/video-extraction/extract-frame.js +21 -0
  82. package/dist/video-extraction/get-frames-since-keyframe.d.ts +23 -0
  83. package/dist/video-extraction/get-frames-since-keyframe.js +42 -0
  84. package/dist/video-extraction/keyframe-bank.d.ts +25 -0
  85. package/dist/video-extraction/keyframe-bank.js +121 -0
  86. package/dist/video-extraction/keyframe-manager.d.ts +23 -0
  87. package/dist/video-extraction/keyframe-manager.js +171 -0
  88. package/dist/video-extraction/remember-actual-matroska-timestamps.d.ts +5 -0
  89. package/dist/video-extraction/remember-actual-matroska-timestamps.js +19 -0
  90. package/dist/video-for-rendering.d.ts +3 -0
  91. package/dist/video-for-rendering.js +108 -0
  92. package/dist/video.d.ts +3 -0
  93. package/dist/video.js +37 -0
  94. package/package.json +55 -0
@@ -0,0 +1,108 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext, useLayoutEffect, useMemo, useRef, useState, } from 'react';
3
+ import { cancelRender, Internals, useCurrentFrame, useDelayRender, useRemotionEnvironment, } from 'remotion';
4
+ import { extractFrameViaBroadcastChannel } from './extract-frame-via-broadcast-channel';
5
+ export const VideoForRendering = ({ volume: volumeProp, playbackRate, src, muted, loopVolumeCurveBehavior, delayRenderRetries, delayRenderTimeoutInMilliseconds,
6
+ // call when a frame of the video, i.e. frame drawn on canvas
7
+ onVideoFrame, logLevel = window.remotion_logLevel, }) => {
8
+ const absoluteFrame = Internals.useTimelinePosition();
9
+ const videoConfig = Internals.useUnsafeVideoConfig();
10
+ const canvasRef = useRef(null);
11
+ const { registerRenderAsset, unregisterRenderAsset } = useContext(Internals.RenderAssetManager);
12
+ const frame = useCurrentFrame();
13
+ const volumePropsFrame = Internals.useFrameForVolumeProp(loopVolumeCurveBehavior ?? 'repeat');
14
+ const environment = useRemotionEnvironment();
15
+ const [id] = useState(() => `${Math.random()}`.replace('0.', ''));
16
+ if (!videoConfig) {
17
+ throw new Error('No video config found');
18
+ }
19
+ if (!src) {
20
+ throw new TypeError('No `src` was passed to <Video>.');
21
+ }
22
+ const volume = Internals.evaluateVolume({
23
+ volume: volumeProp,
24
+ frame: volumePropsFrame,
25
+ mediaVolume: 1,
26
+ });
27
+ Internals.warnAboutTooHighVolume(volume);
28
+ const shouldRenderAudio = useMemo(() => {
29
+ if (!window.remotion_audioEnabled) {
30
+ return false;
31
+ }
32
+ if (muted) {
33
+ return false;
34
+ }
35
+ if (volume <= 0) {
36
+ return false;
37
+ }
38
+ return true;
39
+ }, [muted, volume]);
40
+ const { fps } = videoConfig;
41
+ const { delayRender, continueRender } = useDelayRender();
42
+ useLayoutEffect(() => {
43
+ if (!canvasRef.current) {
44
+ return;
45
+ }
46
+ const actualFps = playbackRate ? fps / playbackRate : fps;
47
+ const timestamp = frame / actualFps;
48
+ const durationInSeconds = 1 / actualFps;
49
+ const newHandle = delayRender(`Extracting frame number ${frame}`, {
50
+ retries: delayRenderRetries ?? undefined,
51
+ timeoutInMilliseconds: delayRenderTimeoutInMilliseconds ?? undefined,
52
+ });
53
+ extractFrameViaBroadcastChannel({
54
+ src,
55
+ timeInSeconds: timestamp,
56
+ durationInSeconds,
57
+ logLevel: logLevel ?? 'info',
58
+ shouldRenderAudio,
59
+ isClientSideRendering: environment.isClientSideRendering,
60
+ })
61
+ .then(({ frame: imageBitmap, audio }) => {
62
+ if (!imageBitmap) {
63
+ cancelRender(new Error('No video frame found'));
64
+ }
65
+ onVideoFrame?.(imageBitmap);
66
+ canvasRef.current?.getContext('2d')?.drawImage(imageBitmap, 0, 0);
67
+ imageBitmap.close();
68
+ if (audio) {
69
+ registerRenderAsset({
70
+ type: 'inline-audio',
71
+ id,
72
+ audio: Array.from(audio.data),
73
+ sampleRate: audio.sampleRate,
74
+ numberOfChannels: audio.numberOfChannels,
75
+ frame: absoluteFrame,
76
+ timestamp: audio.timestamp,
77
+ duration: (audio.numberOfFrames / audio.sampleRate) * 1000000,
78
+ });
79
+ }
80
+ continueRender(newHandle);
81
+ })
82
+ .catch((error) => {
83
+ cancelRender(error);
84
+ });
85
+ return () => {
86
+ continueRender(newHandle);
87
+ unregisterRenderAsset(id);
88
+ };
89
+ }, [
90
+ absoluteFrame,
91
+ continueRender,
92
+ delayRender,
93
+ delayRenderRetries,
94
+ delayRenderTimeoutInMilliseconds,
95
+ environment.isClientSideRendering,
96
+ fps,
97
+ frame,
98
+ id,
99
+ logLevel,
100
+ onVideoFrame,
101
+ playbackRate,
102
+ registerRenderAsset,
103
+ shouldRenderAudio,
104
+ src,
105
+ unregisterRenderAsset,
106
+ ]);
107
+ return (_jsx("canvas", { ref: canvasRef, width: videoConfig.width, height: videoConfig.height }));
108
+ };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { VideoProps } from './props';
3
+ export declare const Video: React.FC<VideoProps>;
package/dist/video.js ADDED
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback } from 'react';
3
+ import { Internals, Sequence, useRemotionEnvironment } from 'remotion';
4
+ import { VideoForRendering } from './video-for-rendering';
5
+ const { validateMediaTrimProps, resolveTrimProps, validateMediaProps, VideoForPreview, } = Internals;
6
+ export const Video = (props) => {
7
+ // Should only destruct `trimBefore` and `trimAfter` from props,
8
+ // rest gets drilled down
9
+ const { trimBefore, trimAfter, name, pauseWhenBuffering, stack, showInTimeline, ...otherProps } = props;
10
+ const environment = useRemotionEnvironment();
11
+ const onDuration = useCallback(() => undefined, []);
12
+ if (typeof props.src !== 'string') {
13
+ throw new TypeError(`The \`<Video>\` tag requires a string for \`src\`, but got ${JSON.stringify(props.src)} instead.`);
14
+ }
15
+ validateMediaTrimProps({
16
+ startFrom: undefined,
17
+ endAt: undefined,
18
+ trimBefore,
19
+ trimAfter,
20
+ });
21
+ const { trimBeforeValue, trimAfterValue } = resolveTrimProps({
22
+ startFrom: undefined,
23
+ endAt: undefined,
24
+ trimBefore,
25
+ trimAfter,
26
+ });
27
+ if (typeof trimBeforeValue !== 'undefined' ||
28
+ typeof trimAfterValue !== 'undefined') {
29
+ return (_jsx(Sequence, { layout: "none", from: 0 - (trimBeforeValue ?? 0), showInTimeline: false, durationInFrames: trimAfterValue, name: name, children: _jsx(Video, { pauseWhenBuffering: pauseWhenBuffering ?? false, ...otherProps }) }));
30
+ }
31
+ validateMediaProps(props, 'Video');
32
+ if (environment.isRendering) {
33
+ return _jsx(VideoForRendering, { ...otherProps });
34
+ }
35
+ const { onAutoPlayError, onVideoFrame, crossOrigin, delayRenderRetries, delayRenderTimeoutInMilliseconds, ...propsForPreview } = otherProps;
36
+ return (_jsx(VideoForPreview, { _remotionInternalStack: stack ?? null, _remotionInternalNativeLoopPassed: false, onDuration: onDuration, onlyWarnForMediaSeekingError: true, pauseWhenBuffering: pauseWhenBuffering ?? false, showInTimeline: showInTimeline ?? true, onAutoPlayError: onAutoPlayError ?? undefined, onVideoFrame: onVideoFrame ?? null, crossOrigin: crossOrigin, ...propsForPreview }));
37
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@remotion/media",
3
+ "version": "4.0.351",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "module": "dist/esm/index.mjs",
7
+ "repository": {
8
+ "url": "https://github.com/remotion-dev/remotion/tree/main/packages/media"
9
+ },
10
+ "sideEffects": false,
11
+ "author": "Hunain Ahmed <junaidhunain6@gmail.com>",
12
+ "bugs": {
13
+ "url": "https://github.com/remotion-dev/remotion/issues"
14
+ },
15
+ "dependencies": {
16
+ "mediabunny": "1.17.0",
17
+ "webdriverio": "9.19.2",
18
+ "remotion": "4.0.351"
19
+ },
20
+ "peerDependencies": {
21
+ "react": ">=16.8.0",
22
+ "react-dom": ">=16.8.0"
23
+ },
24
+ "devDependencies": {
25
+ "@vitest/browser": "^3.2.4",
26
+ "eslint": "9.19.0",
27
+ "react": "19.0.0",
28
+ "react-dom": "19.0.0",
29
+ "vitest": "3.2.4",
30
+ "@remotion/eslint-config-internal": "4.0.351"
31
+ },
32
+ "keywords": [],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "require": "./dist/index.js",
40
+ "module": "./dist/esm/index.mjs",
41
+ "import": "./dist/esm/index.mjs"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "description": "Experimental WebCodecs-based media tags",
46
+ "homepage": "https://remotion.dev/docs/media",
47
+ "scripts": {
48
+ "if-node-18+": "node -e \"const [maj]=process.versions.node.split('.').map(Number); process.exit(maj>=18?0:1)\"",
49
+ "formatting": "prettier --experimental-cli src --check",
50
+ "lint": "eslint src",
51
+ "watch": "tsc -w",
52
+ "test": "node src/test/execute.mjs",
53
+ "make": "tsc -d && bun --env-file=../.env.bundle bundle.ts"
54
+ }
55
+ }