🎥 Make videos programmatically with React
use convertToPositiveFrameIndex
Jonny Burger908931633f76
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.tsindex 2f713b7c13..2fe02d1fba 100644--- a/packages/lambda/src/functions/still.ts+++ b/packages/lambda/src/functions/still.ts@@ -137,7 +137,10 @@ const innerStillHandler = async (serveUrl: lambdaParams.serveUrl,dumpBrowserLogs: false,envVariables: lambdaParams.envVariables,- frame: lambdaParams.frame < 0 ? composition.durationInFrames - lambdaParams.frame : lambdaParams.frame,+ frame: RenderInternals.convertToPositiveFrameIndex({+ frame: lambdaParams.frame,+ durationInFrames: composition.durationInFrames,+ }),imageFormat: lambdaParams.imageFormat as StillImageFormat,inputProps: lambdaParams.inputProps,overwrite: false,diff --git a/packages/renderer/src/convert-to-positive-frame-index.ts b/packages/renderer/src/convert-to-positive-frame-index.tsindex 4b1e27b4b0..f8a9f245e0 100644--- a/packages/renderer/src/convert-to-positive-frame-index.ts+++ b/packages/renderer/src/convert-to-positive-frame-index.ts@@ -1,7 +1,10 @@// Handle negative indices (e.g. -1 being the last frame)-export const convertToPositiveFrameIndex = (- frame: number,- durationInFrames: number-) => {+export const convertToPositiveFrameIndex = ({+ frame,+ durationInFrames,+}: {+ frame: number;+ durationInFrames: number;+}) => {return frame < 0 ? durationInFrames - frame : frame;};diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.tsindex 05a2fdd17b..1f931414eb 100644--- a/packages/renderer/src/index.ts+++ b/packages/renderer/src/index.ts@@ -5,6 +5,7 @@ import {DEFAULT_BROWSER} from './browser';import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';import {canUseParallelEncoding} from './can-use-parallel-encoding';import {DEFAULT_CODEC, validCodecs} from './codec';+import {convertToPositiveFrameIndex} from './convert-to-positive-frame-index';import {getDefaultCrfForCodec,getValidCrfRanges,@@ -165,4 +166,5 @@ export const RenderInternals = {perf,makeDownloadMap,cleanDownloadMap,+ convertToPositiveFrameIndex,};diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.tsindex ba5f0dbeba..b533c065d7 100644--- a/packages/renderer/src/render-still.ts+++ b/packages/renderer/src/render-still.ts@@ -8,10 +8,10 @@ import {cleanDownloadMap, makeDownloadMap} from './assets/download-map';import {DEFAULT_BROWSER} from './browser';import type {BrowserExecutable} from './browser-executable';import type {Browser as PuppeteerBrowser} from './browser/Browser';+import {convertToPositiveFrameIndex} from './convert-to-positive-frame-index';import {ensureOutputDirectory} from './ensure-output-directory';import {handleJavascriptException} from './error-handling/handle-javascript-exception';import type {FfmpegExecutable} from './ffmpeg-executable';-import {convertToPositiveFrameIndex} from './get-actual-still-frame';import type {StillImageFormat} from './image-format';import {validateNonNullImageFormat} from './image-format';import type {ServeUrlOrWebpackBundle} from './legacy-webpack-config';@@ -104,10 +104,10 @@ const innerRenderStill = async ({);validateNonNullImageFormat(imageFormat);validateFrame(frame, composition.durationInFrames);- const stillFrame = convertToPositiveFrameIndex(+ const stillFrame = convertToPositiveFrameIndex({+ durationInFrames: composition.durationInFrames,frame,- composition.durationInFrames- );+ });validatePuppeteerTimeout(timeoutInMilliseconds);validateScale(scale);