Created
January 25, 2025 00:41
-
-
Save cassidoo/2e4e71c593c3ebb527c86321547e7d08 to your computer and use it in GitHub Desktop.
Revisions
-
cassidoo revised this gist
Jan 25, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,6 @@ function generateLutFilter(hexColorsToExclude) { return { r, g, b }; } let lutFilter = "lutrgb="; let rConditions = []; let gConditions = []; @@ -33,4 +32,5 @@ const hexColorsToExclude = ["008000", "007ACC"]; const lutFilter = generateLutFilter(hexColorsToExclude); const ffmpegCommand = `ffmpeg -i input.mp4 -vf "${lutFilter}" -c:a copy output.mp4`; console.log(ffmpegCommand); -
cassidoo created this gist
Jan 25, 2025 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ 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 }; } // Create the LUT filter string 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);