Skip to content

🎥 Make videos programmatically with React

nice

Jonny Burger27f287fe76a9
diff --git a/packages/convert/app/components/ConvertAdvancedSettings.tsx b/packages/convert/app/components/ConvertAdvancedSettings.tsx
new file mode 100644
index 0000000000..503a6f09e7
--- /dev/null
+++ b/packages/convert/app/components/ConvertAdvancedSettings.tsx
@@ -0,0 +1,56 @@
+import {Checkbox} from './ui/checkbox';
+
+export const ConvertAdvancedSettings: React.FC<{
+ canPixelManipulate: boolean;
+ flipHorizontal: boolean;
+ flipVertical: boolean;
+ setFlipVertical: React.Dispatch<React.SetStateAction<boolean>>;
+ setFlipHorizontal: React.Dispatch<React.SetStateAction<boolean>>;
+}> = ({
+ canPixelManipulate,
+ flipHorizontal,
+ setFlipHorizontal,
+ flipVertical,
+ setFlipVertical,
+}) => {
+ return (
+ <>
+ {canPixelManipulate ? (
+ <>
+ <div className="flex flex-row">
+ <Checkbox
+ checked={flipHorizontal}
+ id="flipHorizontal"
+ onCheckedChange={() => setFlipHorizontal((e) => !e)}
+ />
+ <div className="w-2" />
+ <div className="grid gap-1.5 leading-none">
+ <label
+ htmlFor="flipHorizontal"
+ className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
+ >
+ Flip video horizontally
+ </label>
+ </div>
+ </div>
+ <div className="flex flex-row">
+ <Checkbox
+ checked={flipVertical}
+ id="flipVertical"
+ onCheckedChange={() => setFlipVertical((e) => !e)}
+ />
+ <div className="w-2" />
+ <div className="grid gap-1.5 leading-none">
+ <label
+ htmlFor="flipVertical"
+ className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
+ >
+ Flip video vertically
+ </label>
+ </div>
+ </div>
+ </>
+ ) : null}
+ </>
+ );
+};
diff --git a/packages/convert/app/components/ConvertForm.tsx b/packages/convert/app/components/ConvertForm.tsx
index 8b5d22c857..47ae2d56f3 100644
--- a/packages/convert/app/components/ConvertForm.tsx
+++ b/packages/convert/app/components/ConvertForm.tsx
@@ -7,13 +7,11 @@ import {
getAvailableContainers,
} from '@remotion/webcodecs';
import React from 'react';
-import {isReencoding} from '~/lib/is-reencoding';
import {renderHumanReadableContainer} from '~/lib/render-codec-label';
import {AudioCodecSelection} from './AudioCodecSelection';
import {SupportedConfigs} from './get-supported-configs';
import {SelectionSkeleton} from './SelectionSkeleton';
import {AudioTrackLabel, VideoTrackLabel} from './TrackSelectionLabels';
-import {Checkbox} from './ui/checkbox';
import {Label} from './ui/label';
import {
Select,
@@ -30,10 +28,6 @@ export const ConvertForm: React.FC<{
readonly setContainer: React.Dispatch<
React.SetStateAction<ConvertMediaContainer>
>;
- readonly flipHorizontal: boolean;
- readonly setFlipHorizontal: React.Dispatch<React.SetStateAction<boolean>>;
- readonly flipVertical: boolean;
- readonly setFlipVertical: React.Dispatch<React.SetStateAction<boolean>>;
readonly supportedConfigs: SupportedConfigs | null;
readonly videoConfigIndex: Record<number, number>;
readonly audioConfigIndex: Record<number, number>;
@@ -44,10 +38,6 @@ export const ConvertForm: React.FC<{
}> = ({
container,
setContainer,
- flipHorizontal,
- flipVertical,
- setFlipHorizontal,
- setFlipVertical,
supportedConfigs,
audioConfigIndex,
setAudioConfigIndex,
@@ -56,11 +46,6 @@ export const ConvertForm: React.FC<{
currentAudioCodec,
currentVideoCodec,
}) => {
- const [showAdvanced, setShowAdvanced] = React.useState(false);
-
- const canPixelManipulate =
- supportedConfigs && isReencoding({supportedConfigs, videoConfigIndex});
-
return (
<div className="gap-4 grid">
<div>
@@ -129,52 +114,6 @@ export const ConvertForm: React.FC<{
) : (
<SelectionSkeleton />
)}
- {canPixelManipulate && showAdvanced ? (
- <>
- <div className="flex flex-row">
- <Checkbox
- checked={flipHorizontal}
- id="flipHorizontal"
- onCheckedChange={() => setFlipHorizontal((e) => !e)}
- />
- <div className="w-2" />
- <div className="grid gap-1.5 leading-none">
- <label
- htmlFor="flipHorizontal"
- className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
- >
- Flip video horizontally
- </label>
- </div>
- </div>
- <div className="flex flex-row">
- <Checkbox
- checked={flipVertical}
- id="flipVertical"
- onCheckedChange={() => setFlipVertical((e) => !e)}
- />
- <div className="w-2" />
- <div className="grid gap-1.5 leading-none">
- <label
- htmlFor="flipVertical"
- className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
- >
- Flip video vertically
- </label>
- </div>
- </div>
- </>
- ) : canPixelManipulate ? (
- <div className="flex flex-row justify-center text-muted-foreground">
- <button
- type="button"
- className="font-brand"
- onClick={() => setShowAdvanced(true)}
- >
- Advanced settings
- </button>
- </div>
- ) : null}
</div>
);
};
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index e4924ba738..92b47246d1 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -1,5 +1,4 @@
import {Button} from '@/components/ui/button';
-import {CardTitle} from '@/components/ui/card';
import {
MediaParserAudioCodec,
MediaParserInternals,
@@ -13,12 +12,14 @@ import {useCallback, useEffect, useRef, useState} from 'react';
import {ConvertState, Source} from '~/lib/convert-state';
import {isDroppingEverything, isReencoding} from '~/lib/is-reencoding';
import {ConversionDone} from './ConversionDone';
+import {ConvertAdvancedSettings} from './ConvertAdvancedSettings';
import {ConvertForm} from './ConvertForm';
import {ConvertProgress, convertProgressRef} from './ConvertProgress';
+import {ConvertUiSection} from './ConvertUiSection';
import {ErrorState} from './ErrorState';
import {flipVideoFrame} from './flip-video';
import {getDefaultContainerForConversion} from './guess-codec-from-source';
-import {Badge} from './ui/badge';
+import {RotateComponents} from './RotateComponents';
import {useSupportedConfigs} from './use-supported-configs';
export default function ConvertUI({
@@ -45,10 +46,14 @@ export default function ConvertUI({
const [audioConfigIndex, _setAudioConfigIndex] = useState<
Record<number, number>
>({});
+ const [showAdvanced, setShowAdvanced] = useState(false);
const [state, setState] = useState<ConvertState>({type: 'idle'});
const [name, setName] = useState<string | null>(null);
const [flipHorizontal, setFlipHorizontal] = useState(false);
const [flipVertical, setFlipVertical] = useState(false);
+ const [enableConvert, setEnableConvert] = useState(true);
+ const [enableRotate, setEnableRotate] = useState(false);
+ const [enableMirror, setEnableMirror] = useState(false);
const supportedConfigs = useSupportedConfigs({container, tracks});
@@ -266,34 +271,54 @@ export default function ConvertUI({
videoConfigIndex,
});
+ const canPixelManipulate =
+ (supportedConfigs && isReencoding({supportedConfigs, videoConfigIndex})) ??
+ false;
+
return (
<>
<div className="w-full items-center">
- <div className="flex flex-row">
- <CardTitle>Convert video</CardTitle>
- <div className="w-2" />
- <Badge variant="default">Alpha</Badge>
- </div>
- <div className="h-6" />
- <ConvertForm
- {...{
- container,
- setContainer,
- flipHorizontal,
- flipVertical,
- setFlipHorizontal,
- setFlipVertical,
- supportedConfigs,
- audioConfigIndex,
- videoConfigIndex,
- setAudioConfigIndex,
- setVideoConfigIndex,
- currentAudioCodec,
- currentVideoCodec,
- }}
- />
+ <ConvertUiSection active={enableConvert} setActive={setEnableConvert}>
+ Convert
+ </ConvertUiSection>
+ {enableConvert ? (
+ <>
+ <div className="h-2" />
+ <ConvertForm
+ {...{
+ container,
+ setContainer,
+ flipHorizontal,
+ flipVertical,
+ setFlipHorizontal,
+ setFlipVertical,
+ supportedConfigs,
+ audioConfigIndex,
+ videoConfigIndex,
+ setAudioConfigIndex,
+ setVideoConfigIndex,
+ currentAudioCodec,
+ currentVideoCodec,
+ }}
+ />
+ </>
+ ) : null}
</div>
<div className="h-4" />
+ <ConvertUiSection active={enableRotate} setActive={setEnableRotate}>
+ Rotate
+ </ConvertUiSection>
+ <RotateComponents />
+ <ConvertUiSection active={enableMirror} setActive={setEnableMirror}>
+ Mirror
+ </ConvertUiSection>
+ <ConvertAdvancedSettings
+ canPixelManipulate={canPixelManipulate}
+ flipHorizontal={flipHorizontal}
+ flipVertical={flipVertical}
+ setFlipHorizontal={setFlipHorizontal}
+ setFlipVertical={setFlipVertical}
+ />
<Button
className="block w-full font-brand"
type="button"
diff --git a/packages/convert/app/components/ConvertUiSection.tsx b/packages/convert/app/components/ConvertUiSection.tsx
new file mode 100644
index 0000000000..04745b986e
--- /dev/null
+++ b/packages/convert/app/components/ConvertUiSection.tsx
@@ -0,0 +1,39 @@
+import React, {useCallback} from 'react';
+
+const Switch: React.FC<{
+ readonly active: boolean;
+ readonly onToggle: () => void;
+}> = ({active, onToggle}) => {
+ return (
+ <div
+ data-active={active}
+ className="h-6 transition-all rounded-full w-12 border-2 bg-gray-200 p-[2px] cursor-pointer data-[active=true]:bg-brand border-black relative"
+ onClick={onToggle}
+ >
+ <div
+ data-active={active}
+ className="h-4 w-4 left-[2px] transition-all rounded-full bg-white border-[2px] border-black absolute data-[active=true]:left-[calc(100%-1rem-2px)]"
+ />
+ </div>
+ );
+};
+
+export const ConvertUiSection: React.FC<{
+ readonly children: React.ReactNode;
+ readonly active: boolean;
+ readonly setActive: React.Dispatch<React.SetStateAction<boolean>>;
+}> = ({children, active, setActive}) => {
+ const onToggle = useCallback(() => {
+ setActive((e) => !e);
+ }, [setActive]);
+
+ return (
+ <div className="flex flex-row items-center">
+ <Switch active={active} onToggle={onToggle} />
+ <div className="w-2" />
+ <div className="font-semibold tracking-tight text-ellipsis font-brand overflow-x-hidden text-xl">
+ {children}
+ </div>
+ </div>
+ );
+};
diff --git a/packages/convert/app/components/RotateComponents.tsx b/packages/convert/app/components/RotateComponents.tsx
new file mode 100644
index 0000000000..b6cdf3c12a
--- /dev/null
+++ b/packages/convert/app/components/RotateComponents.tsx
@@ -0,0 +1,81 @@
+import {makePie} from '@remotion/shapes';
+import React from 'react';
+
+const Rotation: React.FC<{
+ readonly progress: number;
+}> = ({progress}) => {
+ return (
+ <div className="flex-1 border-black border-2 rounded flex flex-col items-center p-2">
+ <svg
+ viewBox="0 0 100 100"
+ width={40}
+ height={40}
+ style={{
+ overflow: 'visible',
+ }}
+ >
+ <path
+ fill="transparent"
+ className="stroke-slate-200"
+ strokeWidth={6}
+ style={{
+ transformOrigin: '50% 50%',
+ transform: `rotate(${progress * 360}deg)`,
+ }}
+ d={
+ makePie({
+ progress: 1 - progress - 0.1,
+ radius: 50,
+ closePath: false,
+ counterClockwise: false,
+ }).path
+ }
+ />
+ {progress === 0 ? null : (
+ <>
+ <path
+ fill="transparent"
+ stroke="black"
+ strokeWidth={6}
+ d={
+ makePie({
+ progress,
+ radius: 50,
+ closePath: false,
+ counterClockwise: false,
+ }).path
+ }
+ />
+ <g
+ style={{
+ transformOrigin: '50% 50%',
+ transform: `rotate(${progress * 360 - 90}deg)`,
+ }}
+ >
+ <path
+ d="M 85 50 L 115 50 L 100 70 z"
+ fill="black"
+ strokeWidth={10}
+ />
+ </g>
+ </>
+ )}
+ </svg>
+ <div className="h-2" />
+ <div className="text-center font-brand font-medium">
+ {Math.round(progress * 360)}°
+ </div>
+ </div>
+ );
+};
+
+export const RotateComponents: React.FC = () => {
+ return (
+ <div className="flex flex-row gap-2 mt-3 mb-3">
+ <Rotation progress={0} />
+ <Rotation progress={0.25} />
+ <Rotation progress={0.5} />
+ <Rotation progress={0.75} />
+ </div>
+ );
+};
diff --git a/packages/convert/package.json b/packages/convert/package.json
index 138900d282..ff5772ab1e 100644
--- a/packages/convert/package.json
+++ b/packages/convert/package.json
@@ -24,6 +24,7 @@
"@remix-run/serve": "^2.11.2",
"@remotion/media-parser": "workspace:*",
"@remotion/webcodecs": "workspace:*",
+ "@remotion/shapes": "workspace:*",
"@vercel/remix": "^2.11.2",
"class-variance-authority": "^0.7.0",
"clsx": "2.1.1",
diff --git a/packages/paths/bundle.ts b/packages/paths/bundle.ts
new file mode 100644
index 0000000000..1b55b5c06d
--- /dev/null
+++ b/packages/paths/bundle.ts
@@ -0,0 +1,18 @@
+import {build} from 'bun';
+
+if (process.env.NODE_ENV !== 'production') {
+ throw new Error('This script must be run using NODE_ENV=production');
+}
+
+const output = await build({
+ entrypoints: ['src/index.ts'],
+ naming: '[name].mjs',
+ external: ['react/jsx-runtime', 'react', 'remotion', 'remotion/no-react'],
+});
+
+const [file] = output.outputs;
+const text = await file.text();
+
+await Bun.write('dist/esm/index.mjs', text);
+
+export {};
diff --git a/packages/paths/package.json b/packages/paths/package.json
index 601156cbbb..35224b1d46 100644
--- a/packages/paths/package.json
+++ b/packages/paths/package.json
@@ -6,12 +6,14 @@
"version": "4.0.232",
"description": "Utilities for working with SVG paths",
"main": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "module": "dist/esm/index.mjs",
"sideEffects": false,
"scripts": {
"formatting": "prettier src --check",
"lint": "eslint src",
"test": "bun test src",
- "make": "tsc -d"
+ "make": "tsc -d && bun --env-file=../.env.bundle bundle.ts"
},
"author": "Jonny Burger <[email protected]>",
"license": "MIT",
@@ -27,6 +29,15 @@
"@remotion/eslint-config-internal": "workspace:*",
"eslint": "9.14.0"
},
+ "exports": {
+ "./package.json": "./package.json",
+ ".": {
+ "types": "./dist/index.d.ts",
+ "module": "./dist/esm/index.mjs",
+ "import": "./dist/esm/index.mjs",
+ "require": "./dist/index.js"
+ }
+ },
"publishConfig": {
"access": "public"
},
diff --git a/packages/shapes/bundle.ts b/packages/shapes/bundle.ts
new file mode 100644
index 0000000000..4f520bdacb
--- /dev/null
+++ b/packages/shapes/bundle.ts
@@ -0,0 +1,24 @@
+import {build} from 'bun';
+
+if (process.env.NODE_ENV !== 'production') {
+ throw new Error('This script must be run using NODE_ENV=production');
+}
+
+const output = await build({
+ entrypoints: ['src/index.ts'],
+ naming: '[name].mjs',
+ external: [
+ 'react/jsx-runtime',
+ 'react',
+ 'remotion',
+ 'remotion/no-react',
+ '@remotion/paths',
+ ],
+});
+
+const [file] = output.outputs;
+const text = await file.text();
+
+await Bun.write('dist/esm/index.mjs', text);
+
+export {};
diff --git a/packages/shapes/package.json b/packages/shapes/package.json
index 152bcaa28a..2caeef8eab 100644
--- a/packages/shapes/package.json
+++ b/packages/shapes/package.json
@@ -11,13 +11,24 @@
"formatting": "prettier src --check",
"lint": "eslint src",
"test": "bun test src",
- "make": "tsc -d"
+ "make": "tsc -d && bun --env-file=../.env.bundle bundle.ts"
},
+ "types": "dist/index.d.ts",
+ "module": "dist/esm/index.mjs",
"author": "Alex Fernandez, Jonny Burger <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/remotion-dev/remotion/issues"
},
+ "exports": {
+ "./package.json": "./package.json",
+ ".": {
+ "types": "./dist/index.d.ts",
+ "module": "./dist/esm/index.mjs",
+ "import": "./dist/esm/index.mjs",
+ "require": "./dist/index.js"
+ }
+ },
"devDependencies": {
"@testing-library/react": "^13.4.0",
"react": "18.3.1",
diff --git a/packages/shapes/src/index.ts b/packages/shapes/src/index.ts
index ce14994892..b50310a014 100644
--- a/packages/shapes/src/index.ts
+++ b/packages/shapes/src/index.ts
@@ -1,4 +1,4 @@
-export {Instruction} from '@remotion/paths';
+export type {Instruction} from '@remotion/paths';
export {Circle, CircleProps} from './components/circle';
export {Ellipse, EllipseProps} from './components/ellipse';
export {Pie, PieProps} from './components/pie';
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0a49338caa..e894e205f4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -397,6 +397,9 @@ importers:
'@remotion/media-parser':
specifier: workspace:*
version: link:../media-parser
+ '@remotion/shapes':
+ specifier: workspace:*
+ version: link:../shapes
'@remotion/webcodecs':
specifier: workspace:*
version: link:../webcodecs