🎥 Make videos programmatically with React
extract frame
Jonny Burgercb336e1a1569
diff --git a/packages/renderer/src/test/extract-frame-from-video.test.ts b/packages/renderer/src/test/extract-frame-from-video.test.tsdeleted file mode 100644index 3ef407fc98..0000000000--- a/packages/renderer/src/test/extract-frame-from-video.test.ts+++ /dev/null@@ -1,59 +0,0 @@-import path from 'path';-import {expect, test} from 'vitest';-import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';--const src = path.join(- __dirname,- '..',- '..',- '..',- 'example',- 'public',- 'framermp4withoutfileextension'-);--test('Should be able to extract a frame from a video', async () => {- const downloadMap = makeDownloadMap();- const str = await extractFrameFromVideo({- src,- time: 1,- imageFormat: 'jpeg',- downloadMap,- remotionRoot: process.cwd(),- });-- cleanDownloadMap(downloadMap);-- expect(str.length).toBeGreaterThan(10000);-});--test('Should be able to extract a frame from a video as PNG', async () => {- const downloadMap = makeDownloadMap();-- const str = await extractFrameFromVideo({- src,- time: 1,- imageFormat: 'png',- downloadMap,- remotionRoot: process.cwd(),- });- cleanDownloadMap(downloadMap);-- expect(str.length).toBeGreaterThan(10000);-});--test('Should get the last frame if out of range', async () => {- const downloadMap = makeDownloadMap();-- const str = await extractFrameFromVideo({- src,- time: 100,- imageFormat: 'jpeg',- downloadMap,- remotionRoot: process.cwd(),- });-- cleanDownloadMap(downloadMap);-- expect(str.length).toBeGreaterThan(10000);-});diff --git a/packages/renderer/src/test/extract-frame-rust.test.ts b/packages/renderer/src/test/extract-frame-rust.test.tsindex 7ebed7c660..58bbc464d1 100644--- a/packages/renderer/src/test/extract-frame-rust.test.ts+++ b/packages/renderer/src/test/extract-frame-rust.test.ts@@ -1,4 +1,5 @@import fs from 'fs';+import path from 'path';import {expect, test} from 'vitest';import {startCompositor} from '../compositor/compositor';import {makeNonce} from '../compositor/make-nonce';@@ -84,3 +85,97 @@ test('Should be able to seek backwards', async () => {compositor.finishCommands();await compositor.waitForDone();});++test(+ 'Should be able to extract a frame that has no file extension',+ async () => {+ const compositor = startCompositor({+ type: 'StartLongRunningProcess',+ params: {+ nonce: makeNonce(),+ },+ });++ const data = await compositor.executeCommand('ExtractFrame', {+ input: path.join(+ __dirname,+ '..',+ '..',+ '..',+ 'example',+ 'public',+ 'framermp4withoutfileextension'+ ),+ time: 1,+ });+ expect(data.length).toBe(3499254);+ fs.writeFileSync('nofileext.bmp', data);++ compositor.finishCommands();+ await compositor.waitForDone();+ },+ {timeout: 10000}+);++test.only(+ 'Should get the last frame if out of range',+ async () => {+ const compositor = startCompositor({+ type: 'StartLongRunningProcess',+ params: {+ nonce: makeNonce(),+ },+ });++ // TODO: Should not return 97+ const data = await compositor.executeCommand('ExtractFrame', {+ input: path.join(+ __dirname,+ '..',+ '..',+ '..',+ 'example',+ 'public',+ 'framermp4withoutfileextension'+ ),+ time: 30,+ });+ expect(data.length).toBe(3499254);+ fs.writeFileSync('lastframe.bmp', data);++ compositor.finishCommands();+ await compositor.waitForDone();+ },+ {timeout: 10000}+);++test(+ 'Should get the last frame of a corrupted video',+ async () => {+ const compositor = startCompositor({+ type: 'StartLongRunningProcess',+ params: {+ nonce: makeNonce(),+ },+ });++ const data = await compositor.executeCommand('ExtractFrame', {+ input: path.join(+ __dirname,+ '..',+ '..',+ '..',+ 'example',+ 'public',+ 'corrupted.mp4'+ ),+ time: 100,+ });+ expect(data.length).toBe(3499254);+ fs.writeFileSync('corrupted.bmp', data);++ compositor.finishCommands();+ await compositor.waitForDone();+ },+ {timeout: 5000}+);diff --git a/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts b/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.tsdeleted file mode 100644index 80841aff33..0000000000--- a/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts+++ /dev/null@@ -1,25 +0,0 @@-import path from 'path';-import {test} from 'vitest';-import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';-import {getLastFrameOfVideo} from '../extract-frame-from-video';--test('Get last frame of corrupted video', async () => {- const downloadMap = makeDownloadMap();- await getLastFrameOfVideo({- offset: 0,- src: path.join(- __dirname,- '..',- '..',- '..',- 'example',- 'public',- 'corrupted.mp4'- ),- imageFormat: 'png',- specialVCodecForTransparency: 'none',- needsResize: null,- downloadMap,- });- cleanDownloadMap(downloadMap);-}, 90000);