🎥 Make videos programmatically with React
new ui
Jonny Burgercc45431d1972
diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsxindex b5f19f5538..29b2fe29e0 100644--- a/packages/convert/app/components/FileAvailable.tsx+++ b/packages/convert/app/components/FileAvailable.tsx@@ -13,6 +13,7 @@ import {Page} from './Page';import {Probe} from './Probe';import {ReplaceVideo} from './ReplaceVideo';import type {VideoThumbnailRef} from './VideoThumbnail';+import Transcribe from './transcribe/App';import {useProbe} from './use-probe';export const FileAvailable: React.FC<{@@ -84,7 +85,8 @@ export const FileAvailable: React.FC<{}mirrorVertical={flipVertical && enableRotateOrMirrow === 'mirror'}/>- {routeAction.type !== 'generic-probe' ? (+ {routeAction.type !== 'generic-probe' &&+ routeAction.type !== 'transcribe' ? (<><div className="h-8 lg:h-0 lg:w-8" /><div@@ -123,9 +125,10 @@ export const FileAvailable: React.FC<{</div></>) : null}+ {routeAction.type === 'transcribe' ? <Transcribe /> : null}</div><div className="h-16" />- <Footer />+ <Footer routeAction={routeAction} /><ReplaceVideo setSrc={setSrc} /></div></Page>diff --git a/packages/convert/app/components/Footer.tsx b/packages/convert/app/components/Footer.tsxindex fc3dc0df46..2b8eb9edca 100644--- a/packages/convert/app/components/Footer.tsx+++ b/packages/convert/app/components/Footer.tsx@@ -1,4 +1,5 @@import React from 'react';+import type {RouteAction} from '~/seo';const Logo: React.FC = () => {return (@@ -32,7 +33,9 @@ const Logo: React.FC = () => {);};-export const Footer: React.FC = () => {+export const Footer: React.FC<{+ readonly routeAction: RouteAction;+}> = ({routeAction}) => {return (<div className="lg:flex flex-row items-center"><a@@ -56,13 +59,23 @@ export const Footer: React.FC = () => {</div></a><div className="flex-1" />- <a- target="_blank"- href="https://remotion.dev/webcodecs"- className="text-sm text-muted-foreground font-medium hover:text-foreground"- >- Powered by @remotion/webcodecs- </a>+ {routeAction.type === 'transcribe' ? (+ <a+ target="_blank"+ href="https://remotion.dev/docs/whisper-web"+ className="text-sm text-muted-foreground font-medium hover:text-foreground"+ >+ Powered by @remotion/whisper-web+ </a>+ ) : (+ <a+ target="_blank"+ href="https://remotion.dev/webcodecs"+ className="text-sm text-muted-foreground font-medium hover:text-foreground"+ >+ Powered by @remotion/webcodecs+ </a>+ )}<div className="w-6" /><atarget="_blank"diff --git a/packages/convert/app/components/get-supported-configs.tsx b/packages/convert/app/components/get-supported-configs.tsxindex 7d2f43a3a7..39aba1f45a 100644--- a/packages/convert/app/components/get-supported-configs.tsx+++ b/packages/convert/app/components/get-supported-configs.tsx@@ -76,6 +76,10 @@ const shouldPrioritizeVideoCopyOverReencode = (routeAction: RouteAction) => {return false;}+ if (routeAction.type === 'transcribe') {+ 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 fb44f05b7e..e8b7cf5d47 100644--- a/packages/convert/app/components/guess-codec-from-source.ts+++ b/packages/convert/app/components/guess-codec-from-source.ts@@ -100,6 +100,10 @@ const shouldKeepSameContainerByDefault = (action: RouteAction) => {return true;}+ if (action.type === 'transcribe') {+ return false;+ }+throw new Error(`Unhandled action type: ${action satisfies never}`);};diff --git a/packages/convert/app/components/transcribe/App.tsx b/packages/convert/app/components/transcribe/App.tsxindex 19fb0a9c43..602494a5d7 100644--- a/packages/convert/app/components/transcribe/App.tsx+++ b/packages/convert/app/components/transcribe/App.tsx@@ -1,24 +1,10 @@import type {TranscriptionJson} from '@remotion/whisper-web';import {useState} from 'react';-import MainTitle from './MainTitle';import Display from './display';import DownloadModel from './downloadModel';-import Info from './info';-import './transcribe.css';import TranscribeAudio from './transcribeAudio';-const VBarrier = () => {- return (- <div- style={{- height: 50,- borderLeft: '1px solid grey',- }}- />- );-};--const App = () => {+const Transcribe = () => {const [transcriptionCompleted, setTranscriptionCompleted] = useState(false);const [modelDownloading, setModelDownloading] = useState(false);const [result, setResult] = useState<TranscriptionJson | null>(null);@@ -26,24 +12,17 @@ const App = () => {return (<>- <MainTitle /><divstyle={{padding: 15,left: 20,borderRadius: 15,- position: 'absolute',- display: 'flex',gap: 30,alignItems: 'center',top: 20,- background: '#18191a',}}>- <Info />- <VBarrier /><DownloadModel setDownloadingModel={setModelDownloading} />- <VBarrier /><TranscribeAudio{...{setFile,@@ -59,4 +38,4 @@ const App = () => {);};-export default App;+export default Transcribe;diff --git a/packages/convert/app/components/transcribe/MainTitle.tsx b/packages/convert/app/components/transcribe/MainTitle.tsxdeleted file mode 100644index 28f07f8362..0000000000--- a/packages/convert/app/components/transcribe/MainTitle.tsx+++ /dev/null@@ -1,27 +0,0 @@-export default function MainTitle() {- return (- <div- style={{- position: 'absolute',- left: '50%',- top: '50%',- zIndex: '-1',- transform: 'translate(-50%, -50%)',- }}- >- <img- src="./logo-dark.png"- style={{- maxWidth: 200,- }}- />- <h1- style={{- margin: 0,- }}- >- Whisper Web- </h1>- </div>- );-}diff --git a/packages/convert/app/components/transcribe/downloadModel.tsx b/packages/convert/app/components/transcribe/downloadModel.tsxindex 592cc2b701..1db8410206 100644--- a/packages/convert/app/components/transcribe/downloadModel.tsx+++ b/packages/convert/app/components/transcribe/downloadModel.tsx@@ -3,6 +3,16 @@ import {type DownloadWhisperModelParams,} from '@remotion/whisper-web';import {useState} from 'react';+import {Button} from '../ui/button';+import {Label} from '../ui/label';+import {+ Select,+ SelectContent,+ SelectGroup,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from '../ui/select';export default function DownloadModel({setDownloadingModel,@@ -23,36 +33,32 @@ export default function DownloadModel({const [downloadModelProgress, setDownloadProgress] = useState<number>(0);return (- <div- style={{- display: 'flex',- gap: 20,- flexFlow: 'column',- }}- >- <div- style={{- display: 'flex',- gap: 20,- }}- >- <select- value={selectedModel}- onChange={(e) =>- setSelectedModel(- e.target.value as DownloadWhisperModelParams['model'],- )- }- >- {modelOptions.map((model) => (- <option key={model} value={model}>- {model}- </option>- ))}- </select>- <button- type="button"- style={{background: 'rgb(50, 50, 50)'}}+ <div className="flex flex-col gap-5">+ <div className="flex items-end gap-2">+ <div className="grid w-full max-w-sm items-center gap-1.5">+ <Label htmlFor="model">Whisper model</Label>+ <Select+ value={selectedModel}+ onValueChange={(v) =>+ setSelectedModel(v as DownloadWhisperModelParams['model'])+ }+ >+ <SelectTrigger id="model">+ <SelectValue placeholder="Select a model" />+ </SelectTrigger>+ <SelectContent>+ <SelectGroup>+ {modelOptions.map((model) => (+ <SelectItem key={model} value={model}>+ {model}+ </SelectItem>+ ))}+ </SelectGroup>+ </SelectContent>+ </Select>+ </div>+ <Button+ variant="secondary"onClick={() => {setDownloadingModel(true);downloadWhisperModel({@@ -61,8 +67,8 @@ export default function DownloadModel({}).then(() => setDownloadingModel(false));}}>- download model- </button>+ Download model+ </Button></div>{downloadModelProgress !== 0 && downloadModelProgress !== 1 && (<progress value={downloadModelProgress} max={1} />diff --git a/packages/convert/app/components/transcribe/info.tsx b/packages/convert/app/components/transcribe/info.tsxdeleted file mode 100644index 8f12c5de77..0000000000--- a/packages/convert/app/components/transcribe/info.tsx+++ /dev/null@@ -1,41 +0,0 @@-export default function Info() {- // returns package name with logo, and links- return (- <div- style={{- display: 'flex',- flexFlow: 'column',- gap: 10,- }}- >- <div- style={{- display: 'flex',- gap: 10,- }}- >- <img src="./mainlogo.png" style={{maxWidth: 30, alignSelf: 'center'}} />- <h2- style={{- margin: 0,- }}- >- Whisper Web- </h2>- </div>- <div- style={{- display: 'flex',- gap: 10,- }}- >- <a href="https://github.com/remotion-dev/remotion/tree/main/packages/convert">- View Source Code- </a>- <a href="https://www.remotion.dev/docs/whisper-web/">- Read Documentation- </a>- </div>- </div>- );-}diff --git a/packages/convert/app/components/transcribe/transcribe.css b/packages/convert/app/components/transcribe/transcribe.cssdeleted file mode 100644index 21ab04fc3a..0000000000--- a/packages/convert/app/components/transcribe/transcribe.css+++ /dev/null@@ -1,28 +0,0 @@-html {- background-color: rgb(36, 36, 36) !important;-}--body {- max-width: 1280px;- margin: 0 auto;- padding: 2rem;- text-align: center;- color-scheme: dark;- background-color: rgb(36, 36, 36) !important;- color: rgba(255, 255, 255, 0.87) !important;-}--button:disabled {- cursor: default !important;-}--@media (prefers-color-scheme: light) {- :root {- background-color: rgb(36, 36, 36) !important;- color: rgba(255, 255, 255, 0.87) !important;- }-}--a {- cursor: pointer;-}diff --git a/packages/convert/app/lib/default-ui.ts b/packages/convert/app/lib/default-ui.tsindex deb7fb4fc6..1fdb9a8962 100644--- a/packages/convert/app/lib/default-ui.ts+++ b/packages/convert/app/lib/default-ui.ts@@ -45,6 +45,10 @@ export const defaultRotateOrMirorState = (return null;}+ if (action.type === 'transcribe') {+ return null;+ }+throw new Error('Rotate is not enabled by default ' + (action satisfies never),);@@ -91,6 +95,10 @@ export const isConvertEnabledByDefault = (action: RouteAction) => {return true;}+ if (action.type === 'transcribe') {+ return true;+ }+throw new Error('Convert is not enabled by default ' + (action satisfies never),);@@ -149,7 +157,8 @@ export const getOrderOfSections = (if (action.type === 'generic-resize' ||action.type === 'resize-format' ||- action.type === 'report'+ action.type === 'report' ||+ action.type === 'transcribe') {return {resize: 0,diff --git a/packages/convert/app/routes/convert._index.tsx b/packages/convert/app/routes/convert._index.tsxindex 86dd40e424..27353d205b 100644--- a/packages/convert/app/routes/convert._index.tsx+++ b/packages/convert/app/routes/convert._index.tsx@@ -8,3 +8,5 @@ const action: RouteAction = {const Index = () => {return <Main routeAction={action} />;};++export default Index;diff --git a/packages/convert/app/routes/transcribe._index.tsx b/packages/convert/app/routes/transcribe._index.tsxindex 3008710bad..4eb593d66b 100644--- a/packages/convert/app/routes/transcribe._index.tsx+++ b/packages/convert/app/routes/transcribe._index.tsx@@ -1,14 +1,18 @@-import App from '~/components/transcribe/App';+import {Main} from '~/components/Main';+import type {RouteAction} from '~/seo';-const Main = () => {- return <App />;+const action: RouteAction = {+ type: 'transcribe',};-export default Main;+const Index = () => {+ return <Main routeAction={action} />;+};++export default Index;-/* comment this out for development-export const headers: HeadersFunction = ({}) => ({+import type {HeadersFunction} from '@remix-run/node';+export const headers: HeadersFunction = () => ({'Cross-Origin-Embedder-Policy': 'require-corp','Cross-Origin-Opener-Policy': 'same-origin',});-*/