fix(engine): a video shown at exactly half its size is extracted at half size (#7607)

This commit is contained in:
Miguel Ángel
2026-11-12 14:00:10 +00:00
committed by GitHub
parent 256675f92c
commit cc47f7ea74
2 changed files with 3 additions and 1 deletions
@@ -380,6 +380,8 @@ describe.skipIf(!HAS_FFMPEG)("frame sampling at the output frame rate", () => {
// 64x36 source: halved as often as the box allows (even sides round up); never below the box.
expect(await firstFrameSize("shown-quarter", { width: 16, height: 9 })).toBe("16,10");
expect(await firstFrameSize("shown-third", { width: 20, height: 12 })).toBe("32,18");
// Exactly half (a 4K source in a 1080p box): one halving lands on the box and still covers it.
expect(await firstFrameSize("shown-half", { width: 32, height: 18 })).toBe("32,18");
expect(await firstFrameSize("shown-near-full", { width: 40, height: 20 })).toBe("64,36");
}, 30_000);
});
@@ -325,7 +325,7 @@ function halveToCoverScaleFilter(box: { width: number; height: number }): string
const fit = `max(${Math.ceil(box.width)}/iw\\,${Math.ceil(box.height)}/ih)`;
const halvings = `floor(log(1/${fit})/log(2))`;
const side = (dim: "iw" | "ih") =>
`if(lt(${fit}\\,0.5)\\,2*ceil(${dim}/pow(2\\,${halvings})/2)\\,${dim})`;
`if(lte(${fit}\\,0.5)\\,2*ceil(${dim}/pow(2\\,${halvings})/2)\\,${dim})`;
return `scale=w=${side("iw")}:h=${side("ih")}:flags=area+accurate_rnd`;
}