Convert a video from dark mode to light mode with FFmpeg!
Cassidy Williams

Cassidy Williams @cassidoo

About: bold and brash

Location:
Chicago, IL
Joined:
Feb 22, 2017

Convert a video from dark mode to light mode with FFmpeg!

Publish Date: Apr 14
1 0

Let's make it so you can record a demo (assuming you recorded it in VS Code) once in dark mode, and then convert that into light mode, in a single command!

Install FFmpeg

FFmpeg is the brains behind pretty much all video editing softwares. It’s a really awesome tool beyond just this use case!

You can go to their downloads page to clone the repo or go into details about how it runs, but here’s some shortcuts.

If you’ve already installed it, skip this section!

MacOS 🍏

If you’re on MacOS, you can use Homebrew to install FFmpeg:

brew install ffmpeg
Enter fullscreen mode Exit fullscreen mode

Linux 🐧

If you’re on Linux:

sudo apt install ffmpeg
Enter fullscreen mode Exit fullscreen mode

Windows 🪟

And if you’re on Windows:

  1. Download the pre-built binaries. Choose the Windows version and click on the link to download a static build.

  2. Extract the downloaded ZIP file to a folder of your choice, e.g., C:\ffmpeg. I personally have a babyscripts folder for small CLI apps like this or yt-dlp.

  3. Add the bin directory to your system’s PATH:

  4. Verify the installation by opening Command Prompt and typing ffmpeg -version.

Running the command

Now, whenever you have a dark mode video, let’s say it’s named input.mp4, you can run this command in the folder where it’s located to get a light mode version named output.mp4!

ffmpeg -i input.mp4 -vf "negate,hue=h=180,eq=contrast=1.2:saturation=1.1" output.mp4
Enter fullscreen mode Exit fullscreen mode

🛑 You can stop here if you want to rest your brain 🛑

Creating a reusable alias

Now, this may be hard to remember, so what you can also do is create an alias for this in your terminal!

If you're on MacOS/Linux 🍏🐧

For MacOS/Linux, run the below command and then restart your terminal:

newCommand='
# Alias for converting videos from dark mode to light mode
convert-to-light-mode() {
    inputFileName=$1
    outputFileName=$2

    if [-z "$outputFileName"]; then
        fileBaseName="${inputFileName%.*}"
        suffix="-light-mode"
        fileExtension="${inputFileName##*.}"
        outputFileName="${fileBaseName}${suffix}.${fileExtension}"
    fi

    ffmpeg -i "$inputFileName" -vf "negate,hue=h=180,eq=contrast=1.2:saturation=1.1" "$outputFileName"
}
'

# Add command to bash and zsh
echo $newCommand >> ~/.bashrc
echo $newCommand >> ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

(thanks to @chriswblake for help with this part!)

Now, when you want to run the command, you run:

convert-to-light-mode input.mp4 output.mp4

# or

convert-to-light-mode my-video.mp4
# the output here would be my-video-light-mode.mp4
Enter fullscreen mode Exit fullscreen mode

If you're on Windows 🪟

And here’s the equivalent for Windows!

# A function for converting videos from dark mode to light mode
function Convert-ToLightMode {
    param (
        [string]$inputFileName,
        [string]$outputFileName
    )

    if (-not $outputFileName) {
        $fileBaseName = [System.IO.Path]::GetFileNameWithoutExtension($inputFileName)
        $suffix = "-light-mode"
        $fileExtension = [System.IO.Path]::GetExtension($inputFileName)
        $outputFileName = "${fileBaseName}${suffix}${fileExtension}"
    }

    ffmpeg -i $inputFileName -vf "negate,hue=h=180,eq=contrast=1.2:saturation=1.1" $outputFileName
}

$profileContent = @"
function Convert-ToLightMode {
    param (
        [string]`$inputFileName,
        [string]`$outputFileName
    )

if (-not `$outputFileName) {
        `$fileBaseName = [System.IO.Path]::GetFileNameWithoutExtension(`$inputFileName)
        `$suffix = "-light-mode"
        `$fileExtension = [System.IO.Path]::GetExtension(`$inputFileName)
        `$outputFileName = "`$fileBaseName`$suffix`$fileExtension"
    }

    ffmpeg -i `$inputFileName -vf "negate,hue=h=180,eq=contrast=1.2:saturation=1.1" `$outputFileName
}
"@

Add-Content -Path $PROFILE -Value $profileContent
Enter fullscreen mode Exit fullscreen mode

To use this, you would run it like so:

Convert-ToLightMode -inputFileName "input.mp4" -outputFileName "output.mp4"

# or

Convert-ToLightMode -inputFileName "my-video.mp4"
# the output here would be my-video-light-mode.mp4
Enter fullscreen mode Exit fullscreen mode

After creating the alias, an added bonus 👀

Something that you can ALSO do with this script is export the light mode version as a .gif image!

MacOS/Linux:

convert-to-light-mode input.mp4 output.gif
Enter fullscreen mode Exit fullscreen mode

Windows:

Convert-ToLightMode -inputFileName "input.mp4" -outputFileName "output.gif"
Enter fullscreen mode Exit fullscreen mode

Wow! By the way, if you want your original video to be a .gif too, you can run it fairly plainly with FFmpeg:

ffmpeg -i input.mp4 output.gif
Enter fullscreen mode Exit fullscreen mode

Happy converting!

Let me know if you have any questions!

So far, this script seems to work best with the theme Dark Modern. If you try other themes, let me know!

Dark Light Demo

Comments 0 total

    Add comment