Skip to content

πŸŽ₯ Make videos programmatically with React

Address PR review feedback for remotion-media

Jonny Burger981c4c5a3338
diff --git a/bun.lock b/bun.lock
index 6e871f271f..4d3efddc33 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1311,10 +1311,8 @@
"version": "4.0.463",
"dependencies": {
"@remotion/cli": "workspace:*",
- "@remotion/media": "workspace:*",
"@remotion/paths": "workspace:*",
"@remotion/shapes": "workspace:*",
- "@remotion/studio": "workspace:*",
"bun-plugin-tailwind": "0.1.2",
"react": "catalog:",
"react-dom": "catalog:",
diff --git a/packages/remotion-media/README.md b/packages/remotion-media/README.md
index b5e8b6e1b0..9daee7d331 100644
--- a/packages/remotion-media/README.md
+++ b/packages/remotion-media/README.md
@@ -18,9 +18,11 @@ Requires `ffmpeg` on your PATH. Renders base compositions from `src/compositions
bun run generate
```
+Place `multiple-audio-streams.mov` in the package root before running `generate` if you want that edge-case fixture included in the catalog.
+
## Build and deploy
-Bundles the catalog UI and uploads to Cloudflare R2 when `AWS_ACCESS_KEY_ID` and `AWS_ACCESS_SECRET_ACCESS_KEY` are set:
+Bundles the catalog UI and uploads to Cloudflare R2 when `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are set:
```bash
bun run build
diff --git a/packages/remotion-media/build.ts b/packages/remotion-media/build.ts
index 2a8a1095fa..1674214ea9 100644
--- a/packages/remotion-media/build.ts
+++ b/packages/remotion-media/build.ts
@@ -1,13 +1,13 @@
#!/usr/bin/env bun
-import { build, Glob, S3Client, type BuildConfig } from "bun";
-import plugin from "bun-plugin-tailwind";
-import { cpSync, existsSync, readdirSync } from "fs";
-import { rm } from "fs/promises";
-import path from "path";
+import {build, S3Client, type BuildConfig} from 'bun';
+import plugin from 'bun-plugin-tailwind';
+import {cpSync, existsSync, readdirSync} from 'fs';
+import {rm} from 'fs/promises';
+import path from 'path';
// Print help text if requested
-if (process.argv.includes("--help") || process.argv.includes("-h")) {
- console.log(`
+if (process.argv.includes('--help') || process.argv.includes('-h')) {
+ console.log(`
πŸ—οΈ Bun Build Script
Usage: bun run build.ts [options]
@@ -32,142 +32,142 @@ Common Options:
Example:
bun run build.ts --outdir=dist --minify --source-map=linked --external=react,react-dom
`);
- process.exit(0);
+ process.exit(0);
}
// Helper function to convert kebab-case to camelCase
const toCamelCase = (str: string): string => {
- return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
+ return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
};
// Helper function to parse a value into appropriate type
const parseValue = (value: string): any => {
- // Handle true/false strings
- if (value === "true") return true;
- if (value === "false") return false;
+ // Handle true/false strings
+ if (value === 'true') return true;
+ if (value === 'false') return false;
- // Handle numbers
- if (/^\d+$/.test(value)) return parseInt(value, 10);
- if (/^\d*\.\d+$/.test(value)) return parseFloat(value);
+ // Handle numbers
+ if (/^\d+$/.test(value)) return parseInt(value, 10);
+ if (/^\d*\.\d+$/.test(value)) return parseFloat(value);
- // Handle arrays (comma-separated)
- if (value.includes(",")) return value.split(",").map((v) => v.trim());
+ // Handle arrays (comma-separated)
+ if (value.includes(',')) return value.split(',').map((v) => v.trim());
- // Default to string
- return value;
+ // Default to string
+ return value;
};
// Magical argument parser that converts CLI args to BuildConfig
function parseArgs(): Partial<BuildConfig> {
- const config: Record<string, any> = {};
- const args = process.argv.slice(2);
-
- for (let i = 0; i < args.length; i++) {
- const arg = args[i];
- if (!arg.startsWith("--")) continue;
-
- // Handle --no-* flags
- if (arg.startsWith("--no-")) {
- const key = toCamelCase(arg.slice(5));
- config[key] = false;
- continue;
- }
-
- // Handle --flag (boolean true)
- if (
- !arg.includes("=") &&
- (i === args.length - 1 || args[i + 1].startsWith("--"))
- ) {
- const key = toCamelCase(arg.slice(2));
- config[key] = true;
- continue;
- }
-
- // Handle --key=value or --key value
- let key: string;
- let value: string;
-
- if (arg.includes("=")) {
- [key, value] = arg.slice(2).split("=", 2);
- } else {
- key = arg.slice(2);
- value = args[++i];
- }
-
- // Convert kebab-case key to camelCase
- key = toCamelCase(key);
-
- // Handle nested properties (e.g. --minify.whitespace)
- if (key.includes(".")) {
- const [parentKey, childKey] = key.split(".");
- config[parentKey] = config[parentKey] || {};
- config[parentKey][childKey] = parseValue(value);
- } else {
- config[key] = parseValue(value);
- }
- }
-
- return config as Partial<BuildConfig>;
+ const config: Record<string, any> = {};
+ const args = process.argv.slice(2);
+
+ for (let i = 0; i < args.length; i++) {
+ const arg = args[i];
+ if (!arg.startsWith('--')) continue;
+
+ // Handle --no-* flags
+ if (arg.startsWith('--no-')) {
+ const key = toCamelCase(arg.slice(5));
+ config[key] = false;
+ continue;
+ }
+
+ // Handle --flag (boolean true)
+ if (
+ !arg.includes('=') &&
+ (i === args.length - 1 || args[i + 1].startsWith('--'))
+ ) {
+ const key = toCamelCase(arg.slice(2));
+ config[key] = true;
+ continue;
+ }
+
+ // Handle --key=value or --key value
+ let key: string;
+ let value: string;
+
+ if (arg.includes('=')) {
+ [key, value] = arg.slice(2).split('=', 2);
+ } else {
+ key = arg.slice(2);
+ value = args[++i];
+ }
+
+ // Convert kebab-case key to camelCase
+ key = toCamelCase(key);
+
+ // Handle nested properties (e.g. --minify.whitespace)
+ if (key.includes('.')) {
+ const [parentKey, childKey] = key.split('.');
+ config[parentKey] = config[parentKey] || {};
+ config[parentKey][childKey] = parseValue(value);
+ } else {
+ config[key] = parseValue(value);
+ }
+ }
+
+ return config as Partial<BuildConfig>;
}
// Helper function to format file sizes
const formatFileSize = (bytes: number): string => {
- const units = ["B", "KB", "MB", "GB"];
- let size = bytes;
- let unitIndex = 0;
+ const units = ['B', 'KB', 'MB', 'GB'];
+ let size = bytes;
+ let unitIndex = 0;
- while (size >= 1024 && unitIndex < units.length - 1) {
- size /= 1024;
- unitIndex++;
- }
+ while (size >= 1024 && unitIndex < units.length - 1) {
+ size /= 1024;
+ unitIndex++;
+ }
- return `${size.toFixed(2)} ${units[unitIndex]}`;
+ return `${size.toFixed(2)} ${units[unitIndex]}`;
};
-console.log("\nπŸš€ Starting build process...\n");
+console.log('\nπŸš€ Starting build process...\n');
// Parse CLI arguments with our magical parser
const cliConfig = parseArgs();
-const outdir = cliConfig.outdir || path.join(process.cwd(), "dist");
+const outdir = cliConfig.outdir || path.join(process.cwd(), 'dist');
if (existsSync(outdir)) {
- console.log(`πŸ—‘οΈ Cleaning previous build at ${outdir}`);
- await rm(outdir, { recursive: true, force: true });
+ console.log(`πŸ—‘οΈ Cleaning previous build at ${outdir}`);
+ await rm(outdir, {recursive: true, force: true});
}
const start = performance.now();
// Scan for all HTML files in the project
-const entrypoints = [...new Bun.Glob("**.html").scanSync("src")]
- .map((a) => path.resolve("src", a))
- .filter((dir) => !dir.includes("node_modules"));
+const entrypoints = [...new Bun.Glob('**.html').scanSync('src')]
+ .map((a) => path.resolve('src', a))
+ .filter((dir) => !dir.includes('node_modules'));
console.log(
- `πŸ“„ Found ${entrypoints.length} HTML ${
- entrypoints.length === 1 ? "file" : "files"
- } to process\n`
+ `πŸ“„ Found ${entrypoints.length} HTML ${
+ entrypoints.length === 1 ? 'file' : 'files'
+ } to process\n`,
);
// Build all the HTML files
const result = await build({
- entrypoints,
- outdir,
- plugins: [plugin],
- minify: true,
- target: "browser",
- sourcemap: "linked",
- define: {
- "process.env.NODE_ENV": JSON.stringify("production"),
- },
- ...cliConfig, // Merge in any CLI-provided options
+ entrypoints,
+ outdir,
+ plugins: [plugin],
+ minify: true,
+ target: 'browser',
+ sourcemap: 'linked',
+ define: {
+ 'process.env.NODE_ENV': JSON.stringify('production'),
+ },
+ ...cliConfig, // Merge in any CLI-provided options
});
// Print the results
const end = performance.now();
const outputTable = result.outputs.map((output) => ({
- File: path.relative(process.cwd(), output.path),
- Type: output.kind,
- Size: formatFileSize(output.size),
+ File: path.relative(process.cwd(), output.path),
+ Type: output.kind,
+ Size: formatFileSize(output.size),
}));
console.table(outputTable);
@@ -175,49 +175,52 @@ const buildTime = (end - start).toFixed(2);
console.log(`\nβœ… Build completed in ${buildTime}ms\n`);
-const filesDir = path.join(process.cwd(), "files");
+const filesDir = path.join(process.cwd(), 'files');
-for await (const file of new Bun.Glob("chunk-*").scan(filesDir)) {
- await rm(path.join(filesDir, file));
+for await (const file of new Bun.Glob('chunk-*').scan(filesDir)) {
+ await rm(path.join(filesDir, file));
}
-const indexHtml = path.join(filesDir, "index.html");
+const indexHtml = path.join(filesDir, 'index.html');
if (existsSync(indexHtml)) {
- await rm(indexHtml);
+ await rm(indexHtml);
}
const files = readdirSync(outdir);
for (const file of files) {
- cpSync(path.join(outdir, file), path.join(filesDir, file));
+ cpSync(path.join(outdir, file), path.join(filesDir, file));
}
-if (!Bun.env.AWS_ACCESS_KEY_ID || !Bun.env.AWS_ACCESS_SECRET_KEY) {
- console.log(
- "Skipping R2 upload: AWS_ACCESS_KEY_ID and AWS_ACCESS_SECRET_KEY are not set",
- );
+const awsSecretAccessKey =
+ Bun.env.AWS_SECRET_ACCESS_KEY ?? Bun.env.AWS_ACCESS_SECRET_KEY;
+
+if (!Bun.env.AWS_ACCESS_KEY_ID || !awsSecretAccessKey) {
+ console.log(
+ 'Skipping R2 upload: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are not set',
+ );
} else {
- const client = new S3Client({
- accessKeyId: Bun.env.AWS_ACCESS_KEY_ID,
- secretAccessKey: Bun.env.AWS_ACCESS_SECRET_KEY,
- endpoint:
- "https://2fe488b3b0f4deee223aef7464784c46.r2.cloudflarestorage.com",
- bucket: "parser-media",
- });
-
- for (const file of readdirSync(filesDir)) {
- const exists = await client.exists(file);
- const fileToUpload = Bun.file(path.join(filesDir, file));
- if (exists) {
- const stat = await client.stat(file);
- if (stat.size === fileToUpload.size) {
- console.log(
- `Skipping ${file} because it already exists and is the same size`,
- );
- continue;
- }
- }
-
- await client.write(file, fileToUpload);
- console.log(`Uploaded ${file}`);
- }
+ const client = new S3Client({
+ accessKeyId: Bun.env.AWS_ACCESS_KEY_ID,
+ secretAccessKey: awsSecretAccessKey,
+ endpoint:
+ 'https://2fe488b3b0f4deee223aef7464784c46.r2.cloudflarestorage.com',
+ bucket: 'parser-media',
+ });
+
+ for (const file of readdirSync(filesDir)) {
+ const exists = await client.exists(file);
+ const fileToUpload = Bun.file(path.join(filesDir, file));
+ if (exists) {
+ const stat = await client.stat(file);
+ if (stat.size === fileToUpload.size) {
+ console.log(
+ `Skipping ${file} because it already exists and is the same size`,
+ );
+ continue;
+ }
+ }
+
+ await client.write(file, fileToUpload);
+ console.log(`Uploaded ${file}`);
+ }
}
diff --git a/packages/remotion-media/clean.ts b/packages/remotion-media/clean.ts
index b5e977dc08..4f9455244b 100644
--- a/packages/remotion-media/clean.ts
+++ b/packages/remotion-media/clean.ts
@@ -1,5 +1,5 @@
-import { $ } from "bun";
+import {$} from 'bun';
-$`rm -rf files`;
-$`rm -rf out`;
-$`rm -rf dist`;
+await $`rm -rf files`;
+await $`rm -rf out`;
+await $`rm -rf dist`;
diff --git a/packages/remotion-media/generate.ts b/packages/remotion-media/generate.ts
index 6715040ef6..d24f0dedb4 100644
--- a/packages/remotion-media/generate.ts
+++ b/packages/remotion-media/generate.ts
@@ -1,30 +1,30 @@
-import { copyFileSync, existsSync, mkdirSync } from "fs";
-import { $ } from "bun";
-import path from "path";
+import {$} from 'bun';
+import {copyFileSync, existsSync, mkdirSync} from 'fs';
+import path from 'path';
const audioCodecs = [
- "aac",
- "flac",
- "mp3",
- "opus",
- "vorbis",
- "pcm",
- "none",
+ 'aac',
+ 'flac',
+ 'mp3',
+ 'opus',
+ 'vorbis',
+ 'pcm',
+ 'none',
] as const;
-const videoCodecs = ["h264", "h265", "vp8", "vp9", "prores", "none"] as const;
-const containers = ["mp4", "wav", "mp3", "flac", "webm", "mkv", "mov"] as const;
+const videoCodecs = ['h264', 'h265', 'vp8', 'vp9', 'prores', 'none'] as const;
+const containers = ['mp4', 'wav', 'mp3', 'flac', 'webm', 'mkv', 'mov'] as const;
const categories = [
- "codecs",
- "dimensions",
- "durations",
- "fps",
- "audio",
- "sample-rates",
- "greenscreen",
- "edge-cases",
- "sound-effects",
- "hls",
+ 'codecs',
+ 'dimensions',
+ 'durations',
+ 'fps',
+ 'audio',
+ 'sample-rates',
+ 'greenscreen',
+ 'edge-cases',
+ 'sound-effects',
+ 'hls',
] as const;
type Container = (typeof containers)[number];
@@ -33,631 +33,677 @@ type AudioCodec = (typeof audioCodecs)[number];
type Category = (typeof categories)[number];
type VideoVariant = {
- videoCodec: VideoCodec;
- audioCodec: AudioCodec;
- container: Container | "m3u8";
- fileNames: string[];
- size: number;
- category: Category;
- attribution?: string;
+ videoCodec: VideoCodec;
+ audioCodec: AudioCodec;
+ container: Container | 'm3u8';
+ fileNames: string[];
+ size: number;
+ category: Category;
+ attribution?: string;
};
-const outDir = "files";
+const outDir = 'files';
const canFitAudioCodecInContainer: {
- [key in Container]: { [key in AudioCodec]: boolean };
+ [key in Container]: {[key in AudioCodec]: boolean};
} = {
- mp4: {
- aac: true,
- flac: true,
- mp3: true,
- opus: false,
- vorbis: false,
- pcm: true,
- none: true,
- },
- wav: {
- aac: false,
- flac: false,
- mp3: false,
- opus: false,
- vorbis: false,
- pcm: true,
- none: false,
- },
- flac: {
- aac: false,
- flac: true,
- mp3: false,
- opus: false,
- vorbis: false,
- pcm: false,
- none: false,
- },
- webm: {
- aac: false,
- flac: false,
- mp3: false,
- opus: true,
- vorbis: true,
- pcm: false,
- none: true,
- },
- mp3: {
- aac: false,
- flac: false,
- mp3: true,
- opus: false,
- vorbis: false,
- pcm: false,
- none: false,
- },
- mkv: {
- aac: true,
- flac: true,
- mp3: true,
- opus: true,
- vorbis: true,
- pcm: false,
- none: true,
- },
- mov: {
- aac: true,
- flac: false,
- mp3: false,
- opus: false,
- vorbis: false,
- pcm: true,
- none: true,
- },
+ mp4: {
+ aac: true,
+ flac: true,
+ mp3: true,
+ opus: false,
+ vorbis: false,
+ pcm: true,
+ none: true,
+ },
+ wav: {
+ aac: false,
+ flac: false,
+ mp3: false,
+ opus: false,
+ vorbis: false,
+ pcm: true,
+ none: false,
+ },
+ flac: {
+ aac: false,
+ flac: true,
+ mp3: false,
+ opus: false,
+ vorbis: false,
+ pcm: false,
+ none: false,
+ },
+ webm: {
+ aac: false,
+ flac: false,
+ mp3: false,
+ opus: true,
+ vorbis: true,
+ pcm: false,
+ none: true,
+ },
+ mp3: {
+ aac: false,
+ flac: false,
+ mp3: true,
+ opus: false,
+ vorbis: false,
+ pcm: false,
+ none: false,
+ },
+ mkv: {
+ aac: true,
+ flac: true,
+ mp3: true,
+ opus: true,
+ vorbis: true,
+ pcm: false,
+ none: true,
+ },
+ mov: {
+ aac: true,
+ flac: false,
+ mp3: false,
+ opus: false,
+ vorbis: false,
+ pcm: true,
+ none: true,
+ },
};
const canFitVideoCodecInContainer: {
- [key in Container]: { [key in VideoCodec]: boolean };
+ [key in Container]: {[key in VideoCodec]: boolean};
} = {
- mp4: {
- h264: true,
- h265: true,
- vp8: false,
- vp9: false,
- prores: false,
- none: false,
- },
- wav: {
- h264: false,
- h265: false,
- vp8: false,
- vp9: false,
- prores: false,
- none: true,
- },
- flac: {
- h264: false,
- h265: false,
- vp8: false,
- vp9: false,
- prores: false,
- none: true,
- },
- webm: {
- h264: false,
- h265: false,
- vp8: true,
- vp9: true,
- prores: false,
- none: false,
- },
- mp3: {
- h264: false,
- h265: false,
- vp8: false,
- vp9: false,
- prores: false,
- none: true,
- },
- mkv: {
- h264: true,
- h265: true,
- vp8: true,
- vp9: true,
- prores: true,
- none: false,
- },
- mov: {
- h264: true,
- h265: true,
- vp8: false,
- vp9: false,
- prores: true,
- none: false,
- },
+ mp4: {
+ h264: true,
+ h265: true,
+ vp8: false,
+ vp9: false,
+ prores: false,
+ none: false,
+ },
+ wav: {
+ h264: false,
+ h265: false,
+ vp8: false,
+ vp9: false,
+ prores: false,
+ none: true,
+ },
+ flac: {
+ h264: false,
+ h265: false,
+ vp8: false,
+ vp9: false,
+ prores: false,
+ none: true,
+ },
+ webm: {
+ h264: false,
+ h265: false,
+ vp8: true,
+ vp9: true,
+ prores: false,
+ none: false,
+ },
+ mp3: {
+ h264: false,
+ h265: false,
+ vp8: false,
+ vp9: false,
+ prores: false,
+ none: true,
+ },
+ mkv: {
+ h264: true,
+ h265: true,
+ vp8: true,
+ vp9: true,
+ prores: true,
+ none: false,
+ },
+ mov: {
+ h264: true,
+ h265: true,
+ vp8: false,
+ vp9: false,
+ prores: true,
+ none: false,
+ },
};
-const defaultVideoCodec: { [key in Container]: VideoCodec | null } = {
- mp4: "h264",
- wav: null,
- flac: null,
- webm: "vp8",
- mp3: null,
- mkv: "h264",
- mov: "h264",
+const defaultVideoCodec: {[key in Container]: VideoCodec | null} = {
+ mp4: 'h264',
+ wav: null,
+ flac: null,
+ webm: 'vp8',
+ mp3: null,
+ mkv: 'h264',
+ mov: 'h264',
};
-const defaultAudioCodec: { [key in Container]: AudioCodec | null } = {
- mp4: "aac",
- wav: "pcm",
- flac: "flac",
- webm: null,
- mp3: "mp3",
- mkv: "aac",
- mov: "aac",
+const defaultAudioCodec: {[key in Container]: AudioCodec | null} = {
+ mp4: 'aac',
+ wav: 'pcm',
+ flac: 'flac',
+ webm: null,
+ mp3: 'mp3',
+ mkv: 'aac',
+ mov: 'aac',
};
-const isVideoContainer: { [key in Container]: boolean } = {
- mp4: true,
- wav: false,
- flac: false,
- webm: true,
- mp3: false,
- mkv: true,
- mov: true,
+const isVideoContainer: {[key in Container]: boolean} = {
+ mp4: true,
+ wav: false,
+ flac: false,
+ webm: true,
+ mp3: false,
+ mkv: true,
+ mov: true,
};
const videoEncoders: {
- [key in VideoCodec]: string | null;
+ [key in VideoCodec]: string | null;
} = {
- h264: "libx264",
- h265: "libx265",
- vp8: "libvpx",
- vp9: "libvpx-vp9",
- prores: "prores_ks",
- none: null,
+ h264: 'libx264',
+ h265: 'libx265',
+ vp8: 'libvpx',
+ vp9: 'libvpx-vp9',
+ prores: 'prores_ks',
+ none: null,
};
const audioEncoders: {
- [key in AudioCodec]: string | null;
+ [key in AudioCodec]: string | null;
} = {
- aac: "aac",
- flac: "flac",
- mp3: "mp3",
- opus: "libopus",
- vorbis: "libvorbis",
- pcm: "pcm_s16le",
- none: null,
+ aac: 'aac',
+ flac: 'flac',
+ mp3: 'mp3',
+ opus: 'libopus',
+ vorbis: 'libvorbis',
+ pcm: 'pcm_s16le',
+ none: null,
};
const extensions: {
- [key in Container]: string;
+ [key in Container]: string;
} = {
- flac: "flac",
- mp3: "mp3",
- mp4: "mp4",
- mkv: "mkv",
- webm: "webm",
- wav: "wav",
- mov: "mov",
+ flac: 'flac',
+ mp3: 'mp3',
+ mp4: 'mp4',
+ mkv: 'mkv',
+ webm: 'webm',
+ wav: 'wav',
+ mov: 'mov',
};
const getOutputName = ({
- container,
- videoCodec,
- audioCodec,
- abbreviateDefaultVideoCodec,
- abbreviateDefaultAudioCodec,
+ container,
+ videoCodec,
+ audioCodec,
+ abbreviateDefaultVideoCodec,
+ abbreviateDefaultAudioCodec,
}: {
- container: Container;
- videoCodec: VideoCodec;
- audioCodec: AudioCodec;
- abbreviateDefaultVideoCodec: boolean;
- abbreviateDefaultAudioCodec: boolean;
+ container: Container;
+ videoCodec: VideoCodec;
+ audioCodec: AudioCodec;
+ abbreviateDefaultVideoCodec: boolean;
+ abbreviateDefaultAudioCodec: boolean;
}) => {
- const isDefaultVideoCodec = defaultVideoCodec[container] === videoCodec;
- const isDefaultAudioCodec = defaultAudioCodec[container] === audioCodec;
-
- return [
- [
- isVideoContainer[container] ? "video" : "audio",
- isDefaultVideoCodec && abbreviateDefaultVideoCodec
- ? null
- : isVideoContainer[container]
- ? videoCodec
- : null,
- isDefaultAudioCodec && abbreviateDefaultAudioCodec ? null : audioCodec,
- ]
- .filter(Boolean)
- .join("-"),
- extensions[container],
- ].join(".");
+ const isDefaultVideoCodec = defaultVideoCodec[container] === videoCodec;
+ const isDefaultAudioCodec = defaultAudioCodec[container] === audioCodec;
+
+ return [
+ [
+ isVideoContainer[container] ? 'video' : 'audio',
+ isDefaultVideoCodec && abbreviateDefaultVideoCodec
+ ? null
+ : isVideoContainer[container]
+ ? videoCodec
+ : null,
+ isDefaultAudioCodec && abbreviateDefaultAudioCodec ? null : audioCodec,
+ ]
+ .filter(Boolean)
+ .join('-'),
+ extensions[container],
+ ].join('.');
};
-const base8k = path.join("out", "8k.mp4");
-const baseMute = path.join("out", "mute.mp4");
+const tonePath = 'tone.wav';
+
+const base8k = path.join('out', '8k.mp4');
+const baseMute = path.join('out', 'mute.mp4');
+
+const generateCodecVariant = async ({
+ outputPath,
+ videoEncoder,
+ audioEncoder,
+}: {
+ outputPath: string;
+ videoEncoder: string | null;
+ audioEncoder: string | null;
+}) => {
+ if (videoEncoder && audioEncoder) {
+ await $`ffmpeg -i ${baseMute} -i ${tonePath} -t 10 -c:v ${videoEncoder} -c:a ${audioEncoder} ${outputPath} -y`;
+ return;
+ }
+
+ if (videoEncoder && !audioEncoder) {
+ await $`ffmpeg -i ${baseMute} -t 10 -c:v ${videoEncoder} -an ${outputPath} -y`;
+ return;
+ }
+
+ if (!videoEncoder && audioEncoder) {
+ await $`ffmpeg -i ${tonePath} -t 10 -vn -c:a ${audioEncoder} ${outputPath} -y`;
+ return;
+ }
+
+ throw new Error(`No encoders for ${outputPath}`);
+};
if (!(await Bun.file(base8k).exists())) {
- await $`bunx remotion render src/compositions/index.ts Base ${base8k} --frames=0-599 --scale=4 --muted`;
+ await $`bunx remotion render src/compositions/index.ts Base ${base8k} --frames=0-599 --scale=4 --muted`;
}
if (!(await Bun.file(baseMute).exists())) {
- await $`bunx remotion render src/compositions/index.ts Base ${baseMute} --muted`;
+ await $`bunx remotion render src/compositions/index.ts Base ${baseMute} --muted`;
}
const variants: VideoVariant[] = [];
for (const container of containers) {
- for (const videoCodec of videoCodecs) {
- for (const audioCodec of audioCodecs) {
- if (!canFitAudioCodecInContainer[container][audioCodec]) {
- continue;
- }
-
- if (!canFitVideoCodecInContainer[container][videoCodec]) {
- continue;
- }
-
- const [outputName, ...alternativeNames] = [
- ...new Set([
- getOutputName({
- container,
- videoCodec,
- audioCodec,
- abbreviateDefaultAudioCodec: true,
- abbreviateDefaultVideoCodec: true,
- }),
- getOutputName({
- container,
- videoCodec,
- audioCodec,
- abbreviateDefaultAudioCodec: true,
- abbreviateDefaultVideoCodec: false,
- }),
- getOutputName({
- container,
- videoCodec,
- audioCodec,
- abbreviateDefaultAudioCodec: false,
- abbreviateDefaultVideoCodec: true,
- }),
- getOutputName({
- container,
- videoCodec,
- audioCodec,
- abbreviateDefaultAudioCodec: false,
- abbreviateDefaultVideoCodec: false,
- }),
- ]),
- ];
-
- if (!existsSync(outDir)) {
- mkdirSync(outDir, { recursive: true });
- }
-
- if (!(await Bun.file(path.join(outDir, outputName)).exists())) {
- console.log(`Generating ${outputName}`);
-
- const videoEncoder = videoEncoders[videoCodec];
- const audioEncoder = audioEncoders[audioCodec];
-
- // 10 second video
- await $`ffmpeg ${videoEncoder ? "-i" : ""} ${
- videoEncoder ? baseMute : ""
- } ${audioEncoder ? "-i" : ""} ${
- audioEncoder ? "tone.wav" : ""
- } -t 10 -c:v ${videoEncoder} -c:a ${audioEncoder} ${path.join(
- outDir,
- outputName
- )} -y`;
- }
-
- for (const alternativeName of alternativeNames) {
- copyFileSync(
- path.join(outDir, outputName),
- path.join(outDir, alternativeName)
- );
- }
-
- const size = await Bun.file(path.join(outDir, outputName)).stat();
-
- const videoVariant: VideoVariant = {
- videoCodec,
- audioCodec,
- container,
- fileNames: [outputName, ...alternativeNames],
- size: size.size,
- category: "codecs",
- };
- variants.push(videoVariant);
- }
- }
+ for (const videoCodec of videoCodecs) {
+ for (const audioCodec of audioCodecs) {
+ if (!canFitAudioCodecInContainer[container][audioCodec]) {
+ continue;
+ }
+
+ if (!canFitVideoCodecInContainer[container][videoCodec]) {
+ continue;
+ }
+
+ const [outputName, ...alternativeNames] = [
+ ...new Set([
+ getOutputName({
+ container,
+ videoCodec,
+ audioCodec,
+ abbreviateDefaultAudioCodec: true,
+ abbreviateDefaultVideoCodec: true,
+ }),
+ getOutputName({
+ container,
+ videoCodec,
+ audioCodec,
+ abbreviateDefaultAudioCodec: true,
+ abbreviateDefaultVideoCodec: false,
+ }),
+ getOutputName({
+ container,
+ videoCodec,
+ audioCodec,
+ abbreviateDefaultAudioCodec: false,
+ abbreviateDefaultVideoCodec: true,
+ }),
+ getOutputName({
+ container,
+ videoCodec,
+ audioCodec,
+ abbreviateDefaultAudioCodec: false,
+ abbreviateDefaultVideoCodec: false,
+ }),
+ ]),
+ ];
+
+ if (!existsSync(outDir)) {
+ mkdirSync(outDir, {recursive: true});
+ }
+
+ if (!(await Bun.file(path.join(outDir, outputName)).exists())) {
+ console.log(`Generating ${outputName}`);
+
+ const videoEncoder = videoEncoders[videoCodec];
+ const audioEncoder = audioEncoders[audioCodec];
+
+ await generateCodecVariant({
+ outputPath: path.join(outDir, outputName),
+ videoEncoder,
+ audioEncoder,
+ });
+ }
+
+ for (const alternativeName of alternativeNames) {
+ copyFileSync(
+ path.join(outDir, outputName),
+ path.join(outDir, alternativeName),
+ );
+ }
+
+ const size = await Bun.file(path.join(outDir, outputName)).stat();
+
+ const videoVariant: VideoVariant = {
+ videoCodec,
+ audioCodec,
+ container,
+ fileNames: [outputName, ...alternativeNames],
+ size: size.size,
+ category: 'codecs',
+ };
+ variants.push(videoVariant);
+ }
+ }
}
// Generate additional size variants (16:9) from out/8k.mp4 using H.264/AAC MP4
const sizePresets = [
- { width: 640, height: 360, label: "360p" },
- { width: 854, height: 480, label: "480p" },
- { width: 1280, height: 720, label: "720p" },
- { width: 1920, height: 1080, label: "1080p" },
- { width: 2560, height: 1440, label: "1440p" },
- { width: 3840, height: 2160, label: "2160p" },
+ {width: 640, height: 360, label: '360p'},
+ {width: 854, height: 480, label: '480p'},
+ {width: 1280, height: 720, label: '720p'},
+ {width: 1920, height: 1080, label: '1080p'},
+ {width: 2560, height: 1440, label: '1440p'},
+ {width: 3840, height: 2160, label: '2160p'},
] as const;
for (const preset of sizePresets) {
- const outputName = `video-${preset.label}.mp4`;
- const targetPath = path.join(outDir, outputName);
-
- if (!(await Bun.file(targetPath).exists())) {
- console.log(`Generating ${outputName} from ${base8k}`);
- await $`ffmpeg -i ${base8k} -i tone.wav -vf scale=${preset.width}:${preset.height} -c:v libx264 -c:a aac ${targetPath} -y`;
- }
-
- const stat = await Bun.file(targetPath).stat();
- const videoVariant: VideoVariant = {
- videoCodec: "h264",
- audioCodec: "aac",
- container: "mp4",
- fileNames: [outputName],
- size: stat.size,
- category: "dimensions",
- };
- variants.push(videoVariant);
+ const outputName = `video-${preset.label}.mp4`;
+ const targetPath = path.join(outDir, outputName);
+
+ if (!(await Bun.file(targetPath).exists())) {
+ console.log(`Generating ${outputName} from ${base8k}`);
+ await $`ffmpeg -i ${base8k} -i tone.wav -vf scale=${preset.width}:${preset.height} -c:v libx264 -c:a aac ${targetPath} -y`;
+ }
+
+ const stat = await Bun.file(targetPath).stat();
+ const videoVariant: VideoVariant = {
+ videoCodec: 'h264',
+ audioCodec: 'aac',
+ container: 'mp4',
+ fileNames: [outputName],
+ size: stat.size,
+ category: 'dimensions',
+ };
+ variants.push(videoVariant);
}
// Generate duration variants (use BaseMute as the video reference), H.264/AAC MP4
-const durationBaseVideoPath = "out/mute.mp4";
+const durationBaseVideoPath = 'out/mute.mp4';
const durationPresets = [
- { seconds: 5, label: "5s" },
- { seconds: 10, label: "10s" },
- { seconds: 30, label: "30s" },
- { seconds: 60, label: "1m" },
- { seconds: 60 * 5, label: "5m" },
- { seconds: 60 * 10, label: "10m" },
- { seconds: 60 * 30, label: "30m" },
+ {seconds: 5, label: '5s'},
+ {seconds: 10, label: '10s'},
+ {seconds: 30, label: '30s'},
+ {seconds: 60, label: '1m'},
+ {seconds: 60 * 5, label: '5m'},
+ {seconds: 60 * 10, label: '10m'},
+ {seconds: 60 * 30, label: '30m'},
] as const;
for (const preset of durationPresets) {
- const outputName = `video-${preset.label}.mp4`;
- const targetPath = path.join(outDir, outputName);
-
- if (!(await Bun.file(targetPath).exists())) {
- console.log(`Generating ${outputName} from ${durationBaseVideoPath}`);
- await $`ffmpeg -i ${durationBaseVideoPath} -i tone.wav -t ${preset.seconds} -c:v copy -c:a aac ${targetPath} -y`;
- }
-
- const stat = await Bun.file(targetPath).stat();
- const videoVariant: VideoVariant = {
- videoCodec: "h264",
- audioCodec: "aac",
- container: "mp4",
- fileNames: [outputName],
- size: stat.size,
- category: "durations",
- };
- variants.push(videoVariant);
+ const outputName = `video-${preset.label}.mp4`;
+ const targetPath = path.join(outDir, outputName);
+
+ if (!(await Bun.file(targetPath).exists())) {
+ console.log(`Generating ${outputName} from ${durationBaseVideoPath}`);
+ await $`ffmpeg -i ${durationBaseVideoPath} -i tone.wav -t ${preset.seconds} -c:v copy -c:a aac ${targetPath} -y`;
+ }
+
+ const stat = await Bun.file(targetPath).stat();
+ const videoVariant: VideoVariant = {
+ videoCodec: 'h264',
+ audioCodec: 'aac',
+ container: 'mp4',
+ fileNames: [outputName],
+ size: stat.size,
+ category: 'durations',
+ };
+ variants.push(videoVariant);
}
const fpsPresets = [
- { fps: 24, label: "24fps" },
- { fps: 25, label: "25fps" },
- { fps: 29.97, label: "29.97fps" },
- { fps: 30, label: "30fps" },
- { fps: 59.94, label: "59.94fps" },
- { fps: 60, label: "60fps" },
- { fps: 120, label: "120fps" },
- { fps: 240, label: "240fps" },
+ {fps: 24, label: '24fps'},
+ {fps: 25, label: '25fps'},
+ {fps: 29.97, label: '29.97fps'},
+ {fps: 30, label: '30fps'},
+ {fps: 59.94, label: '59.94fps'},
+ {fps: 60, label: '60fps'},
+ {fps: 120, label: '120fps'},
+ {fps: 240, label: '240fps'},
] as const;
for (const preset of fpsPresets) {
- const outputName = `video-${preset.label}.mp4`;
- const targetPath = path.join(outDir, outputName);
-
- if (!(await Bun.file(targetPath).exists())) {
- console.log(`Generating ${outputName}`);
- const intermediate = path.join("out", `${preset.label}.mp4`);
- if (!(await Bun.file(intermediate).exists())) {
- await $`bunx remotion render src/compositions/index.ts Base --props="{\"fps\": ${
- preset.fps
- }}" --frames=0-${Math.round(
- preset.fps * 10 - 1
- )} --muted=true ${intermediate}`;
- }
- await $`ffmpeg -i ${intermediate} -i tone.wav -t 10 -c:v copy -c:a aac ${targetPath} -y`;
- }
-
- const stat = await Bun.file(targetPath).stat();
- variants.push({
- videoCodec: "h264",
- audioCodec: "aac",
- container: "mp4",
- fileNames: [outputName],
- size: stat.size,
- category: "fps",
- });
+ const outputName = `video-${preset.label}.mp4`;
+ const targetPath = path.join(outDir, outputName);
+
+ if (!(await Bun.file(targetPath).exists())) {
+ console.log(`Generating ${outputName}`);
+ const intermediate = path.join('out', `${preset.label}.mp4`);
+ if (!(await Bun.file(intermediate).exists())) {
+ await $`bunx remotion render src/compositions/index.ts Base --props="{\"fps\": ${
+ preset.fps
+ }}" --frames=0-${Math.round(
+ preset.fps * 10 - 1,
+ )} --muted=true ${intermediate}`;
+ }
+ await $`ffmpeg -i ${intermediate} -i tone.wav -t 10 -c:v copy -c:a aac ${targetPath} -y`;
+ }
+
+ const stat = await Bun.file(targetPath).stat();
+ variants.push({
+ videoCodec: 'h264',
+ audioCodec: 'aac',
+ container: 'mp4',
+ fileNames: [outputName],
+ size: stat.size,
+ category: 'fps',
+ });
}
-copyFileSync("dialogue.wav", path.join(outDir, "dialogue.wav"));
+copyFileSync('dialogue.wav', path.join(outDir, 'dialogue.wav'));
+const dialogueStat = await Bun.file(path.join(outDir, 'dialogue.wav')).stat();
variants.push({
- videoCodec: "none",
- audioCodec: "pcm",
- container: "wav",
- fileNames: ["dialogue.wav"],
- size: Bun.file(path.join(outDir, "dialogue.wav")).size,
- category: "audio",
+ videoCodec: 'none',
+ audioCodec: 'pcm',
+ container: 'wav',
+ fileNames: ['dialogue.wav'],
+ size: dialogueStat.size,
+ category: 'audio',
});
-variants.push({
- videoCodec: "h264",
- audioCodec: "pcm",
- container: "mov",
- fileNames: ["multiple-audio-streams.mov"],
- size: 66906020,
- category: "audio",
-});
+const multipleAudioStreamsFileName = 'multiple-audio-streams.mov';
+const multipleAudioStreamsTarget = path.join(
+ outDir,
+ multipleAudioStreamsFileName,
+);
+if (await Bun.file(multipleAudioStreamsFileName).exists()) {
+ if (!(await Bun.file(multipleAudioStreamsTarget).exists())) {
+ copyFileSync(multipleAudioStreamsFileName, multipleAudioStreamsTarget);
+ }
+
+ const multipleAudioStreamsStat = await Bun.file(
+ multipleAudioStreamsTarget,
+ ).stat();
+ variants.push({
+ videoCodec: 'h264',
+ audioCodec: 'pcm',
+ container: 'mov',
+ fileNames: [multipleAudioStreamsFileName],
+ size: multipleAudioStreamsStat.size,
+ category: 'audio',
+ });
+}
// Generate PCM WAV sine tone files at various sample rates
const pcmSampleRates = [
- 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000,
- 176400, 192000,
+ 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000,
+ 176400, 192000,
] as const;
for (const sr of pcmSampleRates) {
- const outputName = `audio-${sr}hz.wav`;
- const targetPath = path.join(outDir, outputName);
- if (!(await Bun.file(targetPath).exists())) {
- console.log(`Generating ${outputName} (sine 1kHz, 10s, pcm_s16le)`);
- await $`ffmpeg -f lavfi -i ${`sine=frequency=1000:sample_rate=${sr}:duration=10`} -c:a pcm_s16le -ar ${sr} ${targetPath} -y`;
- }
- const stat = await Bun.file(targetPath).stat();
- variants.push({
- videoCodec: "none",
- audioCodec: "pcm",
- container: "wav",
- fileNames: [outputName],
- size: stat.size,
- category: "sample-rates",
- });
+ const outputName = `audio-${sr}hz.wav`;
+ const targetPath = path.join(outDir, outputName);
+ if (!(await Bun.file(targetPath).exists())) {
+ console.log(`Generating ${outputName} (sine 1kHz, 10s, pcm_s16le)`);
+ await $`ffmpeg -f lavfi -i ${`sine=frequency=1000:sample_rate=${sr}:duration=10`} -c:a pcm_s16le -ar ${sr} ${targetPath} -y`;
+ }
+ const stat = await Bun.file(targetPath).stat();
+ variants.push({
+ videoCodec: 'none',
+ audioCodec: 'pcm',
+ container: 'wav',
+ fileNames: [outputName],
+ size: stat.size,
+ category: 'sample-rates',
+ });
}
-copyFileSync("greenscreen.mp4", path.join(outDir, "greenscreen.mp4"));
+copyFileSync('greenscreen.mp4', path.join(outDir, 'greenscreen.mp4'));
+const greenscreenStat = await Bun.file(
+ path.join(outDir, 'greenscreen.mp4'),
+).stat();
variants.push({
- videoCodec: "h264",
- audioCodec: "aac",
- container: "mp4",
- fileNames: ["greenscreen.mp4"],
- size: Bun.file(path.join(outDir, "greenscreen.mp4")).size,
- category: "greenscreen",
+ videoCodec: 'h264',
+ audioCodec: 'aac',
+ container: 'mp4',
+ fileNames: ['greenscreen.mp4'],
+ size: greenscreenStat.size,
+ category: 'greenscreen',
});
copyFileSync(
- "first-frame-at-4sec.webm",
- path.join(outDir, "first-frame-at-4sec.webm")
+ 'first-frame-at-4sec.webm',
+ path.join(outDir, 'first-frame-at-4sec.webm'),
);
+const firstFrameStat = await Bun.file(
+ path.join(outDir, 'first-frame-at-4sec.webm'),
+).stat();
variants.push({
- videoCodec: "vp9",
- audioCodec: "opus",
- container: "webm",
- fileNames: ["first-frame-at-4sec.webm"],
- size: Bun.file(path.join(outDir, "first-frame-at-4sec.webm")).size,
- category: "edge-cases",
+ videoCodec: 'vp9',
+ audioCodec: 'opus',
+ container: 'webm',
+ fileNames: ['first-frame-at-4sec.webm'],
+ size: firstFrameStat.size,
+ category: 'edge-cases',
});
// Sound effects (pre-existing files, CC0 licensed)
const soundEffects = [
- {
- fileName: "whoosh.wav",
- attribution:
- "Woosh by 1bob -- https://freesound.org/s/831936/ -- License: Creative Commons 0",
- },
- {
- fileName: "whip.wav",
- attribution:
- "SWSH_Badminton Racquet_Recording_01_JW Audio by JW_Audio -- https://freesound.org/s/838766/ -- License: Creative Commons 0",
- },
- {
- fileName: "page-turn.wav",
- attribution:
- "Draw Knife 1 by kenney.nl -- https://kenney.nl -- License: Creative Commons 0",
- },
- {
- fileName: "switch.wav",
- attribution:
- "UI Audio - Switch 35 by kenney.nl -- https://kenney.nl -- License: Creative Commons 0",
- },
- {
- fileName: "mouse-click.wav",
- attribution:
- "Mouse Click Sound.mp3 by Pixeliota -- https://freesound.org/s/678248/ -- License: Creative Commons 0",
- },
- {
- fileName: "shutter-modern.wav",
- attribution:
- "DSLR Shutter fast 006.wav by ristooooo1 -- https://freesound.org/s/539136/ -- License: Creative Commons 0",
- },
- {
- fileName: "shutter-old.wav",
- attribution:
- "Werra.wav by hmilleo -- https://freesound.org/s/409093/ -- License: Creative Commons 0",
- },
- {
- fileName: "bruh.wav",
- attribution:
- "Bruh Sound Effect -- https://soundeffects.fandom.com/wiki/Bruh_Sound_Effect",
- },
- {
- fileName: "windows-xp-error.wav",
- attribution:
- "Windows XP Error -- https://www.myinstants.com/en/instant/windows-xp-error/",
- },
- {
- fileName: "vine-boom.wav",
- attribution:
- "Vine Boom Sound -- https://www.myinstants.com/en/instant/vine-boom-sound-70972/",
- },
- {
- fileName: "ding.wav",
- attribution:
- "Ding Sound Effect -- https://www.myinstants.com/en/instant/ding-sound-effect/",
- },
+ {
+ fileName: 'whoosh.wav',
+ attribution:
+ 'Woosh by 1bob -- https://freesound.org/s/831936/ -- License: Creative Commons 0',
+ },
+ {
+ fileName: 'whip.wav',
+ attribution:
+ 'SWSH_Badminton Racquet_Recording_01_JW Audio by JW_Audio -- https://freesound.org/s/838766/ -- License: Creative Commons 0',
+ },
+ {
+ fileName: 'page-turn.wav',
+ attribution:
+ 'Draw Knife 1 by kenney.nl -- https://kenney.nl -- License: Creative Commons 0',
+ },
+ {
+ fileName: 'switch.wav',
+ attribution:
+ 'UI Audio - Switch 35 by kenney.nl -- https://kenney.nl -- License: Creative Commons 0',
+ },
+ {
+ fileName: 'mouse-click.wav',
+ attribution:
+ 'Mouse Click Sound.mp3 by Pixeliota -- https://freesound.org/s/678248/ -- License: Creative Commons 0',
+ },
+ {
+ fileName: 'shutter-modern.wav',
+ attribution:
+ 'DSLR Shutter fast 006.wav by ristooooo1 -- https://freesound.org/s/539136/ -- License: Creative Commons 0',
+ },
+ {
+ fileName: 'shutter-old.wav',
+ attribution:
+ 'Werra.wav by hmilleo -- https://freesound.org/s/409093/ -- License: Creative Commons 0',
+ },
+ {
+ fileName: 'bruh.wav',
+ attribution:
+ 'Bruh Sound Effect -- https://soundeffects.fandom.com/wiki/Bruh_Sound_Effect',
+ },
+ {
+ fileName: 'windows-xp-error.wav',
+ attribution:
+ 'Windows XP Error -- https://www.myinstants.com/en/instant/windows-xp-error/',
+ },
+ {
+ fileName: 'vine-boom.wav',
+ attribution:
+ 'Vine Boom Sound -- https://www.myinstants.com/en/instant/vine-boom-sound-70972/',
+ },
+ {
+ fileName: 'ding.wav',
+ attribution:
+ 'Ding Sound Effect -- https://www.myinstants.com/en/instant/ding-sound-effect/',
+ },
];
for (const sfx of soundEffects) {
- copyFileSync(sfx.fileName, path.join(outDir, sfx.fileName));
- const stat = await Bun.file(path.join(outDir, sfx.fileName)).stat();
- variants.push({
- videoCodec: "none",
- audioCodec: "pcm",
- container: "wav",
- fileNames: [sfx.fileName],
- size: stat.size,
- category: "sound-effects",
- attribution: sfx.attribution,
- });
+ copyFileSync(sfx.fileName, path.join(outDir, sfx.fileName));
+ const stat = await Bun.file(path.join(outDir, sfx.fileName)).stat();
+ variants.push({
+ videoCodec: 'none',
+ audioCodec: 'pcm',
+ container: 'wav',
+ fileNames: [sfx.fileName],
+ size: stat.size,
+ category: 'sound-effects',
+ attribution: sfx.attribution,
+ });
}
// Generate HLS (m3u8) variants β€” H.264/AAC with both MPEG-TS and fMP4 segments
const hlsPresets = [
- { label: "ts", segmentType: "mpegts", segmentExt: "ts" },
- { label: "fmp4", segmentType: "fmp4", segmentExt: "m4s" },
+ {label: 'ts', segmentType: 'mpegts', segmentExt: 'ts'},
+ {label: 'fmp4', segmentType: 'fmp4', segmentExt: 'm4s'},
] as const;
for (const preset of hlsPresets) {
- const outputName = `hls-${preset.label}.m3u8`;
- const targetPath = path.join(outDir, outputName);
- const segmentPattern = path.join(
- outDir,
- `hls-${preset.label}-%d.${preset.segmentExt}`
- );
- const initFilename = `hls-${preset.label}-init.mp4`;
-
- if (!(await Bun.file(targetPath).exists())) {
- console.log(`Generating ${outputName}`);
- if (preset.segmentType === "fmp4") {
- await $`ffmpeg -i ${baseMute} -i tone.wav -t 10 -c:v libx264 -c:a aac -hls_time 2 -hls_playlist_type vod -hls_segment_type fmp4 -hls_fmp4_init_filename ${initFilename} -hls_segment_filename ${segmentPattern} ${targetPath} -y`;
- } else {
- await $`ffmpeg -i ${baseMute} -i tone.wav -t 10 -c:v libx264 -c:a aac -hls_time 2 -hls_playlist_type vod -hls_segment_type mpegts -hls_segment_filename ${segmentPattern} ${targetPath} -y`;
- }
- }
-
- const segmentFiles: string[] = [];
- for await (const segFile of new Bun.Glob(
- `hls-${preset.label}-*.${preset.segmentExt}`
- ).scan(outDir)) {
- segmentFiles.push(segFile);
- }
- if (
- preset.segmentType === "fmp4" &&
- (await Bun.file(path.join(outDir, initFilename)).exists())
- ) {
- segmentFiles.push(initFilename);
- }
-
- const stat = await Bun.file(targetPath).stat();
- variants.push({
- videoCodec: "h264",
- audioCodec: "aac",
- container: "m3u8",
- fileNames: [outputName, ...segmentFiles.sort()],
- size: stat.size,
- category: "hls",
- });
+ const outputName = `hls-${preset.label}.m3u8`;
+ const targetPath = path.join(outDir, outputName);
+ const segmentPattern = path.join(
+ outDir,
+ `hls-${preset.label}-%d.${preset.segmentExt}`,
+ );
+ const initFilename = `hls-${preset.label}-init.mp4`;
+
+ if (!(await Bun.file(targetPath).exists())) {
+ console.log(`Generating ${outputName}`);
+ if (preset.segmentType === 'fmp4') {
+ await $`ffmpeg -i ${baseMute} -i tone.wav -t 10 -c:v libx264 -c:a aac -hls_time 2 -hls_playlist_type vod -hls_segment_type fmp4 -hls_fmp4_init_filename ${initFilename} -hls_segment_filename ${segmentPattern} ${targetPath} -y`;
+ } else {
+ await $`ffmpeg -i ${baseMute} -i tone.wav -t 10 -c:v libx264 -c:a aac -hls_time 2 -hls_playlist_type vod -hls_segment_type mpegts -hls_segment_filename ${segmentPattern} ${targetPath} -y`;
+ }
+ }
+
+ const segmentFiles: string[] = [];
+ for await (const segFile of new Bun.Glob(
+ `hls-${preset.label}-*.${preset.segmentExt}`,
+ ).scan(outDir)) {
+ segmentFiles.push(segFile);
+ }
+ if (
+ preset.segmentType === 'fmp4' &&
+ (await Bun.file(path.join(outDir, initFilename)).exists())
+ ) {
+ segmentFiles.push(initFilename);
+ }
+
+ const stat = await Bun.file(targetPath).stat();
+ variants.push({
+ videoCodec: 'h264',
+ audioCodec: 'aac',
+ container: 'm3u8',
+ fileNames: [outputName, ...segmentFiles.sort()],
+ size: stat.size,
+ category: 'hls',
+ });
}
-await Bun.write("variants.json", JSON.stringify(variants, null, 2));
+await Bun.write('variants.json', JSON.stringify(variants, null, 2));
diff --git a/packages/remotion-media/package.json b/packages/remotion-media/package.json
index 37a7b4941a..65671899e2 100644
--- a/packages/remotion-media/package.json
+++ b/packages/remotion-media/package.json
@@ -18,10 +18,8 @@
},
"dependencies": {
"@remotion/cli": "workspace:*",
- "@remotion/media": "workspace:*",
"@remotion/paths": "workspace:*",
"@remotion/shapes": "workspace:*",
- "@remotion/studio": "workspace:*",
"bun-plugin-tailwind": "0.1.2",
"react": "catalog:",
"react-dom": "catalog:",
diff --git a/packages/remotion-media/src/App.tsx b/packages/remotion-media/src/App.tsx
index 4377852566..07204f0bc2 100644
--- a/packages/remotion-media/src/App.tsx
+++ b/packages/remotion-media/src/App.tsx
@@ -98,6 +98,7 @@ const categoryLabelMap: Record<string, string> = {
greenscreen: 'Green Screen',
'edge-cases': 'Edge Cases',
'sound-effects': 'Sound Effects',
+ hls: 'HLS',
};
const getCategoryLabel = (category: string) =>