Search code examples
vlc

VLC : How to change a certain key color of video with a background image?


I am struggling to find the necessary vlc command line arguments and vlm file setting for the following problem:

  1. Given an mp4 video with blue background
  2. Replace the blue color, with showing an image on the background
  3. Save the result to an mp4 with sound also

VLC documentation is too poor.


Solution

  • Put vlc folder in the PATH (Not necessary but saves some lines of code.)

    Open a Windows Command Line as "ADMISTRATOR" (right click and select) give this in command prompt:

    vlc -I dummy --vlm-conf=mosaic3.vlm -vv --sub-filter=mosaic --mosaic-alpha=255 --mosaic-width=960 --mosaic-height=540 --mosaic-xoffset=0 --mosaic-yoffset=0 --mosaic-keep-picture --bluescreen-u=120 --bluescreen-v=90 --bluescreen-vt=17 --bluescreen-ut=17 --file-logging --logfile=".\log.txt" --logmode=text
    

    where mosaic3.vlm is a file as follows

    new channel1 broadcast enabled
    setup channel1 input myvideo.mp4
    setup channel1 output #duplicate{dst=mosaic-bridge{height=540,width=960,chroma=YUVA,vfilter=bluescreen},select=video,dst=bridge-out{id=11},select=audio,acodec=mp4a,ab=128,channels=2,samplerate=44100}:display
      
    new mosaic broadcast enabled
    setup mosaic input "back.jpg"
    setup mosaic option image-duration=-1
    setup mosaic output #transcode{sfilter=mosaic{height=540,width=960,cols=1,rows=1,keep-aspect-ratio=enabled,keep-picture=1},vcodec=h264,acodec=mp4a,ab=128,channels=2,samplerate=44100}:bridge-in:std{access=file,mux=ts,dst=myoutput.mp4}
    
    control channel1 play
    control mosaic play
    

    Your result will be saved at myoutput.mp4

    Options:

    • My video is 960 x 540 , replace with your own dimensions

    • Chroma key bluescreen-u=120 --bluescreen-v=90 corresponds to blue color

    If you have a green, the try : bluescreen-u=60 --bluescreen-v=45

    See here for other colors: https://www.mikekohn.net/file_formats/yuv_rgb_converter.php