Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive codec from file extension for remotion lambda #1357

Merged
merged 21 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/cli/src/get-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const getFinalCodec = async (options: {isLambda: boolean}) => {

const codec = getFinalOutputCodec({
codec: userCodec,
fileExtension: options.isLambda
? null
: RenderInternals.getExtensionOfFilename(getUserPassedOutputLocation()),
fileExtension: RenderInternals.getExtensionOfFilename(
getUserPassedOutputLocation()
),
emitWarning: true,
});
const ffmpegExecutable = ConfigInternals.getCustomFfmpegExecutable();
Expand Down
8 changes: 8 additions & 0 deletions packages/lambda/src/api/render-media-on-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
PixelFormat,
ProResProfile,
} from '@remotion/renderer';
import {RenderInternals, validateOutputFilename} from '@remotion/renderer';
import {VERSION} from 'remotion/version';
import type {AwsRegion} from '../pricing/aws-regions';
import {callLambda} from '../shared/call-lambda';
Expand Down Expand Up @@ -111,6 +112,13 @@ export const renderMediaOnLambda = async ({
durationInFrames: 1,
});
validateDownloadBehavior(downloadBehavior);
if (outName === undefined || typeof outName === 'string') {
validateOutputFilename(
codec,
RenderInternals.getExtensionOfFilename(outName ?? null)
);
}

JonnyBurger marked this conversation as resolved.
Show resolved Hide resolved
const realServeUrl = await convertToServeUrl(serveUrl, region);
try {
const res = await callLambda({
Expand Down
36 changes: 35 additions & 1 deletion packages/lambda/src/cli/commands/still.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const stillCommand = async (args: string[]) => {
const {
chromiumOptions,
envVariables,
imageFormat,
imageFormat: cliImageFormat,
inputProps,
logLevel,
puppeteerTimeout,
Expand All @@ -69,6 +69,40 @@ export const stillCommand = async (args: string[]) => {
const privacy = parsedLambdaCli.privacy ?? DEFAULT_OUTPUT_PRIVACY;
validatePrivacy(privacy);

let imageFormat = cliImageFormat;

if (outName) {
if (cliImageFormat === 'none') {
if (outName?.endsWith('.jpeg') || outName?.endsWith('.jpg')) {
Log.verbose(
'Output file has a JPEG extension, setting the image format to JPEG.'
);
imageFormat = 'jpeg';
}

if (outName?.endsWith('.png')) {
Log.verbose(
'Output file has a PNG extension, setting the image format to PNG.'
);
imageFormat = 'png';
}
}

if (imageFormat === 'png' && outName.endsWith('.png')) {
Log.warn(`Rendering a PNG, expected a .png extension but got ${outName}`);
}

if (
imageFormat === 'jpeg' &&
!outName.endsWith('.jpg') &&
!outName.endsWith('.jpeg')
) {
Log.warn(
`Rendering a JPEG, expected a .jpg or .jpeg extension but got ${outName}`
);
JonnyBurger marked this conversation as resolved.
Show resolved Hide resolved
}
}

try {
const res = await renderStillOnLambda({
functionName,
Expand Down
1 change: 1 addition & 0 deletions packages/renderer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export {StitcherOptions, stitchFramesToVideo} from './stitch-frames-to-video';
export {SymbolicatedStackFrame} from './symbolicate-stacktrace';
export {OnStartData, RenderFramesOutput} from './types';
export {OpenGlRenderer} from './validate-opengl-renderer';
export {validateOutputFilename} from './validate-output-filename';
export const RenderInternals = {
ensureLocalBrowser,
ffmpegHasFeature,
Expand Down