Created
January 25, 2025 00:41
-
-
Save cassidoo/2e4e71c593c3ebb527c86321547e7d08 to your computer and use it in GitHub Desktop.
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
function generateLutFilter(hexColorsToExclude) { | |
function hexToRgb(hex) { | |
const bigint = parseInt(hex, 16); | |
const r = (bigint >> 16) & 255; | |
const g = (bigint >> 8) & 255; | |
const b = bigint & 255; | |
return { r, g, b }; | |
} | |
let lutFilter = "lutrgb="; | |
let rConditions = []; | |
let gConditions = []; | |
let bConditions = []; | |
for (const hexColor of hexColorsToExclude) { | |
const { r, g, b } = hexToRgb(hexColor); | |
rConditions.push(`if(eq(val\\,${r})\\,${r}\\,`); | |
gConditions.push(`if(eq(val\\,${g})\\,${g}\\,`); | |
bConditions.push(`if(eq(val\\,${b})\\,${b}\\,`); | |
} | |
const rFilter = rConditions.length > 0 ? rConditions.join("") + "255-val" + ")".repeat(rConditions.length) : "255-val"; | |
const gFilter = gConditions.length > 0 ? gConditions.join("") + "255-val" + ")".repeat(gConditions.length) : "255-val"; | |
const bFilter = bConditions.length > 0 ? bConditions.join("") + "255-val" + ")".repeat(bConditions.length) : "255-val"; | |
lutFilter += `r='${rFilter}':g='${gFilter}':b='${bFilter}'`; | |
return lutFilter; | |
} | |
const hexColorsToExclude = ["008000", "007ACC"]; | |
const lutFilter = generateLutFilter(hexColorsToExclude); | |
const ffmpegCommand = `ffmpeg -i input.mp4 -vf "${lutFilter}" -c:a copy output.mp4`; | |
console.log(ffmpegCommand); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment