fix(engine): skip unnecessary dimension pad (#2398)

This commit is contained in:
Miguel Ángel
2026-07-14 00:42:16 -04:00
committed by GitHub
parent 90be05019b
commit 0dfc85b680
6 changed files with 89 additions and 10 deletions
@@ -25,6 +25,18 @@ describe("withEvenDimensionPad", () => {
expect(withEvenDimensionPad("", "yuv420p")).toBe("pad=ceil(iw/2)*2:ceil(ih/2)*2");
});
it("omits the pad when known dimensions are already even", () => {
expect(withEvenDimensionPad("", "yuv420p", 1920, 1080)).toBe("");
expect(withEvenDimensionPad("scale=in_range=pc:out_range=tv", "yuv420p", 1920, 1080)).toBe(
"scale=in_range=pc:out_range=tv",
);
});
it("keeps the pad when either known dimension is odd", () => {
expect(withEvenDimensionPad("", "yuv420p", 1921, 1080)).toBe("pad=ceil(iw/2)*2:ceil(ih/2)*2");
expect(withEvenDimensionPad("", "yuv420p", 1920, 1081)).toBe("pad=ceil(iw/2)*2:ceil(ih/2)*2");
});
it("leaves the filter chain unchanged for alpha output (even in, unchanged)", () => {
const vf = "scale=in_range=pc:out_range=tv";
expect(withEvenDimensionPad(vf, "yuva444p10le")).toBe(vf);
+13 -3
View File
@@ -36,10 +36,20 @@ export function requiresEvenDimensions(pixelFormat: string): boolean {
/**
* Append the even-dimension pad to an FFmpeg `-vf` chain when the target pixel
* format requires it. Returns the chain unchanged for formats that accept odd
* dimensions, and returns just the pad when there is no existing chain.
* format requires it. When both dimensions are known and already even, omit
* the filter entirely so minimal FFmpeg builds do not need to provide `pad`.
* Returns the chain unchanged for formats that accept odd dimensions, and
* returns just the pad when there is no existing chain.
*/
export function withEvenDimensionPad(vfChain: string, pixelFormat: string): string {
export function withEvenDimensionPad(
vfChain: string,
pixelFormat: string,
width?: number,
height?: number,
): string {
if (!requiresEvenDimensions(pixelFormat)) return vfChain;
if (width !== undefined && height !== undefined && width % 2 === 0 && height % 2 === 0) {
return vfChain;
}
return vfChain ? `${vfChain},${EVEN_DIMENSION_PAD}` : EVEN_DIMENSION_PAD;
}