🎥 Make videos programmatically with React
progress
Jonny Burger384b61b1e8ac
diff --git a/packages/convert/app/components/ContainerOverview.tsx b/packages/convert/app/components/ContainerOverview.tsxindex 1165153a85..8193f6b9db 100644--- a/packages/convert/app/components/ContainerOverview.tsx+++ b/packages/convert/app/components/ContainerOverview.tsx@@ -3,6 +3,7 @@ import type {Dimensions,MediaParserAudioCodec,MediaParserVideoCodec,+ MetadataEntry,ParseMediaContainer,} from '@remotion/media-parser';import React from 'react';@@ -12,8 +13,20 @@ import {renderHumanReadableAudioCodec,renderHumanReadableVideoCodec,} from '~/lib/render-codec-label';+import {renderMetadataLabel} from '~/lib/render-metadata-label';import {Skeleton} from './ui/skeleton';+const LimitedWidthLabel: React.FC<{+ readonly children: React.ReactNode;+ readonly alt: string;+}> = ({children, alt}) => {+ return (+ <div className="text-ellipsis break-words" title={alt}>+ {children}+ </div>+ );+};+export const ContainerOverview: React.FC<{readonly dimensions: Dimensions | null;readonly durationInSeconds: number | null | undefined;@@ -23,6 +36,7 @@ export const ContainerOverview: React.FC<{readonly fps: number | null | undefined;readonly container: ParseMediaContainer | null;readonly isHdr: boolean | undefined;+ readonly metadata: MetadataEntry[] | null;}> = ({container,dimensions,@@ -32,14 +46,13 @@ export const ContainerOverview: React.FC<{size,fps,isHdr,+ metadata,}) => {return (- <Table>+ <Table className="table-fixed"><TableBody><TableRow>- <TableCell className="font-brand" colSpan={3}>- Size- </TableCell>+ <TableCell className="font-brand">Size</TableCell><TableCell className="text-right">{size === null ? (<Skeleton className="h-3 w-[100px] inline-block" />@@ -49,9 +62,7 @@ export const ContainerOverview: React.FC<{</TableCell></TableRow><TableRow>- <TableCell className="font-brand" colSpan={3}>- Container- </TableCell>+ <TableCell className="font-brand">Container</TableCell><TableCell className="text-right">{container ? (<>{String(container)}</>@@ -61,9 +72,7 @@ export const ContainerOverview: React.FC<{</TableCell></TableRow><TableRow>- <TableCell className="font-brand" colSpan={3}>- Duration- </TableCell>+ <TableCell className="font-brand">Duration</TableCell><TableCell className="text-right">{durationInSeconds === undefined ? (<Skeleton className="h-3 w-[100px] inline-block" />@@ -75,9 +84,7 @@ export const ContainerOverview: React.FC<{</TableCell></TableRow><TableRow>- <TableCell className="font-brand" colSpan={3}>- Dimensions- </TableCell>+ <TableCell className="font-brand">Dimensions</TableCell><TableCell className="text-right">{dimensions === null ? (<Skeleton className="h-3 w-[100px] inline-block" />@@ -89,9 +96,7 @@ export const ContainerOverview: React.FC<{</TableCell></TableRow><TableRow>- <TableCell className="font-brand" colSpan={3}>- Frame Rate- </TableCell>+ <TableCell className="font-brand">Frame Rate</TableCell><TableCell className="text-right">{fps === undefined ? (<Skeleton className="h-3 w-[100px] inline-block" />@@ -103,9 +108,7 @@ export const ContainerOverview: React.FC<{</TableCell></TableRow><TableRow>- <TableCell className="font-brand" colSpan={3}>- Video Codec- </TableCell>+ <TableCell className="font-brand">Video Codec</TableCell><TableCell className="text-right">{videoCodec === null ? (<Skeleton className="h-3 w-[100px] inline-block" />@@ -115,9 +118,7 @@ export const ContainerOverview: React.FC<{</TableCell></TableRow><TableRow>- <TableCell className="font-brand" colSpan={3}>- Audio Codec- </TableCell>+ <TableCell className="font-brand">Audio Codec</TableCell><TableCell className="text-right">{audioCodec === undefined ? (<Skeleton className="h-3 w-[100px] inline-block" />@@ -129,9 +130,7 @@ export const ContainerOverview: React.FC<{</TableCell></TableRow><TableRow>- <TableCell className="font-brand" colSpan={3}>- HDR- </TableCell>+ <TableCell className="font-brand">HDR</TableCell><TableCell className="text-right">{isHdr === undefined ? (<Skeleton className="h-3 w-[100px] inline-block" />@@ -142,6 +141,20 @@ export const ContainerOverview: React.FC<{)}</TableCell></TableRow>+ {metadata?.map((entry) => (+ <TableRow>+ <TableCell className="font-brand">+ <LimitedWidthLabel alt={entry.key}>+ {renderMetadataLabel(entry.key)}+ </LimitedWidthLabel>+ </TableCell>+ <TableCell className="text-right">+ <LimitedWidthLabel alt={entry.key}>+ {entry.value}+ </LimitedWidthLabel>+ </TableCell>+ </TableRow>+ ))}</TableBody></Table>);diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsxindex 61e0892b97..4dbb476991 100644--- a/packages/convert/app/components/FileAvailable.tsx+++ b/packages/convert/app/components/FileAvailable.tsx@@ -17,7 +17,9 @@ export const FileAvailable: React.FC<{readonly setSrc: React.Dispatch<React.SetStateAction<Source | null>>;readonly routeAction: RouteAction;}> = ({src, setSrc, routeAction}) => {- const [probeDetails, setProbeDetails] = useState(false);+ const [probeDetails, setProbeDetails] = useState(+ () => routeAction.type === 'generic-probe',+ );const clear = useCallback(() => {setSrc(null);@@ -103,32 +105,36 @@ export const FileAvailable: React.FC<{}mirrorVertical={flipVertical && enableRotateOrMirrow === 'mirror'}/>- <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- currentAudioCodec={probeResult.audioCodec ?? null}- currentVideoCodec={probeResult.videoCodec ?? null}- src={src}- tracks={probeResult.tracks}- setSrc={setSrc}- duration={probeResult.durationInSeconds ?? null}- logLevel="verbose"- action={routeAction}- enableRotateOrMirror={enableRotateOrMirrow}- setEnableRotateOrMirror={setEnableRotateOrMirror}- userRotation={actualUserRotation}- setRotation={setRotation}- flipHorizontal={flipHorizontal}- setFlipHorizontal={setFlipHorizontal}- flipVertical={flipVertical}- setFlipVertical={setFlipVertical}- />- </div>- </div>+ {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+ currentAudioCodec={probeResult.audioCodec ?? null}+ currentVideoCodec={probeResult.videoCodec ?? null}+ src={src}+ tracks={probeResult.tracks}+ setSrc={setSrc}+ duration={probeResult.durationInSeconds ?? null}+ logLevel="verbose"+ action={routeAction}+ enableRotateOrMirror={enableRotateOrMirrow}+ setEnableRotateOrMirror={setEnableRotateOrMirror}+ userRotation={actualUserRotation}+ setRotation={setRotation}+ flipHorizontal={flipHorizontal}+ setFlipHorizontal={setFlipHorizontal}+ flipVertical={flipVertical}+ setFlipVertical={setFlipVertical}+ />+ </div>+ </div>+ </>+ ) : null}</div><div className="h-16" /><Footer />diff --git a/packages/convert/app/components/Probe.tsx b/packages/convert/app/components/Probe.tsxindex f2b2ff440e..18907ab600 100644--- a/packages/convert/app/components/Probe.tsx+++ b/packages/convert/app/components/Probe.tsx@@ -47,6 +47,7 @@ export const Probe: React.FC<{rotation,done,error,+ metadata,} = probeResult;const onClick = useCallback(() => {@@ -133,6 +134,7 @@ export const Probe: React.FC<{durationInSeconds={durationInSeconds}audioCodec={audioCodec}fps={fps}+ metadata={metadata}isHdr={isHdr}/>) : selectedTrack.type === 'video' ? (diff --git a/packages/convert/app/lib/render-metadata-label.ts b/packages/convert/app/lib/render-metadata-label.tsnew file mode 100644index 0000000000..96de6f39d2--- /dev/null+++ b/packages/convert/app/lib/render-metadata-label.ts@@ -0,0 +1,7 @@+export const renderMetadataLabel = (key: string) => {+ if (key === 'com.apple.quicktime.location.accuracy.horizontal') {+ return 'Location Accuracy (Horizontal)';+ }++ return key;+};diff --git a/packages/convert/app/routes/probe._index.tsx b/packages/convert/app/routes/probe._index.tsxnew file mode 100644index 0000000000..a2778db652--- /dev/null+++ b/packages/convert/app/routes/probe._index.tsx@@ -0,0 +1,12 @@+import {Main} from '~/components/Main';+import {RouteAction} from '~/seo';++const action: RouteAction = {+ type: 'generic-probe',+};++const Index = () => {+ return <Main routeAction={action} />;+};++export default Index;diff --git a/packages/docs/copy-convert.ts b/packages/docs/copy-convert.tsindex 7a006ce29a..9576b643f9 100644--- a/packages/docs/copy-convert.ts+++ b/packages/docs/copy-convert.ts@@ -70,6 +70,10 @@ extraPages.push({type: 'generic-mirror',});+extraPages.push({+ type: 'generic-probe',+});+for (const page of extraPages) {const slug = seo.makeSlug(page);const pageTitle = seo.getPageTitle(page);diff --git a/packages/docs/docs/media-parser/fast-and-slow.mdx b/packages/docs/docs/media-parser/fast-and-slow.mdxindex 01ff0c4217..f0faebb95d 100644--- a/packages/docs/docs/media-parser/fast-and-slow.mdx+++ b/packages/docs/docs/media-parser/fast-and-slow.mdx@@ -40,6 +40,7 @@ The following [`fields`](/docs/media-parser#fields) require only the metadata se- [`unrotatedDimensions`](/docs/media-parser/parse-media#unrotateddimensions)- [`isHdr`](/docs/media-parser/parse-media#ishdr)- [`rotation`](/docs/media-parser/parse-media#rotation)+- [`metadata`](/docs/media-parser/parse-media#metadata)Also, if an [`onVideoTrack`](/docs/media-parser/parse-media#onvideotrack) or [`onAudioTrack`](/docs/media-parser/parse-media#onvideotrack) handler is passed, only the parsing of the metadata section is required if `null` is returned from the handler function.@@ -51,6 +52,11 @@ The following [`fields`](/docs/media-parser/parse-media#fields) require only the- [`size`](/docs/media-parser/parse-media#size)- [`container`](/docs/media-parser/parse-media#container)+## Seeking required++If you load videos from a URL, make sure that they support the `Range` header.+Otherwise, `@remotion/media-parser` has no choice but to read the full file if the metadata is at the end of it.+## Example```tsx twoslash title="Reading header only"diff --git a/packages/docs/docs/media-parser/parse-media.mdx b/packages/docs/docs/media-parser/parse-media.mdxindex 3c956a2a1f..54d749e19f 100644--- a/packages/docs/docs/media-parser/parse-media.mdx+++ b/packages/docs/docs/media-parser/parse-media.mdx@@ -120,6 +120,11 @@ The audio codec of the file.If multiple audio tracks are present, this will be the first audio track.One of `'aac'`, `'mp3'`, `'aiff'`, `'opus'`, `'pcm'`, `'unknown'` (audio is there but not recognized) or `null` (in case of no audio detected).+#### `metadata`++Metadata fields such as ID3 tags or EXIF data.+See [metadata](/docs/media-parser/metadata) for more information.+#### `tracks`Returns two arrays `videoTracks` and `audioTracks`.diff --git a/packages/docs/docs/media-parser/tags.mdx b/packages/docs/docs/media-parser/tags.mdxnew file mode 100644index 0000000000..a8f8d420e5--- /dev/null+++ b/packages/docs/docs/media-parser/tags.mdx@@ -0,0 +1,106 @@+---+image: /generated/articles-docs-media-parser-tags.png+id: tags+sidebar_label: Extract ID3 tags+title: Extract ID3 tags and EXIF data+slug: /media-parser/tags+crumb: '@remotion/media-parser'+---++[`@remotion/media-parser`](/docs/media-parser) allows you to extract metadata that is embedded in video files, such as ID3 tags or EXIF data.++```tsx twoslash title="Extracting metadata"+// @module: es2022+// @target: es2017+import {parseMedia} from '@remotion/media-parser';++const {metadata} = await parseMedia({+ src: 'https://example.com/my-video.mp4',+ fields: {+ metadata: true,+ },+});++console.log(metadata);++/*+[+ {+ key: 'com.apple.quicktime.model',+ trackId: null,+ value: 'iPhone 15 Pro',+ },+ {+ key: 'encoder',+ trackId: null,+ value: 'Lavf57.19.100',+ }+]+*/+```++Some metadata refers to a certain track, such as the 'encoder' field.+In this case, the `trackId` field will contain a non-null value. You can get a list of tracks by setting the [`tracks`](/docs/media-parser/parse-media#tracks) field to `true`.++## Common metadata fields++Here is a non-exhaustive list of commonly seen metadata that you may want to parse and display.+Use the [`container`](/docs/media-parser/parse-media#container) field to get the container format of the video.++### ISO Base Media (.mp4, .mov)++| Field | Description | Example value |+| --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |+| `artist` | ID3 Artist Tag | `"Blender Foundation 2008, Janus Bager Kristensen 2013"` |+| `album` | ID3 Album Tag | `"The Resistance"` |+| `composer` | ID3 Composer Tag | `"Sacha Goedegebure"` |+| `comment` | ID3 Comment Tag | `"Made with Remotion v4.0.234"` |+| `releaseDate` | ID3 Release Date Tag | |+| `genre` | ID3 Genre Tag | `"Animation"` |+| `title` | ID3 Title Tag | `"Big Buck Bunny, Sunflower version"` |+| `writer` | ID3 Writer Tag | `"Sacha Goedegebure"` |+| `director` | ID3 Director Tag | |+| `producer` | ID3 Producer Tag | |+| `description` | ID3 Description Tag | |+| `duration` | ID3 Duration Tag | `"00:00:10.000000000"` |+| `encoder` | Software used to encode the video/stream | `"Lavf60.16.100"` |+| `copyright` | Copyright information | `"Blender Foundation"` |+| `major_brand` | The major brand of the file | `"isom"` |+| `minor_version` | The minor version of the file | `"512"` |+| `compatible_brands` | Container compatibility | `"isomav01iso2mp41"` |+| `handler_name` | Software used to mux the video | `"GPAC ISO Video Handler"` |+| `com.apple.quicktime.camera.focal_length.35mm_equivalent` | [35mm-equivalent focal length](https://en.wikipedia.org/wiki/35_mm_equivalent_focal_length) | `23` |+| `com.apple.quicktime.camera.lens_model` | Lens of Apple Device | `"iPhone 15 Pro back camera 6.765mm f/1.78"` |+| `com.apple.quicktime.creationdate` | Creation date of video | `"2024-10-01T12:46:18+0200"` |+| `com.apple.quicktime.software` | Operating System Version (e.g. iOS) of Device | `"18.0"` |+| `com.apple.quicktime.model` | Device used to capture video | `"iPhone 15 Pro"` |+| `com.apple.quicktime.make` | Maker of the device used to capture the video | `"Apple"` |+| `com.apple.quicktime.live-photo.vitality-score` | [An identifier that represents the vitality score of a Live Photo movie](https://developer.apple.com/documentation/avfoundation/avmetadataidentifier/quicktimemetadatalivephotovitalityscore) | `1` |+| `com.apple.quicktime.live-photo.vitality-scoring-version` | [An identifier that represents the version of the algorithm responsible for scoring the Live Photo movie for vitality](https://developer.apple.com/documentation/avfoundation/avmetadataidentifier/quicktimemetadatalivephotovitalityscoringversion) | `4` |+| `com.apple.quicktime.content.identifier` | [An identifier that represents the content identifier in QuickTime](https://developer.apple.com/documentation/avfoundation/avmetadataidentifier/quicktimemetadatacontentidentifier) | `"2C1C7C94-E977-45D0-9B3F-9A9CA8EFB47D"` |+| `com.apple.quicktime.full-frame-rate-playback-intent` | [An key that represents whether this movie should play at full frame rate](https://developer.apple.com/documentation/avfoundation/avmetadatakey/quicktimemetadatakeyfullframerateplaybackintent) | `1` |+| `com.apple.quicktime.live-photo.auto` | [An identifier that represents whether the live photo movie used auto mode](https://developer.apple.com/documentation/avfoundation/avmetadataidentifier/quicktimemetadataautolivephoto?language=objc) | `1` |+| `com.apple.quicktime.location.accuracy.horizontal` | [An identifier that represents the horizontal accuracy of the location data](https://developer.apple.com/documentation/avfoundation/avmetadataidentifier/quicktimemetadatalocationhorizontalaccuracyinmeters) | `1` |++### Matroska (.mkv, .webm)++| Field | Description | Example value |+| ---------- | ------------------------------------ | ------------------------------ |+| `duration` | Duration of a video / stream | `"00:00:00.333000000"` |+| `encoder` | Software used to encode stream/Video | `"Lavc60.31.102 libx264"` |+| `comment` | Software used to encode stream/Video | `"Made with Remotion 4.0.192"` |++### RIFF (.avi)++| Field | Description | Example value |+| --------- | ------------------------------------ | ----------------- |+| `encoder` | Software used to encode stream/Video | `"Lavf57.19.100"` |++## Fields are not unique++Some fields may appear multiple times per video, such as `encoder`, `comment` or `duration`.+Oftentimes they are scoped to a certain track, which is why the `trackId` field is present in the metadata object.++## See also++- [`parseMedia()`](/docs/media-parser/parse-media)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 16a03e6437..4b23949bbf 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -564,6 +564,7 @@ module.exports = {'media-parser/web-file-reader','media-parser/webcodecs','media-parser/fast-and-slow',+ 'media-parser/tags','media-parser/support',],},diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 4dacdb6059..2515e61ff7 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1847,6 +1847,13 @@ export const articles = [compId: 'articles-docs-media-parser-support',crumb: '@remotion/media-parser',},+ {+ id: 'tags',+ title: 'Extract ID3 tags and EXIF data',+ relativePath: 'docs/media-parser/tags.mdx',+ compId: 'articles-docs-media-parser-tags',+ crumb: '@remotion/media-parser',+ },{id: 'web-file-reader',title: 'webFileReader',diff --git a/packages/docs/static/generated/articles-docs-media-parser-tags.png b/packages/docs/static/generated/articles-docs-media-parser-tags.pngnew file mode 100644index 0000000000..7e5e49fbebBinary files /dev/null and b/packages/docs/static/generated/articles-docs-media-parser-tags.png differ