🎥 Make videos programmatically with React
show render output
Jonny Burger7057a18f36c5
diff --git a/packages/cli/src/editor/components/FilePreview.tsx b/packages/cli/src/editor/components/FilePreview.tsxindex 1ba26da112..65669a2e83 100644--- a/packages/cli/src/editor/components/FilePreview.tsx+++ b/packages/cli/src/editor/components/FilePreview.tsx@@ -1,5 +1,4 @@import React from 'react';-import {LIGHT_TEXT} from '../helpers/colors';import {JSONViewer} from './JSONViewer';import {Spacing} from './layout';import type {AssetFileType} from './Preview';@@ -13,58 +12,45 @@ const msgStyle: React.CSSProperties = {justifyContent: 'center',};-const errMsgStyle: React.CSSProperties = {- ...msgStyle,- color: LIGHT_TEXT,-};-export const FilePreview: React.FC<{- staticFileSrc: string;+ src: string;fileType: AssetFileType;currentAsset: string;- fileSize: string;-}> = ({fileType, staticFileSrc, currentAsset, fileSize}) => {+ fileSize: string | null;+}> = ({fileType, src, currentAsset, fileSize}) => {if (fileType === 'audio') {- try {- return (- <div>- <audio src={staticFileSrc} controls />- </div>- );- } catch (err) {- return <div style={errMsgStyle}>The audio could not be loaded</div>;- }+ return (+ <div>+ <audio src={src} controls />+ </div>+ );}if (fileType === 'video') {- try {- return <video src={staticFileSrc} controls />;- } catch (err) {- return <div style={errMsgStyle}>The video could not be loaded</div>;- }+ return <video src={src} controls />;}if (fileType === 'image') {- try {- return <img src={staticFileSrc} />;- } catch (err) {- return <div style={errMsgStyle}>The image could not be loaded</div>;- }+ return <img src={src} />;}if (fileType === 'json') {- return <JSONViewer src={staticFileSrc} />;+ return <JSONViewer src={src} />;}if (fileType === 'txt') {- return <TextViewer src={staticFileSrc} />;+ return <TextViewer src={src} />;}return (<><div style={msgStyle}>{currentAsset}</div>- <Spacing y={1} />- <div style={msgStyle}>Size: {fileSize} </div>+ {fileSize ? (+ <>+ <Spacing y={1} />+ <div style={msgStyle}>Size: {fileSize} </div>+ </>+ ) : null}</>);};diff --git a/packages/cli/src/editor/components/Preview.tsx b/packages/cli/src/editor/components/Preview.tsxindex 543bd7d113..0c4e7afdf4 100644--- a/packages/cli/src/editor/components/Preview.tsx+++ b/packages/cli/src/editor/components/Preview.tsx@@ -2,21 +2,19 @@ import type {Size} from '@remotion/player';import {PlayerInternals} from '@remotion/player';import React, {useContext, useEffect, useMemo, useRef} from 'react';import type {CanvasContent} from 'remotion';-import {getStaticFiles, Internals, staticFile} from 'remotion';-import {formatBytes} from '../../format-bytes';+import {Internals} from 'remotion';import {checkerboardBackgroundColor,checkerboardBackgroundImage,getCheckerboardBackgroundPos,getCheckerboardBackgroundSize,} from '../helpers/checkerboard-background';-import {StudioServerConnectionCtx} from '../helpers/client-id';-import {LIGHT_TEXT} from '../helpers/colors';import type {Dimensions} from '../helpers/is-current-selected-still';import {CheckerboardContext} from '../state/checkerboard';import {PreviewSizeContext} from '../state/preview-size';-import {FilePreview} from './FilePreview';+import {RenderPreview} from './RenderPreview';import {Spinner} from './Spinner';+import {StaticFilePreview} from './StaticFilePreview';const spinnerContainer: React.CSSProperties = {display: 'flex',@@ -25,19 +23,6 @@ const spinnerContainer: React.CSSProperties = {alignItems: 'center',};-const msgStyle: React.CSSProperties = {- fontSize: 13,- color: 'white',- fontFamily: 'sans-serif',- display: 'flex',- justifyContent: 'center',-};--const errMsgStyle: React.CSSProperties = {- ...msgStyle,- color: LIGHT_TEXT,-};-export type AssetFileType =| 'audio'| 'video'@@ -111,52 +96,6 @@ const containerStyle = (options: {};};-const AssetComponent: React.FC<{currentAsset: string}> = ({currentAsset}) => {- const fileType = getPreviewFileType(currentAsset);- const staticFileSrc = staticFile(currentAsset);- const staticFiles = getStaticFiles();- const connectionStatus = useContext(StudioServerConnectionCtx).type;-- const exists = staticFiles.find((file) => file.name === currentAsset);-- if (connectionStatus === 'disconnected') {- return <div style={errMsgStyle}>Studio server disconnected</div>;- }-- if (!exists) {- return (- <div style={errMsgStyle}>- {currentAsset} does not exist in your public folder.- </div>- );- }-- const fileSize = (() => {- const fileFromStaticFiles = staticFiles.find(- (file) => file.name === currentAsset,- );-- if (fileFromStaticFiles) {- return formatBytes(fileFromStaticFiles?.sizeInBytes);- }-- return '';- })();-- if (!currentAsset) {- return null;- }-- return (- <FilePreview- currentAsset={currentAsset}- fileSize={fileSize}- fileType={fileType}- staticFileSrc={staticFileSrc}- />- );-};-export const VideoPreview: React.FC<{canvasSize: Size;contentDimensions: Dimensions | 'none' | null;@@ -239,9 +178,9 @@ const CompWhenItHasDimensions: React.FC<{return (<div style={outer}>{canvasContent.type === 'asset' ? (- <AssetComponent currentAsset={canvasContent.asset} />+ <StaticFilePreview currentAsset={canvasContent.asset} />) : canvasContent.type === 'output' ? (- <div>hi there</div>+ <RenderPreview path={canvasContent.path} />) : (<PortalContainercontentDimensions={contentDimensions as Dimensions}diff --git a/packages/cli/src/editor/components/RenderPreview.tsx b/packages/cli/src/editor/components/RenderPreview.tsxnew file mode 100644index 0000000000..0e4e738492--- /dev/null+++ b/packages/cli/src/editor/components/RenderPreview.tsx@@ -0,0 +1,39 @@+import React, {useContext} from 'react';+import {StudioServerConnectionCtx} from '../helpers/client-id';+import {LIGHT_TEXT} from '../helpers/colors';+import {FilePreview} from './FilePreview';+import {getPreviewFileType} from './Preview';++const msgStyle: React.CSSProperties = {+ fontSize: 13,+ color: 'white',+ fontFamily: 'sans-serif',+ display: 'flex',+ justifyContent: 'center',+};++const errMsgStyle: React.CSSProperties = {+ ...msgStyle,+ color: LIGHT_TEXT,+};++export const RenderPreview: React.FC<{+ path: string;+}> = ({path}) => {+ const fileType = getPreviewFileType(path);+ const src = window.remotion_staticBase.replace('static', 'outputs') + path;+ const connectionStatus = useContext(StudioServerConnectionCtx).type;++ if (connectionStatus === 'disconnected') {+ return <div style={errMsgStyle}>Studio server disconnected</div>;+ }++ return (+ <FilePreview+ currentAsset={path}+ fileSize={null}+ fileType={fileType}+ src={src}+ />+ );+};diff --git a/packages/cli/src/editor/components/StaticFilePreview.tsx b/packages/cli/src/editor/components/StaticFilePreview.tsxnew file mode 100644index 0000000000..a7edeeec20--- /dev/null+++ b/packages/cli/src/editor/components/StaticFilePreview.tsx@@ -0,0 +1,68 @@+import {useContext} from 'react';+import {getStaticFiles, staticFile} from 'remotion';+import {formatBytes} from '../../format-bytes';+import {StudioServerConnectionCtx} from '../helpers/client-id';+import {LIGHT_TEXT} from '../helpers/colors';+import {FilePreview} from './FilePreview';+import {getPreviewFileType} from './Preview';++const msgStyle: React.CSSProperties = {+ fontSize: 13,+ color: 'white',+ fontFamily: 'sans-serif',+ display: 'flex',+ justifyContent: 'center',+};++const errMsgStyle: React.CSSProperties = {+ ...msgStyle,+ color: LIGHT_TEXT,+};++export const StaticFilePreview: React.FC<{currentAsset: string}> = ({+ currentAsset,+}) => {+ const fileType = getPreviewFileType(currentAsset);+ const staticFileSrc = staticFile(currentAsset);+ const staticFiles = getStaticFiles();+ const connectionStatus = useContext(StudioServerConnectionCtx).type;++ const exists = staticFiles.find((file) => file.name === currentAsset);++ if (connectionStatus === 'disconnected') {+ return <div style={errMsgStyle}>Studio server disconnected</div>;+ }++ if (!exists) {+ return (+ <div style={errMsgStyle}>+ {currentAsset} does not exist in your public folder.+ </div>+ );+ }++ const fileSize = (() => {+ const fileFromStaticFiles = staticFiles.find(+ (file) => file.name === currentAsset,+ );++ if (fileFromStaticFiles) {+ return formatBytes(fileFromStaticFiles?.sizeInBytes);+ }++ return null;+ })();++ if (!currentAsset) {+ return null;+ }++ return (+ <FilePreview+ currentAsset={currentAsset}+ fileSize={fileSize}+ fileType={fileType}+ src={staticFileSrc}+ />+ );+};