Notes

from Kemper Barkhurst

Bashrc Script for Chroma Key Compositing

Step 1

The first step of this process is to output the source video into individual frames using FFMPEG. This is the command used to output a sequence of frames.  This was done on both the background and the foreground video files.

ffmpeg -i ../video.avi -f image2 %03d.jpeg

Step 2

Once these two sets of image sequences were created the dark image of the clay man had to be corrected and the background extracted.  This was achieved using a Photoshop Action that provided some level adjustments to brighten the image so it would be easier to extract.  The color range of the blue is selected and that selection is then removed from the image.  The layer with the clay man is then duplicated twice to build back any of the blue that was removed from the man.  For our purposes we had five different shots that all needed varying adjustments because of the variation in the lighting.  So this required that five different actions be created.

Step 3

The two images now need to be composited together into one image.  This can be achieved very easily using a basic loop that uses a command in GraphicsMagick.

#!/bin/bash
for (( f=1; f<=9; f++ ))
do
gm composite top/00$f.png bg/00$f.jpeg 00$f.png
done

For sequences longer than just 9 frames the number padding needs to change based upon the total number of frames.  An if statement would need to be setup to change that number padding so when the frame count reaches 10 the number padding would be reduced down from 00 to just 0.  This is needed for each time the number padding changes so would have to occur again when the count reaches 100, 1,000, 10,000, etc.

Step 4

The final step of this workflow is return the composited frame sequence back into a video.  This can be achieved using FFMPEG with the following command:

ffmpeg -f image2 -i %03d.jpeg final_video.mpg

Leave a Comment