Created
December 20, 2020 05:41
-
-
Save boutell/269745623772730b76353c6057bf0a79 to your computer and use it in GitHub Desktop.
Crop and overlay videos using ffmpeg, to copy and paste in space rather than time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exec = require('child_process').execSync; | |
// I got coordinates using the screenshot picker in quicktime player, | |
// but those are scaled to my screen, not the real video. Do some | |
// corrective fakery | |
const realDimensions = [ 1920, 1080 ]; | |
const fakeWidth = 1680; | |
const fakeTom = [ 1400, 0, 280, 156 ]; | |
const fakeVideo = [ 0, 100, 1470, 760 ]; | |
const realTom = scale(fakeTom); | |
const realVideo = scale(fakeVideo); | |
console.log(realTom); | |
console.log(realVideo); | |
const name = 'whats-new-in-modern-javascript-20201205'; | |
exec(`ffmpeg -i ${name}.mp4 -vf "crop=${realTom[2]}:${realTom[3]}:${realTom[0]}:${realTom[1]}" -c:v libx264 -c:a copy ${name}-tom.mp4 -y`); | |
exec(`ffmpeg -i ${name}.mp4 -vf "crop=${realVideo[2]}:${realVideo[3]}:${realVideo[0]}:${realVideo[1]}" -c:v libx264 -c:a copy ${name}-video.mp4 -y`); | |
exec(`ffmpeg -i ${name}-video.mp4 -vf "movie=${name}-tom.mp4[clip];[0][clip]overlay=main_w-overlay_w:0" ${name}-merged.mp4 -y`); | |
function scale(args) { | |
return args.map(n => Math.floor(n * realDimensions[0] / fakeWidth)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment