🎥 Make videos programmatically with React
finish feature
Jonny Burger351ca44921e5
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsxindex 0ba365db9d..be278de1f4 100644--- a/packages/convert/app/components/ConvertUi.tsx+++ b/packages/convert/app/components/ConvertUi.tsx@@ -108,7 +108,11 @@ export default function ConvertUI({isConvertEnabledByDefault(action),);const [resizeOperation, setResizeOperation] =- useState<ResizeOperation | null>(null);+ useState<ResizeOperation | null>(() => {+ return action.type === 'resize-format' || action.type === 'generic-resize'+ ? getInitialResizeSuggestion(dimensions)+ : null;+ });const order = useMemo(() => {return Object.entries(getOrderOfSections(action))diff --git a/packages/convert/app/components/get-supported-configs.tsx b/packages/convert/app/components/get-supported-configs.tsxindex d3028f32bd..660ce9fefd 100644--- a/packages/convert/app/components/get-supported-configs.tsx+++ b/packages/convert/app/components/get-supported-configs.tsx@@ -50,6 +50,12 @@ const shouldPrioritizeVideoCopyOverReencode = (routeAction: RouteAction) => {if (routeAction.type === 'generic-probe') {return true;}+ if (routeAction.type === 'generic-resize') {+ return false;+ }+ if (routeAction.type === 'resize-format') {+ return false;+ }throw new Error('Unsupported route action' + (routeAction satisfies never));};diff --git a/packages/convert/app/components/guess-codec-from-source.ts b/packages/convert/app/components/guess-codec-from-source.tsindex 9c6c5300da..46252e9a7b 100644--- a/packages/convert/app/components/guess-codec-from-source.ts+++ b/packages/convert/app/components/guess-codec-from-source.ts@@ -59,6 +59,12 @@ const shouldKeepSameContainerByDefault = (action: RouteAction) => {if (action.type === 'generic-probe') {return false;}+ if (action.type === 'resize-format') {+ return true;+ }+ if (action.type === 'generic-resize') {+ return true;+ }throw new Error(`Unhandled action type: ${action satisfies never}`);};diff --git a/packages/convert/app/lib/default-ui.ts b/packages/convert/app/lib/default-ui.tsindex 3e86d32122..bbc150a1b5 100644--- a/packages/convert/app/lib/default-ui.ts+++ b/packages/convert/app/lib/default-ui.ts@@ -31,6 +31,12 @@ export const defaultRotateOrMirorState = (if (action.type === 'generic-mirror') {return 'mirror';}+ if (action.type === 'generic-resize') {+ return null;+ }+ if (action.type === 'resize-format') {+ return null;+ }throw new Error('Rotate is not enabled by default ' + (action satisfies never),@@ -65,6 +71,14 @@ export const isConvertEnabledByDefault = (action: RouteAction) => {return false;}+ if (action.type === 'generic-resize') {+ return false;+ }++ if (action.type === 'resize-format') {+ return false;+ }+throw new Error('Convert is not enabled by default ' + (action satisfies never),);@@ -83,7 +97,7 @@ export const getOrderOfSections = (convert: 3,};}- if (action.type === 'convert') {+ if (action.type === 'convert' || action.type === 'generic-convert') {return {convert: 0,resize: 1,@@ -99,15 +113,7 @@ export const getOrderOfSections = (mirror: 3,};}- if (action.type === 'generic-convert') {- return {- convert: 0,- resize: 1,- rotate: 2,- mirror: 3,- };- }- if (action.type === 'generic-mirror') {+ if (action.type === 'generic-mirror' || action.type === 'mirror-format') {return {mirror: 0,resize: 1,@@ -115,11 +121,11 @@ export const getOrderOfSections = (convert: 3,};}- if (action.type === 'mirror-format') {+ if (action.type === 'generic-resize' || action.type === 'resize-format') {return {- mirror: 0,- resize: 1,- rotate: 2,+ resize: 0,+ rotate: 1,+ mirror: 2,convert: 3,};}diff --git a/packages/convert/app/lib/get-initial-resize-suggestion.ts b/packages/convert/app/lib/get-initial-resize-suggestion.tsindex 73b650ee86..8e95edb187 100644--- a/packages/convert/app/lib/get-initial-resize-suggestion.ts+++ b/packages/convert/app/lib/get-initial-resize-suggestion.ts@@ -2,8 +2,14 @@ import {Dimensions} from '@remotion/media-parser';import {ResizeOperation} from '@remotion/webcodecs';export const getInitialResizeSuggestion = (- rotatedDimensions: Dimensions,+ rotatedDimensions: Dimensions | null,): ResizeOperation => {+ if (rotatedDimensions === null) {+ return {+ mode: 'scale',+ scale: 0.5,+ };+ }const smallerSide = Math.min(rotatedDimensions.width,rotatedDimensions.height,diff --git a/packages/convert/app/routes/resize.$format.tsx b/packages/convert/app/routes/resize.$format.tsxnew file mode 100644index 0000000000..6d0e0b1973--- /dev/null+++ b/packages/convert/app/routes/resize.$format.tsx@@ -0,0 +1,20 @@+import {useParams} from '@remix-run/react';+import {ConvertMediaContainer} from '@remotion/webcodecs';+import {useMemo} from 'react';+import {Main} from '~/components/Main';+import {RouteAction} from '~/seo';++const Index = () => {+ const format = useParams().format as ConvertMediaContainer;++ const routeAction: RouteAction = useMemo(() => {+ return {+ type: 'resize-format',+ format,+ };+ }, [format]);++ return <Main routeAction={routeAction} />;+};++export default Index;diff --git a/packages/convert/app/routes/resize._index.tsx b/packages/convert/app/routes/resize._index.tsxnew file mode 100644index 0000000000..d07bef1b5e--- /dev/null+++ b/packages/convert/app/routes/resize._index.tsx@@ -0,0 +1,12 @@+import {Main} from '~/components/Main';+import {RouteAction} from '~/seo';++const action: RouteAction = {+ type: 'generic-resize',+};++const Index = () => {+ return <Main routeAction={action} />;+};++export default Index;diff --git a/packages/convert/app/seo.ts b/packages/convert/app/seo.tsindex d6ba975ab4..411db6cbe3 100644--- a/packages/convert/app/seo.ts+++ b/packages/convert/app/seo.ts@@ -47,6 +47,13 @@ export type RouteAction =type: 'mirror-format';format: ParseMediaContainer | ConvertMediaContainer;}+ | {+ type: 'generic-resize';+ }+ | {+ type: 'resize-format';+ format: ParseMediaContainer | ConvertMediaContainer;+ }| {type: 'generic-probe';};@@ -80,6 +87,14 @@ export const getHeaderTitle = (routeAction: RouteAction) => {return `Fast ${renderHumanReadableContainer(routeAction.format)} mirroring in the browser`;}+ if (routeAction.type === 'generic-resize') {+ return 'Fast video resizing in the browser';+ }++ if (routeAction.type === 'resize-format') {+ return `Fast ${renderHumanReadableContainer(routeAction.format)} resizing in the browser`;+ }+throw new Error(`Invalid route action ${routeAction satisfies never}`);};@@ -112,6 +127,14 @@ export const getPageTitle = (routeAction: RouteAction) => {return `Online ${renderHumanReadableContainer(routeAction.format)} Mirrorer - Remotion Convert`;}+ if (routeAction.type === 'generic-resize') {+ return 'Online video Resizer - Remotion Convert';+ }++ if (routeAction.type === 'resize-format') {+ return `Online ${renderHumanReadableContainer(routeAction.format)} Resizer - Remotion Convert`;+ }+throw new Error(`Invalid route action ${routeAction satisfies never}`);};@@ -148,6 +171,16 @@ export const getDescription = (routeAction: RouteAction) => {)} rotator, powered by WebCodecs. No upload required, no watermarks, no limits.`;}+ if (routeAction.type === 'generic-resize') {+ return `The fastest online video resizer, powered by WebCodecs. No upload required, no watermarks, no limits.`;+ }++ if (routeAction.type === 'resize-format') {+ return `The fastest online ${renderHumanReadableContainer(+ routeAction.format,+ )} resizer, powered by WebCodecs. No upload required, no watermarks, no limits.`;+ }+throw new Error(`Invalid route action ${routeAction satisfies never}`);};@@ -180,5 +213,13 @@ export const makeSlug = (routeAction: RouteAction) => {return `/mirror`;}+ if (routeAction.type === 'generic-resize') {+ return '/resize';+ }++ if (routeAction.type === 'resize-format') {+ return `/resize/${routeAction.format}`;+ }+throw new Error(`Invalid route action ${routeAction satisfies never}`);};diff --git a/packages/docs/copy-convert.ts b/packages/docs/copy-convert.tsindex bed7fffea9..4ab2ebcda8 100644--- a/packages/docs/copy-convert.ts+++ b/packages/docs/copy-convert.ts@@ -34,6 +34,11 @@ for (const inputs of seo.inputContainers) {type: 'mirror-format',format: inputs,});++ extraPages.push({+ type: 'resize-format',+ format: inputs,+ });}const contents = path.join(dir, 'index.html');@@ -77,6 +82,10 @@ extraPages.push({type: 'generic-probe',});+extraPages.push({+ type: 'generic-resize',+});+for (const page of extraPages) {const slug = seo.makeSlug(page);const pageTitle = seo.getPageTitle(page);diff --git a/packages/docs/docs/webcodecs/resizing.mdx b/packages/docs/docs/webcodecs/resizing.mdxindex e68f812035..4dbe1a7359 100644--- a/packages/docs/docs/webcodecs/resizing.mdx+++ b/packages/docs/docs/webcodecs/resizing.mdx@@ -1,4 +1,5 @@---+image: /generated/articles-docs-webcodecs-resizing.pngid: resize-a-videotitle: Resize a videoslug: /webcodecs/resize-a-videodiff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 7352e5ac06..2faaff34d7 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -3452,6 +3452,13 @@ export const articles = [compId: 'articles-docs-webcodecs-can-reencode-video-track',crumb: '@remotion/webcodecs',},+ {+ id: 'resize-a-video',+ title: 'Resize a video',+ relativePath: 'docs/webcodecs/resizing.mdx',+ compId: 'articles-docs-webcodecs-resizing',+ crumb: '@remotion/webcodecs',+ },{id: 'can-copy-audio-track',title: 'canCopyAudioTrack()',diff --git a/packages/docs/static/generated/articles-docs-webcodecs-resizing.png b/packages/docs/static/generated/articles-docs-webcodecs-resizing.pngnew file mode 100644index 0000000000..0636fc386bBinary files /dev/null and b/packages/docs/static/generated/articles-docs-webcodecs-resizing.png differ