Color Isolation with FFMpeg

Color Isolation with FFMpeg

I had written a post awhile back about color isolation using imagemagick. Here is a recap, but this time using FFMpeg. This turned out to be a good color pattern to do testing against.

the reason I prefer this is because it contains white and black space to visually understand the results of the filter. Lets try this command.

ffplay -i "color-pattern.jpg" -vf "colorhold=0xFF0000:similarity=0.25"

Now our image shows only the defined color threshold, in this example it’s red. Here are a couple more examples, this time the command will isolate only green, then blue.

ffplay -i "color-pattern.jpg" -vf "colorhold=0x00FF00:similarity=0.25"
ffplay -i "color-pattern.jpg" -vf "colorhold=0x0000FF:similarity=0.25"

In this next example, the command includes a blend argument which softens the color edge.

ffplay -i "color-pattern.jpg" -vf "colorhold=0xFF0000:similarity=0.25:blend=.30"
ffplay -i "color-pattern.jpg" -vf "colorhold=0x00FF00:similarity=0.25:blend=.30"
ffplay -i "color-pattern.jpg" -vf "colorhold=0x0000FF:similarity=0.25:blend=.30"

Here are a series of commands that I used to create a video of each color isolation result.

# Create initial image results to a movie
ffmpeg -i "color-pattern.jpg" "FullColor.MOV"
ffmpeg -i "color-pattern.jpg" -vf "colorhold=0xFF0000:similarity=0.25" "RedEdge.MOV"
ffmpeg -i "color-pattern.jpg" -vf "colorhold=0x00FF00:similarity=0.25" "GreenEdge.MOV"
ffmpeg -i "color-pattern.jpg" -vf "colorhold=0x0000FF:similarity=0.25" "BlueEdge.MOV"
ffmpeg -i "color-pattern.jpg" -vf "colorhold=0xFF0000:similarity=0.25:blend=.30" "RedSoftEdge.MOV"
ffmpeg -i "color-pattern.jpg" -vf "colorhold=0x00FF00:similarity=0.25:blend=.30" "GreenSoftEdge.MOV"
ffmpeg -i "color-pattern.jpg" -vf "colorhold=0x0000FF:similarity=0.25:blend=.30" "BlueSoftEdge.MOV"

# Convert the movie to an image
ffmpeg -i "FullColor.MOV" -vf fps=30 "FullColor.jpg"
ffmpeg -i "RedEdge.MOV" -vf fps=30 "RedEdge.jpg"
ffmpeg -i "GreenEdge.MOV" -vf fps=30 "GreenEdge.jpg"
ffmpeg -i "BlueEdge.MOV" -vf fps=30 "BlueEdge.jpg"
ffmpeg -i "RedSoftEdge.MOV" -vf fps=30 "RedSoftEdge.jpg"
ffmpeg -i "GreenSoftEdge.MOV" -vf fps=30 "GreenSoftEdge.jpg"
ffmpeg -i "BlueSoftEdge.MOV" -vf fps=30 "BlueSoftEdge.jpg"

# Convert the image into a timed video
ffmpeg -loop 1 -i FullColor.jpg -c:v libx264 -preset slow -g 60 -r 30 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 2 FullColor.mp4
ffmpeg -loop 1 -i RedEdge.jpg -c:v libx264 -preset slow -g 60 -r 30 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 2 RedEdge.mp4
ffmpeg -loop 1 -i GreenEdge.jpg -c:v libx264 -preset slow -g 60 -r 30 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 2 GreenEdge.mp4
ffmpeg -loop 1 -i BlueEdge.jpg -c:v libx264 -preset slow -g 60 -r 30 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 2 BlueEdge.mp4
ffmpeg -loop 1 -i RedSoftEdge.jpg -c:v libx264 -preset slow -g 60 -r 30 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 2 RedSoftEdge.mp4
ffmpeg -loop 1 -i GreenSoftEdge.jpg -c:v libx264 -preset slow -g 60 -r 30 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 2 GreenSoftEdge.mp4
ffmpeg -loop 1 -i BlueSoftEdge.jpg -c:v libx264 -preset slow -g 60 -r 30 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 2 BlueSoftEdge.mp4

# Concatenate all of the videos
$ cat files.txt
file 'FullColor.mp4'
file 'RedEdge.mp4'
file 'RedSoftEdge.mp4'
file 'GreenEdge.mp4'
file 'GreenSoftEdge.mp4'
file 'BlueEdge.mp4'
file 'BlueSoftEdge.mp4'
ffmpeg -f concat -safe 0 -i files.txt -c copy ColorIsolation.mp4

Here is the video of the results.

Here is some video I captured that demonstrates color isolation.

# Isolate colors from source video
ffmpeg -i "REC_0043.MOV" -vf "scale=iw*.5:ih*.5, colorhold=0xFF0000:similarity=0.55" "RED.MOV"
ffmpeg -i "REC_0043.MOV" -vf "scale=iw*.5:ih*.5, colorhold=0x0088FF:similarity=0.70" "BLUE.MOV"
ffmpeg -i "REC_0043.MOV" -vf "scale=iw*.5:ih*.5, colorhold=0x00AA00:similarity=0.55" "GREEN.MOV"

# Segment the video for a shorter clip
ffmpeg -ss 03:00 -i "REC_0043.MOV" -t 12 "FullColor_Segment.MOV"
ffmpeg -ss 03:00 -i "RED.MOV" -t 12 "RED_Segment.MOV"
ffmpeg -ss 03:00 -i "BLUE.MOV" -t 12 "BLUE_Segment.MOV"
ffmpeg -ss 03:00 -i "GREEN.MOV" -t 12 "GREEN_Segment.MOV"

# Concatenate all of the videos
$ cat filelist.txt
file 'RED_Segment.MOV'
file 'BLUE_Segment.MOV'
file 'GREEN_Segment.MOV'
file 'FullColor_Segment.MOV'
ffmpeg -f concat -safe 0 -i filelist.txt -c copy ColorIsolationDemo.MOV

Much thanks to NerdFirst, cheers! It’s long overdue to give some appreciation, https://nerdfirst.net/donate/

Comments are closed.