Skip to content

🎥 Make videos programmatically with React

fix + add tests

Hunain Ahmedbc2aec3460df
diff --git a/packages/core/src/video/codecVideoForRendering.tsx b/packages/core/src/video/codecVideoForRendering.tsx
index ef7766c6e9..70a787ccfd 100644
--- a/packages/core/src/video/codecVideoForRendering.tsx
+++ b/packages/core/src/video/codecVideoForRendering.tsx
@@ -123,12 +123,9 @@ export const CodecVideoForRendering: React.FC<
extractFrames({
src,
- timestampsInSeconds: async ({track}) => {
- if(!track.fps){
- return [];
- }
- console.log(`called for frame ${frame} with timestamp ${frame/track.fps}`)
- return [frame/track.fps]
+ timestampsInSeconds: async () => {
+ console.log(`called for frame ${frame} with timestamp ${frame/videoConfig.fps}`)
+ return [frame/videoConfig.fps]
},
onFrame: (extractedFrame) => {
console.log("successfully extracted the frame " + frame);
diff --git a/packages/example/src/OffthreadVideoToCanvas/index.tsx b/packages/example/src/OffthreadVideoToCanvas/index.tsx
index f0ffd4b371..681d4c26c3 100644
--- a/packages/example/src/OffthreadVideoToCanvas/index.tsx
+++ b/packages/example/src/OffthreadVideoToCanvas/index.tsx
@@ -46,12 +46,9 @@ export const OffthreadVideoToCanvas: React.FC = () => {
<CodecVideo
// muted
// style={{opacity: 0}}
- src={staticFile('vid1.mp4')}
+ src={staticFile('framer.webm')}
// onVideoFrame={onVideoFrame}
/>
- {/* <AbsoluteFill>
- <canvas ref={canvas} width={width} height={height} />
- </AbsoluteFill> */}
</AbsoluteFill>
);
};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 73764e4505..69c9c41f84 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -674,7 +674,6 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={100}
defaultProps={{
- offthread: false,
codec: 'mp4' as const,
}}
/>
@@ -686,7 +685,7 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={100}
defaultProps={{
- offthread: true,
+ type: 'offthread',
codec: 'mp4' as const,
}}
/>
@@ -709,7 +708,6 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={100}
defaultProps={{
- offthread: false,
codec: 'webm' as const,
}}
/>
@@ -721,10 +719,34 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={100}
defaultProps={{
- offthread: true,
+ type: 'offthread',
codec: 'webm' as const,
}}
/>
+ <Composition
+ id="video-testing-webm-codec"
+ component={VideoTesting}
+ width={1080}
+ height={1080}
+ fps={30}
+ durationInFrames={100}
+ defaultProps={{
+ type: 'codec',
+ codec: 'webm' as const,
+ }}
+ />
+ <Composition
+ id="video-testing-mp4-codec"
+ component={VideoTesting}
+ width={1080}
+ height={1080}
+ fps={30}
+ durationInFrames={100}
+ defaultProps={{
+ type: 'codec',
+ codec: 'mp4' as const,
+ }}
+ />
<Composition
id="remote-video"
component={RemoteVideo}
@@ -879,7 +901,6 @@ export const Index: React.FC = () => {
durationInFrames={(inputProps?.duration as number) ?? 20}
defaultProps={{
codec: 'mp4' as const,
- offthread: false,
}}
/>
<Composition
diff --git a/packages/example/src/VideoTesting/index.tsx b/packages/example/src/VideoTesting/index.tsx
index 75c058fbe8..c9fc7ec1c0 100644
--- a/packages/example/src/VideoTesting/index.tsx
+++ b/packages/example/src/VideoTesting/index.tsx
@@ -1,3 +1,4 @@
+import { CodecVideo } from '@remotion/video';
import {
OffthreadVideo,
Sequence,
@@ -8,13 +9,20 @@ import {
export const VideoTesting: React.FC<{
codec: 'mp4' | 'webm';
- offthread: boolean;
-}> = ({codec, offthread}) => {
+ type?: 'normal' | 'offthread' | 'codec'
+}> = ({codec, type = "normal"}) => {
const {durationInFrames} = useVideoConfig();
const videoMp4 = staticFile('framermp4withoutfileextension');
const videoWebm = staticFile('framer.webm');
- const Comp = offthread ? OffthreadVideo : Video;
+ let Comp;
+ if (type === 'codec'){
+ Comp = CodecVideo
+ }else if(type === 'offthread'){
+ Comp = OffthreadVideo
+ }else{
+ Comp = Video
+ }
return (
<div>
diff --git a/packages/it-tests/src/rendering/frame-accuracy.test.ts b/packages/it-tests/src/rendering/frame-accuracy.test.ts
index 255a6150f9..c97524c945 100644
--- a/packages/it-tests/src/rendering/frame-accuracy.test.ts
+++ b/packages/it-tests/src/rendering/frame-accuracy.test.ts
@@ -13,7 +13,7 @@ function selectColor(color: string, frame: number) {
const getMissedFramesforCodec = async (
codec: 'mp4' | 'webm',
- offthread: boolean,
+ type: 'normal' | 'offthread' | 'codec',
) => {
const outputPath = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'remotion-'),
@@ -21,6 +21,7 @@ const getMissedFramesforCodec = async (
// render the VideoTesting example (which contains the Framer composition embedded with <Video>) to an image
// sequence which can be checked for accuracy
+ console.log(`video-testing-${codec}${type === 'normal' ? '' : '-'+type}`)
await execa(
'pnpm',
[
@@ -28,7 +29,7 @@ const getMissedFramesforCodec = async (
'remotion',
'render',
'build',
- `video-testing-${codec}${offthread ? '-offthread' : ''}`,
+ `video-testing-${codec}${type === 'normal' ? '' : '-'+type}`,
outputPath,
'--image-format',
'png',
@@ -88,7 +89,7 @@ const getMissedFramesforCodec = async (
test(
'should render correct frames from embedded videos - WebM onthread',
async () => {
- const missedFrames = await getMissedFramesforCodec('webm', false);
+ const missedFrames = await getMissedFramesforCodec('webm', 'normal');
expect(missedFrames).toBeLessThanOrEqual(8);
},
{
@@ -99,7 +100,7 @@ test(
test(
'should render correct frames from embedded videos - WebM offthread',
async () => {
- const missedFrames = await getMissedFramesforCodec('webm', true);
+ const missedFrames = await getMissedFramesforCodec('webm', 'offthread');
expect(missedFrames).toBe(0);
},
{
@@ -110,7 +111,7 @@ test(
test(
'should render correct frames from embedded videos - MP4 onthread',
async () => {
- const missedFrames = await getMissedFramesforCodec('mp4', false);
+ const missedFrames = await getMissedFramesforCodec('mp4', 'normal');
expect(missedFrames).toBeLessThanOrEqual(8);
},
{
@@ -121,10 +122,32 @@ test(
test(
'should render correct frames from embedded videos - MP4 offthread',
async () => {
- const missedFrames = await getMissedFramesforCodec('mp4', true);
+ const missedFrames = await getMissedFramesforCodec('mp4', 'offthread');
expect(missedFrames).toBe(0);
},
{
timeout: 40000,
},
);
+
+test(
+ 'should render correct frames from embedded videos - WebM codec video',
+ async () => {
+ const missedFrames = await getMissedFramesforCodec('webm', 'codec');
+ expect(missedFrames).toBe(0);
+ },
+ {
+ timeout: 30000,
+ },
+);
+
+test(
+ 'should render correct frames from embedded videos - MP4 codec video',
+ async () => {
+ const missedFrames = await getMissedFramesforCodec('mp4', 'codec');
+ expect(missedFrames).toBeLessThanOrEqual(8);
+ },
+ {
+ timeout: 40000,
+ },
+);