Skip to content

🎥 Make videos programmatically with React

test 3 codecs

Jonny Burger548425e7114d
diff --git a/.gitignore b/.gitignore
index f20eeb24a3..1f2db025b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,8 @@ packages/cloudrun/remotion-lambda-gcp.code-workspace
packages/example/sa-key.json
packages/example/public/pts-framermp4withoutfileextension.mp4
packages/example/public/long-audio.wav
+packages/example/public/long-audio.mp3
+packages/example/public/long-audio.aac
packages/it-tests/packages/example/out/element-2.png
packages/cloudrun/src/gcpInstaller/terraform*
packages/cloudrun/src/gcpInstaller/*.tfplan
diff --git a/packages/example/src/LongAudio.tsx b/packages/example/src/LongAudio.tsx
index 9724726931..65266743f3 100644
--- a/packages/example/src/LongAudio.tsx
+++ b/packages/example/src/LongAudio.tsx
@@ -2,14 +2,33 @@ import {Audio} from '@remotion/media';
import {getStaticFiles} from '@remotion/studio';
import {AbsoluteFill} from 'remotion';
-const FILE_NAME = 'long-audio.wav';
+const FILES = [
+ {
+ name: 'long-audio.wav',
+ codec: 'pcm_s16le',
+ },
+ {
+ name: 'long-audio.mp3',
+ codec: 'libmp3lame',
+ },
+ {
+ name: 'long-audio.aac',
+ codec: 'aac',
+ },
+] as const;
-const FFMPEG_COMMAND = `bunx remotion ffmpeg -f lavfi -i "sine=frequency=440:duration=3600" -c:a pcm_s16le public/${FILE_NAME}`;
+const ffmpegCommand = (fileName: string, codec: string) =>
+ `bunx remotion ffmpeg -f lavfi -i "sine=frequency=440:duration=3600" -c:a ${codec} public/${fileName}`;
export const LongAudio: React.FC = () => {
- const file = getStaticFiles().find((f) => f.name === FILE_NAME);
+ const staticFiles = getStaticFiles();
+ const resolved = FILES.map((f) => ({
+ ...f,
+ file: staticFiles.find((s) => s.name === f.name),
+ }));
+ const missing = resolved.filter((r) => !r.file);
- if (!file) {
+ if (missing.length > 0) {
return (
<AbsoluteFill
style={{
@@ -21,26 +40,36 @@ export const LongAudio: React.FC = () => {
}}
>
<div style={{fontSize: 32, marginBottom: 24}}>
- Missing <code>public/{FILE_NAME}</code>
+ Missing {missing.length} audio file(s)
</div>
<div style={{fontSize: 20, marginBottom: 16, opacity: 0.8}}>
- Generate a 1h test audio with:
+ Generate the missing 1h test audio file(s) with:
</div>
- <pre
- style={{
- fontSize: 22,
- background: '#222',
- padding: 24,
- borderRadius: 8,
- whiteSpace: 'pre-wrap',
- wordBreak: 'break-all',
- }}
- >
- {FFMPEG_COMMAND}
- </pre>
+ {missing.map((m) => (
+ <pre
+ key={m.name}
+ style={{
+ fontSize: 20,
+ background: '#222',
+ padding: 20,
+ borderRadius: 8,
+ marginBottom: 12,
+ whiteSpace: 'pre-wrap',
+ wordBreak: 'break-all',
+ }}
+ >
+ {ffmpegCommand(m.name, m.codec)}
+ </pre>
+ ))}
</AbsoluteFill>
);
}
- return <Audio src={file.src} />;
+ return (
+ <>
+ {resolved.map((r) => (
+ <Audio key={r.name} src={r.file!.src} />
+ ))}
+ </>
+ );
};