mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 10:06:21 +00:00
fix(engine): skip unnecessary dimension pad (#2398)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user