Skip to content

🎥 Make videos programmatically with React

awesome

Jonny Burgerc3ece77108e9
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
new file mode 100644
index 0000000000..0cb556908b
--- /dev/null
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -0,0 +1,98 @@
+import {Button} from '@/components/ui/button';
+import {CardContent, CardFooter} from '@/components/ui/card';
+import {Label} from '@/components/ui/label';
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from '@/components/ui/select';
+import {convertMedia} from '@remotion/webcodecs';
+import React, {useCallback, useState} from 'react';
+
+export const ConvertUI: React.FC<{
+ src: string;
+}> = ({src}) => {
+ const [abortController, setAbortController] = useState<AbortController>(
+ () => new AbortController(),
+ );
+
+ const onClick = useCallback(async () => {
+ const fn = await convertMedia({
+ src,
+ onVideoFrame: (frame) => {
+ console.log('frame', frame);
+ return Promise.resolve();
+ },
+ onMediaStateUpdate: (s) => {
+ console.log('update', s);
+ },
+ videoCodec: 'vp8',
+ audioCodec: 'opus',
+ to: 'webm',
+ signal: abortController.signal,
+ });
+ }, [abortController.signal, src]);
+
+ const onAbort = useCallback(() => {
+ abortController.abort();
+ }, [abortController]);
+
+ return (
+ <div className="w-[350px]">
+ <CardContent className="gap-4">
+ <div className="grid w-full items-center gap-4">
+ <div>
+ <Label htmlFor="container">Container</Label>
+ <Select>
+ <SelectTrigger id="container">
+ <SelectValue placeholder="Select a container" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectGroup>
+ <SelectItem value="webm">WebM</SelectItem>
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ </div>
+ <div>
+ <Label htmlFor="videoCodec">Video codec</Label>
+ <Select>
+ <SelectTrigger id="videoCodec">
+ <SelectValue placeholder="Select a video codec" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectGroup>
+ <SelectItem value="vp8">VP8</SelectItem>
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ </div>
+ <div>
+ <Label htmlFor="audioCodec">Audio codec</Label>
+ <Select>
+ <SelectTrigger id="audioCodec">
+ <SelectValue placeholder="Select a audio codec" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectGroup>
+ <SelectItem value="opus">Opus</SelectItem>
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ </div>
+ </div>
+ </CardContent>
+ <CardFooter className="flex justify-between">
+ <Button variant={'outline'} type="button" onClick={onAbort}>
+ Abort
+ </Button>
+ <Button type="button" onClick={onClick}>
+ Convert
+ </Button>{' '}
+ </CardFooter>
+ </div>
+ );
+};
diff --git a/packages/convert/app/components/DataTable.tsx b/packages/convert/app/components/DataTable.tsx
index 7d627cd2ba..e563f3d522 100644
--- a/packages/convert/app/components/DataTable.tsx
+++ b/packages/convert/app/components/DataTable.tsx
@@ -12,7 +12,7 @@ export const TableDemo: React.FC<{
<Table>
<TableBody>
<TableRow>
- <TableCell colSpan={3}>Format</TableCell>
+ <TableCell colSpan={3}>Container</TableCell>
<TableCell className="text-right">{container}</TableCell>
</TableRow>
<TableRow>
diff --git a/packages/convert/app/components/VideoPreview.tsx b/packages/convert/app/components/VideoPreview.tsx
index 484d0204c0..88dea0e3ba 100644
--- a/packages/convert/app/components/VideoPreview.tsx
+++ b/packages/convert/app/components/VideoPreview.tsx
@@ -16,12 +16,12 @@ export const VideoPreview: React.FC<{
<Card className="w-[350px]">
<CardHeader>
<CardTitle>bigbuckbunny.mp4</CardTitle>
- <CardDescription>Deploy your new project in one-click.</CardDescription>
+ <CardDescription>From URL</CardDescription>
</CardHeader>
<CardContent>{children}</CardContent>
<CardFooter className="flex justify-between">
- <Button variant="outline">Cancel</Button>
- <Button>Deploy</Button>
+ <div className="flex-1" />
+ <Button variant={'link'}>View info</Button>
</CardFooter>
</Card>
);
diff --git a/packages/convert/app/routes/_index.tsx b/packages/convert/app/routes/_index.tsx
index 6ac0c86a51..08347f4265 100644
--- a/packages/convert/app/routes/_index.tsx
+++ b/packages/convert/app/routes/_index.tsx
@@ -1,11 +1,10 @@
import type {MetaFunction} from '@remix-run/node';
import type {Dimensions, MediaParserVideoCodec} from '@remotion/media-parser';
import {parseMedia} from '@remotion/media-parser';
-import {convertMedia} from '@remotion/webcodecs';
import {useCallback, useEffect, useState} from 'react';
+import {ConvertUI} from '~/components/ConvertUi';
import {TableDemo} from '~/components/DataTable';
import {VideoPreview} from '~/components/VideoPreview';
-import {Button} from '~/components/ui/button';
export const meta: MetaFunction = () => {
return [
@@ -18,31 +17,6 @@ const src =
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';
const Index = () => {
- const [abortController, setAbortController] = useState<AbortController>(
- () => new AbortController(),
- );
-
- const onClick = useCallback(async () => {
- const fn = await convertMedia({
- src,
- onVideoFrame: () => {
- console.log('frame');
- return Promise.resolve();
- },
- onMediaStateUpdate: (s) => {
- console.log('update', s);
- },
- videoCodec: 'vp8',
- audioCodec: 'opus',
- to: 'webm',
- signal: abortController.signal,
- });
- }, [abortController.signal]);
-
- const onAbort = useCallback(() => {
- abortController.abort();
- }, [abortController]);
-
const [dimensions, setDimensions] = useState<Dimensions | null>(null);
const [videoCodec, setVideoCodec] = useState<MediaParserVideoCodec | null>(
null,
@@ -66,13 +40,7 @@ const Index = () => {
}, [getStart]);
return (
- <div className="font-sans p-4 flex justify-center items-center h-screen">
- <Button type="button" onClick={onClick}>
- Convert
- </Button>
- <Button type="button" onClick={onAbort}>
- Abort
- </Button>
+ <div className="font-sans p-4 flex justify-center items-center h-screen bg-slate-50 gap-16">
<VideoPreview>
<TableDemo
container="MP4"
@@ -80,6 +48,7 @@ const Index = () => {
videoCodec={videoCodec}
/>
</VideoPreview>
+ <ConvertUI src={src} />
</div>
);
};