🎥 Make videos programmatically with React
upload works
Jonny Burgercae7f5e40fac
diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsxindex 2cea3de5ba..2b37e4fa5c 100644--- a/packages/convert/app/components/FileAvailable.tsx+++ b/packages/convert/app/components/FileAvailable.tsx@@ -9,6 +9,7 @@ import type {RouteAction} from '~/seo';import {BackButton} from './BackButton';import ConvertUI from './ConvertUi';import {Footer} from './Footer';+import {Page} from './Page';import {Probe} from './Probe';import {ReplaceVideo} from './ReplaceVideo';import type {VideoThumbnailRef} from './VideoThumbnail';@@ -66,65 +67,63 @@ export const FileAvailable: React.FC<{}, [enableRotateOrMirrow, userRotation]);return (- <div>- <div className="overflow-y-auto w-full lg:flex lg:justify-center pt-6 pb-10 px-4 bg-slate-50 min-h-[100vh]">- <div>- <BackButton setSrc={setSrc} />- <div className="h-4" />- <div className="lg:inline-flex lg:flex-row items-start">- <Probe- src={src}- probeDetails={probeDetails}- setProbeDetails={setProbeDetails}- probeResult={probeResult}- videoThumbnailRef={videoThumbnailRef}- userRotation={actualUserRotation}- mirrorHorizontal={- flipHorizontal && enableRotateOrMirrow === 'mirror'- }- mirrorVertical={flipVertical && enableRotateOrMirrow === 'mirror'}- />- {routeAction.type !== 'generic-probe' ? (- <>- <div className="h-8 lg:h-0 lg:w-8" />- <div- data-disabled={!(probeResult.done && !probeResult.error)}- className="w-full lg:w-[350px] data-[disabled=true]:opacity-50 data-[disabled=true]:pointer-events-none"- >- <div className="gap-4">- <ConvertUI- inputContainer={probeResult.container}- currentAudioCodec={probeResult.audioCodec ?? null}- currentVideoCodec={probeResult.videoCodec ?? null}- src={src}- tracks={probeResult.tracks}- setSrc={setSrc}- unrotatedDimensions={probeResult.unrotatedDimensions}- dimensions={probeResult.dimensions}- duration={probeResult.durationInSeconds ?? null}- logLevel="verbose"- action={routeAction}- enableRotateOrMirror={enableRotateOrMirrow}- setEnableRotateOrMirror={setEnableRotateOrMirror}- userRotation={actualUserRotation}- setRotation={setRotation}- flipHorizontal={flipHorizontal}- setFlipHorizontal={setFlipHorizontal}- flipVertical={flipVertical}- setFlipVertical={setFlipVertical}- videoThumbnailRef={videoThumbnailRef}- rotation={probeResult.rotation}- />- </div>+ <Page className="lg:justify-center pt-6 pb-10 px-4 lg:flex">+ <div>+ <BackButton setSrc={setSrc} />+ <div className="h-4" />+ <div className="lg:inline-flex lg:flex-row items-start">+ <Probe+ src={src}+ probeDetails={probeDetails}+ setProbeDetails={setProbeDetails}+ probeResult={probeResult}+ videoThumbnailRef={videoThumbnailRef}+ userRotation={actualUserRotation}+ mirrorHorizontal={+ flipHorizontal && enableRotateOrMirrow === 'mirror'+ }+ mirrorVertical={flipVertical && enableRotateOrMirrow === 'mirror'}+ />+ {routeAction.type !== 'generic-probe' ? (+ <>+ <div className="h-8 lg:h-0 lg:w-8" />+ <div+ data-disabled={!(probeResult.done && !probeResult.error)}+ className="w-full lg:w-[350px] data-[disabled=true]:opacity-50 data-[disabled=true]:pointer-events-none"+ >+ <div className="gap-4">+ <ConvertUI+ inputContainer={probeResult.container}+ currentAudioCodec={probeResult.audioCodec ?? null}+ currentVideoCodec={probeResult.videoCodec ?? null}+ src={src}+ tracks={probeResult.tracks}+ setSrc={setSrc}+ unrotatedDimensions={probeResult.unrotatedDimensions}+ dimensions={probeResult.dimensions}+ duration={probeResult.durationInSeconds ?? null}+ logLevel="verbose"+ action={routeAction}+ enableRotateOrMirror={enableRotateOrMirrow}+ setEnableRotateOrMirror={setEnableRotateOrMirror}+ userRotation={actualUserRotation}+ setRotation={setRotation}+ flipHorizontal={flipHorizontal}+ setFlipHorizontal={setFlipHorizontal}+ flipVertical={flipVertical}+ setFlipVertical={setFlipVertical}+ videoThumbnailRef={videoThumbnailRef}+ rotation={probeResult.rotation}+ /></div>- </>- ) : null}- </div>- <div className="h-16" />- <Footer />- <ReplaceVideo setSrc={setSrc} />+ </div>+ </>+ ) : null}</div>+ <div className="h-16" />+ <Footer />+ <ReplaceVideo setSrc={setSrc} /></div>- </div>+ </Page>);};diff --git a/packages/convert/app/components/Page.tsx b/packages/convert/app/components/Page.tsxnew file mode 100644index 0000000000..0e3a98a124--- /dev/null+++ b/packages/convert/app/components/Page.tsx@@ -0,0 +1,18 @@+import clsx from 'clsx';+import React from 'react';++export const Page: React.FC<{+ readonly children: React.ReactNode;+ readonly className?: string;+}> = ({children, className}) => {+ return (+ <div+ className={clsx(+ 'overflow-y-auto w-full bg-slate-50 min-h-[100vh]',+ className,+ )}+ >+ {children}+ </div>+ );+};diff --git a/packages/convert/app/components/ui/radio.tsx b/packages/convert/app/components/ui/radio.tsxnew file mode 100644index 0000000000..929f9c4193--- /dev/null+++ b/packages/convert/app/components/ui/radio.tsx@@ -0,0 +1,44 @@+'use client';++import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';+import {Circle} from 'lucide-react';+import * as React from 'react';++import {cn} from '@/lib/utils';++const RadioGroup = React.forwardRef<+ React.ElementRef<typeof RadioGroupPrimitive.Root>,+ React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>+>(({className, ...props}, ref) => {+ return (+ <RadioGroupPrimitive.Root+ className={cn('grid gap-2', className)}+ {...props}+ ref={ref}+ />+ );+});+RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;++const RadioGroupItem = React.forwardRef<+ React.ElementRef<typeof RadioGroupPrimitive.Item>,+ React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>+>(({className, ...props}, ref) => {+ return (+ <RadioGroupPrimitive.Item+ ref={ref}+ className={cn(+ 'aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',+ className,+ )}+ {...props}+ >+ <RadioGroupPrimitive.Indicator className="flex items-center justify-center">+ <Circle className="h-2.5 w-2.5 fill-current text-current" />+ </RadioGroupPrimitive.Indicator>+ </RadioGroupPrimitive.Item>+ );+});+RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;++export {RadioGroup, RadioGroupItem};diff --git a/packages/convert/app/components/ui/textarea.tsx b/packages/convert/app/components/ui/textarea.tsxnew file mode 100644index 0000000000..177ca79006--- /dev/null+++ b/packages/convert/app/components/ui/textarea.tsx@@ -0,0 +1,22 @@+import * as React from 'react';++import {cn} from '@/lib/utils';++const Textarea = React.forwardRef<+ HTMLTextAreaElement,+ React.ComponentProps<'textarea'>+>(({className, ...props}, ref) => {+ return (+ <textarea+ ref={ref}+ className={cn(+ 'flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',+ className,+ )}+ {...props}+ />+ );+});+Textarea.displayName = 'Textarea';++export {Textarea};diff --git a/packages/convert/app/lib/upload-report.ts b/packages/convert/app/lib/upload-report.tsindex 4aa31f8e56..ec7c02971d 100644--- a/packages/convert/app/lib/upload-report.ts+++ b/packages/convert/app/lib/upload-report.ts@@ -1,3 +1,5 @@+import {uploadWithProgress} from './upload-with-progress';+export const handleDrop = async (file: File) => {const presignedResponse = await fetch('https://www.remotion.pro/api/upload', {method: 'POST',@@ -10,5 +12,13 @@ export const handleDrop = async (file: File) => {},});const json = await presignedResponse.json();- console.log(json);+ const {presignedUrl, readUrl} = json;++ await uploadWithProgress({+ file,+ url: presignedUrl,+ onProgress: (uploadProgress) => {+ console.log(uploadProgress);+ },+ });};diff --git a/packages/convert/app/lib/upload-with-progress.ts b/packages/convert/app/lib/upload-with-progress.tsnew file mode 100644index 0000000000..434f24de62--- /dev/null+++ b/packages/convert/app/lib/upload-with-progress.ts@@ -0,0 +1,50 @@+export type UploadProgress = {+ progress: number;+ loadedBytes: number;+ totalBytes: number;+};++export type OnUploadProgress = (options: UploadProgress) => void;++export const uploadWithProgress = ({+ file,+ url,+ onProgress,+}: {+ file: File;+ url: string;+ onProgress: OnUploadProgress;+}) => {+ const xhr = new XMLHttpRequest();++ xhr.open('PUT', url);++ xhr.upload.onprogress = function (event) {+ if (event.lengthComputable) {+ onProgress({+ progress: event.loaded / event.total,+ loadedBytes: event.loaded,+ totalBytes: event.total,+ });+ }+ };++ const {resolve, reject, promise} = Promise.withResolvers<void>();++ xhr.onload = function () {+ if (xhr.status === 200) {+ resolve();+ } else {+ reject(new Error(`Upload failed with status: ${xhr.status}`));+ }+ };++ xhr.onerror = function () {+ reject(new Error('Failed to upload'));+ };++ xhr.setRequestHeader('Content-Type', file.type);+ xhr.send(file);++ return promise;+};diff --git a/packages/convert/app/routes/report._index.tsx b/packages/convert/app/routes/report._index.tsxindex 74688eceea..b2e761a62b 100644--- a/packages/convert/app/routes/report._index.tsx+++ b/packages/convert/app/routes/report._index.tsx@@ -1,4 +1,10 @@-import React, {useCallback} from 'react';+import React, {useCallback, useState} from 'react';+import {Page} from '~/components/Page';+import {Button} from '~/components/ui/button';+import {Card} from '~/components/ui/card';+import {Label} from '~/components/ui/label';+import {RadioGroup, RadioGroupItem} from '~/components/ui/radio';+import {Textarea} from '~/components/ui/textarea';import {handleDrop} from '~/lib/upload-report';const Report: React.FC = () => {@@ -13,11 +19,84 @@ const Report: React.FC = () => {await handleDrop(firstItem);}, []);+ const [file, setFile] = useState<File | null>(null);+ const [description, setDescription] = useState('');+return (- <div>- <input onDrop={onDrop} type="text" placeholder="Video URL" />- <h1>Report a video</h1>- </div>+ <Page className="flex-col">+ <div className="m-auto max-w-[800px] w-full">+ <Card className="mx-4 px-8 py-8 mt-12 pt-8">+ <h1 className="text-3xl font-brand font-black">Report a video</h1>+ <input+ onDrop={onDrop}+ type="file"+ placeholder="Video URL"+ className="mt-10"+ />+ <br />+ <h2 className="font-brand mt-5 font-bold">+ Which product has an issue with this video?+ </h2>++ <RadioGroup name="product" defaultValue="remotion" className="mt-3">+ <div className="flex items-center space-x-2">+ <RadioGroupItem checked value="remotion" id="remotion" />+ <Label htmlFor="remotion">+ Remotion - <OffthreadVideo>+ </Label>+ </div>+ <div className="flex items-center space-x-2">+ <RadioGroupItem value="media-parser" id="media-parser" />+ <Label htmlFor="media-parser">@remotion/media-parser</Label>+ </div>+ <div className="flex items-center space-x-2">+ <RadioGroupItem value="webcodecs" id="webcodecs" />+ <Label htmlFor="webcodecs">+ @remotion/webcodecs or remotion.dev/convert+ </Label>+ </div>+ </RadioGroup>++ <h2 className="font-brand mt-5 font-bold">Describe the issue:</h2>+ <Textarea+ name="description"+ className="mt-3"+ placeholder="Conversion fails on Chrome"+ value={description}+ onChange={(e) => setDescription(e.target.value)}+ />+ <h2 className="font-brand mt-5 font-bold">+ May we add this video to the testset?{' '}+ </h2>+ <p className="text-muted-foreground text-sm">+ This allows us to write tests for this video and avoid regressions.+ The testset is public on GitHub.+ </p>+ <RadioGroup id="usage" defaultValue="public-testset" className="mt-3">+ <div className="flex items-center space-x-2">+ <RadioGroupItem value="public-testset" id="public-testset" />+ <Label htmlFor="public-testset">+ Yes, you may commit it to the public testset+ </Label>+ </div>+ <div className="flex items-center space-x-2">+ <RadioGroupItem value="internally" id="internally" />+ <Label htmlFor="internally">+ Only internal testing - don{"'"}t commit to the public testset+ </Label>+ </div>+ <div className="flex items-center space-x-2">+ <RadioGroupItem value="confidential" id="confidential" />+ <Label htmlFor="confidential">+ Confidential - delete the video after testing+ </Label>+ </div>+ </RadioGroup>+ <div className="h-8" />+ <Button type="submit">Submit</Button>+ </Card>+ </div>+ </Page>);};diff --git a/packages/convert/package.json b/packages/convert/package.jsonindex 31f419c7c0..9d05854773 100644--- a/packages/convert/package.json+++ b/packages/convert/package.json@@ -17,6 +17,7 @@"@radix-ui/react-label": "^2.1.0","@radix-ui/react-scroll-area": "^1.1.0","@radix-ui/react-select": "^2.1.1",+ "@radix-ui/react-radio-group": "^1.2.2","@radix-ui/react-separator": "^1.1.0","@radix-ui/react-slot": "^1.1.0","@radix-ui/react-dialog": "^1.1.0",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex c119149801..8d5533c137 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -382,6 +382,9 @@ importers:'@radix-ui/react-label':specifier: ^2.1.0version: 2.1.0(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@radix-ui/react-radio-group':+ specifier: ^1.2.2+ version: 1.2.2(@types/[email protected])(@types/[email protected])([email protected])([email protected])'@radix-ui/react-scroll-area':specifier: ^1.1.0version: 1.1.0(@types/[email protected])(@types/[email protected])([email protected])([email protected])@@ -12123,6 +12126,29 @@ packages:react-dom: 19.0.0([email protected])dev: false+ /@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected])([email protected]):+ resolution: {integrity: sha512-LwT3pSho9Dljg+wY2KN2mrrh6y3qELfftINERIzBUO9e0N+t0oMTyn3k9iv+ZqgrwGkRnLpNJrsMv9BZlt2yuA==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+ dependencies:+ '@radix-ui/react-compose-refs': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@radix-ui/react-slot': 1.1.1(@types/[email protected])([email protected])+ '@types/react': 19.0.0+ '@types/react-dom': 19.0.0+ react: 19.0.0+ react-dom: 19.0.0([email protected])+ dev: false+resolution: {integrity: sha512-b4inOtiaOnYf9KWyO3jAeeCG6FeyfY6ldiEPanbUjWd+xIk5wZeHa8yVwmrJ2vderhu/BQvzCrJI0lHd+wIiqw==}peerDependencies:@@ -12547,6 +12573,63 @@ packages:react-dom: 19.0.0([email protected])dev: false+ /@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected])([email protected]):+ resolution: {integrity: sha512-E0MLLGfOP0l8P/NxgVzfXJ8w3Ch8cdO6UDzJfDChu4EJDy+/WdO5LqpdY8PYnCErkmZH3gZhDL1K7kQ41fAHuQ==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+ dependencies:+ '@radix-ui/primitive': 1.1.1+ '@radix-ui/react-compose-refs': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-direction': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-presence': 1.1.2(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@radix-ui/react-roving-focus': 1.1.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@radix-ui/react-use-controllable-state': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-previous': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-size': 1.1.0(@types/[email protected])([email protected])+ '@types/react': 19.0.0+ '@types/react-dom': 19.0.0+ react: 19.0.0+ react-dom: 19.0.0([email protected])+ dev: false++ /@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected])([email protected]):+ resolution: {integrity: sha512-QE1RoxPGJ/Nm8Qmk0PxP8ojmoaS67i0s7hVssS7KuI2FQoc/uzVlZsqKfQvxPE6D8hICCPHJ4D88zNhT3OOmkw==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+ dependencies:+ '@radix-ui/primitive': 1.1.1+ '@radix-ui/react-collection': 1.1.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@radix-ui/react-compose-refs': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-direction': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-id': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@radix-ui/react-use-callback-ref': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-controllable-state': 1.1.0(@types/[email protected])([email protected])+ '@types/react': 19.0.0+ '@types/react-dom': 19.0.0+ react: 19.0.0+ react-dom: 19.0.0([email protected])+ dev: false+/@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected])([email protected]):resolution: {integrity: sha512-9ArIZ9HWhsrfqS765h+GZuLoxaRHD/j0ZWOWilsCvYTpYJp8XwCqNG7Dt9Nu/TItKOdgLGkOPCodQvDc+UMwYg==}peerDependencies: