{"id":3631,"date":"2021-04-06T22:41:44","date_gmt":"2021-04-07T05:41:44","guid":{"rendered":"https:\/\/www.cloudacm.com\/?p=3631"},"modified":"2021-04-06T22:41:44","modified_gmt":"2021-04-07T05:41:44","slug":"color-isolation-with-ffmpeg","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=3631","title":{"rendered":"Color Isolation with FFMpeg"},"content":{"rendered":"<p>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.<\/p>\n<p><a href=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2021\/04\/color-pattern.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3632\" src=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2021\/04\/color-pattern-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2021\/04\/color-pattern-300x300.jpg 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2021\/04\/color-pattern-150x150.jpg 150w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2021\/04\/color-pattern-270x270.jpg 270w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2021\/04\/color-pattern.jpg 440w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>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.<\/p>\n<pre>ffplay -i \"color-pattern.jpg\" -vf \"colorhold=0xFF0000:similarity=0.25\"\r\n<\/pre>\n<p>Now our image shows only the defined color threshold, in this example it&#8217;s red. Here are a couple more examples, this time the command will isolate only green, then blue.<\/p>\n<pre>ffplay -i \"color-pattern.jpg\" -vf \"colorhold=0x00FF00:similarity=0.25\"\r\nffplay -i \"color-pattern.jpg\" -vf \"colorhold=0x0000FF:similarity=0.25\"\r\n<\/pre>\n<p>In this next example, the command includes a blend argument which softens the color edge.<\/p>\n<pre>ffplay -i \"color-pattern.jpg\" -vf \"colorhold=0xFF0000:similarity=0.25:blend=.30\"\r\nffplay -i \"color-pattern.jpg\" -vf \"colorhold=0x00FF00:similarity=0.25:blend=.30\"\r\nffplay -i \"color-pattern.jpg\" -vf \"colorhold=0x0000FF:similarity=0.25:blend=.30\"\r\n<\/pre>\n<p>Here are a series of commands that I used to create a video of each color isolation result.<\/p>\n<pre># Create initial image results to a movie\r\nffmpeg -i \"color-pattern.jpg\" \"FullColor.MOV\"\r\nffmpeg -i \"color-pattern.jpg\" -vf \"colorhold=0xFF0000:similarity=0.25\" \"RedEdge.MOV\"\r\nffmpeg -i \"color-pattern.jpg\" -vf \"colorhold=0x00FF00:similarity=0.25\" \"GreenEdge.MOV\"\r\nffmpeg -i \"color-pattern.jpg\" -vf \"colorhold=0x0000FF:similarity=0.25\" \"BlueEdge.MOV\"\r\nffmpeg -i \"color-pattern.jpg\" -vf \"colorhold=0xFF0000:similarity=0.25:blend=.30\" \"RedSoftEdge.MOV\"\r\nffmpeg -i \"color-pattern.jpg\" -vf \"colorhold=0x00FF00:similarity=0.25:blend=.30\" \"GreenSoftEdge.MOV\"\r\nffmpeg -i \"color-pattern.jpg\" -vf \"colorhold=0x0000FF:similarity=0.25:blend=.30\" \"BlueSoftEdge.MOV\"\r\n\r\n# Convert the movie to an image\r\nffmpeg -i \"FullColor.MOV\" -vf fps=30 \"FullColor.jpg\"\r\nffmpeg -i \"RedEdge.MOV\" -vf fps=30 \"RedEdge.jpg\"\r\nffmpeg -i \"GreenEdge.MOV\" -vf fps=30 \"GreenEdge.jpg\"\r\nffmpeg -i \"BlueEdge.MOV\" -vf fps=30 \"BlueEdge.jpg\"\r\nffmpeg -i \"RedSoftEdge.MOV\" -vf fps=30 \"RedSoftEdge.jpg\"\r\nffmpeg -i \"GreenSoftEdge.MOV\" -vf fps=30 \"GreenSoftEdge.jpg\"\r\nffmpeg -i \"BlueSoftEdge.MOV\" -vf fps=30 \"BlueSoftEdge.jpg\"\r\n\r\n# Convert the image into a timed video\r\nffmpeg -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\r\nffmpeg -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\r\nffmpeg -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\r\nffmpeg -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\r\nffmpeg -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\r\nffmpeg -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\r\nffmpeg -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\r\n\r\n# Concatenate all of the videos\r\n$ cat files.txt\r\nfile 'FullColor.mp4'\r\nfile 'RedEdge.mp4'\r\nfile 'RedSoftEdge.mp4'\r\nfile 'GreenEdge.mp4'\r\nfile 'GreenSoftEdge.mp4'\r\nfile 'BlueEdge.mp4'\r\nfile 'BlueSoftEdge.mp4'\r\nffmpeg -f concat -safe 0 -i files.txt -c copy ColorIsolation.mp4\r\n<\/pre>\n<p>Here is the video of the results.<\/p>\n<p><iframe loading=\"lazy\" title=\"Color Isolation Pattern\" width=\"640\" height=\"480\" src=\"https:\/\/www.youtube.com\/embed\/3x6-v5X1vBQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Here is some video I captured that demonstrates color isolation.<\/p>\n<pre># Isolate colors from source video\r\nffmpeg -i \"REC_0043.MOV\" -vf \"scale=iw*.5:ih*.5, colorhold=0xFF0000:similarity=0.55\" \"RED.MOV\"\r\nffmpeg -i \"REC_0043.MOV\" -vf \"scale=iw*.5:ih*.5, colorhold=0x0088FF:similarity=0.70\" \"BLUE.MOV\"\r\nffmpeg -i \"REC_0043.MOV\" -vf \"scale=iw*.5:ih*.5, colorhold=0x00AA00:similarity=0.55\" \"GREEN.MOV\"\r\n\r\n# Segment the video for a shorter clip\r\nffmpeg -ss 03:00 -i \"REC_0043.MOV\" -t 12 \"FullColor_Segment.MOV\"\r\nffmpeg -ss 03:00 -i \"RED.MOV\" -t 12 \"RED_Segment.MOV\"\r\nffmpeg -ss 03:00 -i \"BLUE.MOV\" -t 12 \"BLUE_Segment.MOV\"\r\nffmpeg -ss 03:00 -i \"GREEN.MOV\" -t 12 \"GREEN_Segment.MOV\"\r\n\r\n# Concatenate all of the videos\r\n$ cat filelist.txt\r\nfile 'RED_Segment.MOV'\r\nfile 'BLUE_Segment.MOV'\r\nfile 'GREEN_Segment.MOV'\r\nfile 'FullColor_Segment.MOV'\r\nffmpeg -f concat -safe 0 -i filelist.txt -c copy ColorIsolationDemo.MOV\r\n<\/pre>\n<p><iframe loading=\"lazy\" title=\"Color Isolation Demo\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/d8UDVySucBo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Much thanks to NerdFirst, cheers! It&#8217;s long overdue to give some appreciation, <a href=\"https:\/\/nerdfirst.net\/donate\/\">https:\/\/nerdfirst.net\/donate\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;color-pattern.jpg&#8221; -vf &#8220;colorhold=0xFF0000:similarity=0.25&#8221; Now our image shows only the defined color threshold, in this example it&#8217;s red. Here are&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=3631\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,9,3],"tags":[],"class_list":["post-3631","post","type-post","status-publish","format-standard","hentry","category-bike-rides","category-computer-vision","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3631"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3631\/revisions"}],"predecessor-version":[{"id":3633,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3631\/revisions\/3633"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}