Skip to content

Commit

Permalink
Merge pull request #4881 from remotion-dev/round-after-scale
Browse files Browse the repository at this point in the history
`@remotion/renderer`: Be more lenient with floating point-based rounding issues when using `scale` parameter
  • Loading branch information
JonnyBurger authored Feb 12, 2025
2 parents ac12b36 + 43153a6 commit 1545ea5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/cli/src/render-flows/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ export const renderVideoFlow = async ({
codec,
scale,
wantsImageSequence: shouldOutputImageSequence,
indent,
logLevel,
});

const relativeOutputLocation = getOutputFilename({
Expand Down
2 changes: 2 additions & 0 deletions packages/renderer/src/prespawn-ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export const prespawnFfmpeg = (options: PreStitcherOptions) => {
codec,
scale: 1,
wantsImageSequence: false,
indent: options.indent,
logLevel: options.logLevel,
});
const pixelFormat = options.pixelFormat ?? DEFAULT_PIXEL_FORMAT;

Expand Down
2 changes: 2 additions & 0 deletions packages/renderer/src/render-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ const internalRenderMediaRaw = ({
scale,
width: composition.width,
wantsImageSequence: false,
indent,
logLevel,
});

const realFrameRange = getRealFrameRange(
Expand Down
2 changes: 2 additions & 0 deletions packages/renderer/src/stitch-frames-to-video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ const innerStitchFramesToVideo = async (
codec,
scale: 1,
wantsImageSequence: false,
indent,
logLevel,
});
validateSelectedCodecAndProResCombination({
codec,
Expand Down
31 changes: 29 additions & 2 deletions packages/renderer/src/validate-even-dimensions-with-codec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type {Codec} from './codec';
import type {LogLevel} from './log-level';
import {Log} from './logger';
import {truthy} from './truthy';

export const validateEvenDimensionsWithCodec = ({
Expand All @@ -7,12 +9,16 @@ export const validateEvenDimensionsWithCodec = ({
codec,
scale,
wantsImageSequence,
indent,
logLevel,
}: {
width: number;
height: number;
scale: number;
codec: Codec;
wantsImageSequence: boolean;
indent: boolean;
logLevel: LogLevel;
}) => {
if (wantsImageSequence) {
return;
Expand All @@ -27,8 +33,29 @@ export const validateEvenDimensionsWithCodec = ({
return;
}

const actualWidth = width * scale;
const actualHeight = height * scale;
let actualWidth = width * scale;
let actualHeight = height * scale;
if (
actualWidth % 1 !== 0 &&
(actualWidth % 1 < 0.005 || actualWidth % 1 > 0.005)
) {
Log.verbose(
{indent, logLevel},
`Rounding width to an even number from ${actualWidth} to ${Math.round(actualWidth)}`,
);
actualWidth = Math.round(actualWidth);
}

if (
actualHeight % 1 !== 0 &&
(actualHeight % 1 < 0.005 || actualHeight % 1 > 0.005)
) {
Log.verbose(
{indent, logLevel},
`Rounding height to an even number from ${actualHeight} to ${Math.round(actualHeight)}`,
);
actualHeight = Math.round(actualHeight);
}

const displayName = codec === 'h265' ? 'H265' : 'H264';

Expand Down

0 comments on commit 1545ea5

Please sign in to comment.