Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Created November 9, 2020 16:49
Show Gist options
  • Save stefanpenner/ca0334f617acc02e67482947d1fcf7b0 to your computer and use it in GitHub Desktop.
Save stefanpenner/ca0334f617acc02e67482947d1fcf7b0 to your computer and use it in GitHub Desktop.
const output = {
width: 320,
height: 360,
};
const ratio = output.width / output.height;
let crop;
if (width > height) {
crop = {
width: height * ratio,
height: height,
};
} else {
crop = {
width: width,
height: width / ratio,
};
}
const face = {
top: detection.box.top,
left: detection.box.left,
height: detection.box.bottom - detection.box.top,
width: detection.box.right - detection.box.left,
};
const y = face.top - (crop.height - face.height) / 2;
const x = face.left - (crop.width - face.width) / 2;
const cropValue = `${crop.width}:${crop.height}:${x}:${y}`;
const scaleValue = `${output.width}:${output.height}`;
// send to ffmpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment