🎥 Make videos programmatically with React
awesome
Jonny Burger31502dd2f39a
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsxindex f13204d191..75c9e9343a 100644--- a/packages/convert/app/components/ConvertUi.tsx+++ b/packages/convert/app/components/ConvertUi.tsx@@ -96,7 +96,12 @@ export default function ConvertUI({.map(([section]) => section as ConvertSections);}, [action]);- const supportedConfigs = useSupportedConfigs({container, tracks, logLevel});+ const supportedConfigs = useSupportedConfigs({+ container,+ tracks,+ logLevel,+ action,+ });const setVideoConfigIndex = useCallback((trackId: number, i: number) => {_setVideoConfigIndex((prev) => ({diff --git a/packages/convert/app/components/get-supported-configs.tsx b/packages/convert/app/components/get-supported-configs.tsxindex 88fb4c7092..602abde4b9 100644--- a/packages/convert/app/components/get-supported-configs.tsx+++ b/packages/convert/app/components/get-supported-configs.tsx@@ -10,6 +10,7 @@ import {getAvailableVideoCodecs,VideoOperation,} from '@remotion/webcodecs';+import {RouteAction} from '~/seo';export type VideoTrackOption = {trackId: number;@@ -26,28 +27,56 @@ export type SupportedConfigs = {audioTrackOptions: AudioTrackOption[];};+const shouldPrioritizeVideoCopyOverReencode = (routeAction: RouteAction) => {+ if (routeAction.type === 'mirror-format') {+ return false;+ }+ if (routeAction.type === 'rotate-format') {+ return false;+ }+ if (routeAction.type === 'generic-mirror') {+ return false;+ }+ if (routeAction.type === 'generic-rotate') {+ return false;+ }+ if (routeAction.type === 'convert') {+ return true;+ }+ if (routeAction.type === 'generic-convert') {+ return true;+ }++ throw new Error('Unsupported route action' + (routeAction satisfies never));+};+export const getSupportedConfigs = async ({tracks,container,bitrate,logLevel,+ action,}: {tracks: TracksField;container: ConvertMediaContainer;bitrate: number;logLevel: LogLevel;+ action: RouteAction;}): Promise<SupportedConfigs> => {const availableVideoCodecs = getAvailableVideoCodecs({container});const videoTrackOptions: VideoTrackOption[] = [];+ const prioritizeCopyOverReencode =+ shouldPrioritizeVideoCopyOverReencode(action);+for (const track of tracks.videoTracks) {const options: VideoOperation[] = [];const canCopy = canCopyVideoTrack({inputCodec: track.codecWithoutConfig,container,});- if (canCopy) {+ if (canCopy && prioritizeCopyOverReencode) {options.push({type: 'copy',});@@ -64,6 +93,11 @@ export const getSupportedConfigs = async ({});}}+ if (canCopy && !prioritizeCopyOverReencode) {+ options.push({+ type: 'copy',+ });+ }options.push({type: 'drop',});@@ -87,6 +121,7 @@ export const getSupportedConfigs = async ({if (canCopy) {audioTrackOperations.push({type: 'copy'});}+for (const audioCodec of availableAudioCodecs) {const canReencode = await canReencodeAudioTrack({audioCodec,diff --git a/packages/convert/app/components/use-supported-configs.ts b/packages/convert/app/components/use-supported-configs.tsindex 62b913a72d..4907f9c816 100644--- a/packages/convert/app/components/use-supported-configs.ts+++ b/packages/convert/app/components/use-supported-configs.ts@@ -1,16 +1,19 @@import {LogLevel, TracksField} from '@remotion/media-parser';import {ConvertMediaContainer} from '@remotion/webcodecs';import {useEffect, useState} from 'react';+import {RouteAction} from '~/seo';import {getSupportedConfigs, SupportedConfigs} from './get-supported-configs';export const useSupportedConfigs = ({container,tracks,logLevel,+ action,}: {container: ConvertMediaContainer;tracks: TracksField | null;logLevel: LogLevel;+ action: RouteAction;}) => {const [state, setState] = useState<Record<ConvertMediaContainer, SupportedConfigs | null>@@ -26,13 +29,14 @@ export const useSupportedConfigs = ({container,bitrate: 128000,logLevel,+ action,}).then((supportedConfigs) => {setState((prev) => ({...prev,[container]: supportedConfigs,}));});- }, [container, logLevel, tracks]);+ }, [action, container, logLevel, tracks]);return state[container];};