🎥 Make videos programmatically with React
nice
Jonny Burger6941b53304d0
diff --git a/packages/template-react-router/app/lib/api.ts b/packages/template-react-router/app/lib/api.tsindex fa274b493f..92ef90c24a 100644--- a/packages/template-react-router/app/lib/api.ts+++ b/packages/template-react-router/app/lib/api.ts@@ -1,11 +1,11 @@import { z } from "zod";-import type { RenderMediaOnLambdaOutput } from "@remotion/lambda/client";import {CompositionProps,ProgressRequest,ProgressResponse,RenderRequest,} from "~/remotion/schemata";+import { RenderResponse } from "./types";export type ApiResponse<Res> =| {@@ -45,7 +45,7 @@ export const renderVideo = async ({inputProps,};- return makeRequest<RenderMediaOnLambdaOutput>("/api/lambda/render", body);+ return makeRequest<RenderResponse>("/api/lambda/render", body);};export const getProgress = async ({diff --git a/packages/template-react-router/app/lib/return-error-as-json.ts b/packages/template-react-router/app/lib/return-error-as-json.tsindex d4bbd7b8a5..ee8d346a0d 100644--- a/packages/template-react-router/app/lib/return-error-as-json.ts+++ b/packages/template-react-router/app/lib/return-error-as-json.ts@@ -3,7 +3,10 @@ import { ActionFunction } from "react-router";export const errorAsJson = (fn: ActionFunction): ActionFunction => {return async (...args) => {try {- return await fn(...args);+ const res = await fn(...args);+ return new Response(JSON.stringify({ type: "success", data: res }), {+ status: 200,+ });} catch (err) {return new Response(JSON.stringify({ type: "error", message: (err as Error).message }),diff --git a/packages/template-react-router/app/progress.tsx b/packages/template-react-router/app/progress.tsxindex 8b341a7a2f..731f6c9092 100644--- a/packages/template-react-router/app/progress.tsx+++ b/packages/template-react-router/app/progress.tsx@@ -2,18 +2,17 @@ import {getRenderProgress,speculateFunctionName,} from "@remotion/lambda/client";-import type { StatusResponse } from "./lib/types";import { ActionFunction } from "react-router";import { errorAsJson } from "./lib/return-error-as-json";-import { ProgressRequest } from "./remotion/schemata";+import { ProgressRequest, ProgressResponse } from "./remotion/schemata";import { DISK, RAM, REGION, TIMEOUT } from "./remotion/constants.mjs";-export const action: ActionFunction = errorAsJson(async ({ request }) => {- const body = await request.json();- const { bucketName, id } = ProgressRequest.parse(body);+export const action: ActionFunction = errorAsJson(+ async ({ request }): Promise<ProgressResponse> => {+ const body = await request.json();+ const { bucketName, id } = ProgressRequest.parse(body);- const { done, overallProgress, errors, outputFile } = await getRenderProgress(- {+ const renderProgress = await getRenderProgress({renderId: id,bucketName,functionName: speculateFunctionName({@@ -22,15 +21,25 @@ export const action: ActionFunction = errorAsJson(async ({ request }) => {timeoutInSeconds: TIMEOUT,}),region: REGION,- },- );- const status: StatusResponse = {- renderId: id,- done,- overallProgress,- errors,- outputFile,- };+ });+ if (renderProgress.fatalErrorEncountered) {+ return {+ type: "error",+ message: renderProgress.errors[0].message,+ };+ }- return status;-});+ if (renderProgress.done) {+ return {+ type: "done",+ url: renderProgress.outputFile as string,+ size: renderProgress.outputSizeInBytes as number,+ };+ }++ return {+ type: "progress",+ progress: Math.max(0.03, renderProgress.overallProgress),+ };+ },+);diff --git a/packages/template-react-router/app/remotion/components/Main.tsx b/packages/template-react-router/app/remotion/components/Main.tsxindex 97d6196d47..b268293353 100644--- a/packages/template-react-router/app/remotion/components/Main.tsx+++ b/packages/template-react-router/app/remotion/components/Main.tsx@@ -13,7 +13,11 @@ import { Rings } from "./Rings";import { TextFade } from "./TextFade";import { CompositionProps } from "../schemata";-loadFont();+const weight = "600" as const;++loadFont("normal", {+ weights: [weight],+});const container: React.CSSProperties = {backgroundColor: "white",@@ -42,7 +46,7 @@ export const Main = ({ title }: z.infer<typeof CompositionProps>) => {});const titleStyle: React.CSSProperties = useMemo(() => {- return { fontFamily, fontSize: 70 };+ return { fontFamily, fontSize: 70, fontWeight: weight };}, []);return (diff --git a/packages/template-react-router/deploy.mjs b/packages/template-react-router/deploy.mjsindex 3e33183086..7a3368ddd4 100644--- a/packages/template-react-router/deploy.mjs+++ b/packages/template-react-router/deploy.mjs@@ -67,7 +67,7 @@ const { serveUrl } = await deploySite({entryPoint: path.join(process.cwd(), "app/remotion/index.ts"),region: REGION,});-console.log(siteName);+console.log(serveUrl);console.log();console.log("You now have everything you need to render videos!");