Remove everything but a single color (range)

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Remove everything but a single color (range)

Hans Carlson-2
Is it possible to "remove" everything in a video except a specific color
(or maybe a range... ie close to a specific color)?

By "remove" I mean covert every that is NOT the color(s) I want to black
or transparent.

I have a video that contains a yellowish box that moves about the screen.
I want to isolate ONLY the yellowish box.  Everything else should become
black or transparent.  The specific color is "fbed54" according to the
color picker in Gimp.

FYI. My knowledge of "colors" in general is extremely limited... let's put
it this way, I'm pretty sure RGB stands for Red Green Blue... that's about
the extent of it.   So, a specific example would be very helpful.

$ ffmpeg -i sample.mkv
ffmpeg version N-96974-g425b6a9a2c Copyright (c) 2000-2020 the FFmpeg developers
   built with gcc 9 (GCC)
   configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-static --disable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-libbluray --enable-libcdio
   libavutil      56. 42.100 / 56. 42.100
   libavcodec     58. 75.100 / 58. 75.100
   libavformat    58. 41.100 / 58. 41.100
   libavdevice    58.  9.103 / 58.  9.103
   libavfilter     7. 77.100 /  7. 77.100
   libswscale      5.  6.101 /  5.  6.101
   libswresample   3.  6.100 /  3.  6.100
   libpostproc    55.  6.100 / 55.  6.100
Input #0, matroska,webm, from 'sample.mkv':
   Metadata:
     ENCODER         : Lavf58.29.100
   Duration: 00:01:28.33, start: -0.051000, bitrate: 3242 kb/s
     Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1600x900 [SAR 1:1 DAR 16:9], 30.30 fps, 30.30 tbr, 1k tbn, 60 tbc (default)
     Metadata:
       DURATION        : 00:01:28.333000000
     Stream #0:1: Audio: vorbis, 48000 Hz, stereo, fltp (default)
     Metadata:
       DURATION        : 00:01:28.249000000
At least one output file must be specified
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

kumowoon1025
Hello,

> Is it possible to "remove" everything in a video except a specific color (or maybe a range... ie close to a specific color)?
>
> By "remove" I mean covert every that is NOT the color(s) I want to black or transparent.
>
> I have a video that contains a yellowish box that moves about the screen. I want to isolate ONLY the yellowish box.  Everything else should become black or transparent.  
I think colorkey filter can still do this. Basically you want the converse of what color keying does right? It should work the same (that is the opposite) way, and you just have to invert the alpha value.

> The specific color is "fbed54" according to the color picker in Gimp.
>
> FYI. My knowledge of "colors" in general is extremely limited... let's put it this way, I'm pretty sure RGB stands for Red Green Blue... that's about the extent of it.   So, a specific example would be very helpful.

RGB does stand for red, green and blue, and the color “#FBED54” would be a base-16 representation of how much of the three primary colors make up that specific color. The three colors are represented by two hexadecimal (base-16) digits each, with the hidden radix point on the left.
So in this case, it would mean Red has a value of (0.)FB, which is 15/16 + 11/256 = 98.5%, green would be 14/16+13/256=92.6% and so on.

The thing is video usually uses a different scheme of representing/storing color, so using rgb values to key the subject out might not be ideal. But still, try using colorkey or colorhold with higher similarity values first.

Regards,
Ted Park

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Dan Bridges
>Is it possible to "remove" everything in a video except a specific
color (or maybe a range... ie close to a specific color. By "remove" I
mean covert every that is NOT the color(s) I want to black or
transparent. I have a video that contains a yellowish box that moves
about the screen. I want to isolate ONLY the yellowish box. Everything
else should become black or transparent.

Try the colorhold filter:

From http://paulbourke.net/miscellaneous/ffmpeg/FFmpeg_Book.pdf

The 3 parameters are:

"color" is the color to be preserved, can be specified by name or by RGB
values, for example "orange" can be replaced by #FFA500
"similarity" is a percentage, 0.01 means only the specified color is
preserved, 1.0 means all colors are preserved.
"blend" is a percentage, 0.0 makes pixels fully gray, higher values
result in more preserved color


ffmpeg -i input_filename  -vf colorhold="FBED54":0.01:0  output_filename

This produces tight colour discrimination.  If too tight, increase the
2nd parameter from 0.01 until you get what you want.

Note, this filter will only make the discriminated stuff gray, not black
or transparent.  Perhaps someone else will be able to help.

A screenshot from an example using similarity=0.5 (a fairly sloppy
match) and your colour:  
https://dl.dropbox.com/s/isipbbtb2bjj7wy/filtered.jpg

Dan.






_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Michael Koch
Am 15.03.2020 um 11:13 schrieb Dan Bridges:

>> Is it possible to "remove" everything in a video except a specific
> color (or maybe a range... ie close to a specific color. By "remove" I
> mean covert every that is NOT the color(s) I want to black or
> transparent. I have a video that contains a yellowish box that moves
> about the screen. I want to isolate ONLY the yellowish box. Everything
> else should become black or transparent.
>
> Try the colorhold filter:
>
>  From http://paulbourke.net/miscellaneous/ffmpeg/FFmpeg_Book.pdf

You'd better use the original link to my book. Then you always get the
latest version:
http://www.astro-electronic.de/FFmpeg_Book.pdf

In this case the colorkey filter is the better solution, because the
original poster wanted the background black or transparent.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Hans Carlson-2
In reply to this post by kumowoon1025
On Sun, 15 Mar 2020, Ted Park wrote:

> I think colorkey filter can still do this. Basically you want the
> converse of what color keying does right? It should work the same (that
> is the opposite) way, and you just have to invert the alpha value.

I'm not quite sure what you mean by invert the alpha value.  I think you
mean invert the color I'm using... ie, if want to KEEP colors very close
to e6e65c (I've refined the color since my first post), then the "invert"
of that would be 1919A3 (at least according to an "opposite color tool" I
found).

So... after some experimenting...

colorkey sort of works if I use the "invert" color and max similarity and
blend values:

   colorkey=color=0x1919A3:similarity=1:blend=1

But the yellow box is pretty faint and there's still too much of the video
still visible.  NOTE: this ONLY works if I use ffplay, not ffmpeg (see
below).

> try using colorkey or colorhold with higher similarity values first.

colorhold does seem to work, but as Dan Bridges points out...

On Sun, 15 Mar 2020, Dan Bridges wrote:

> Note, this filter will only make the discriminated stuff gray, not black
> or transparent.  Perhaps someone else will be able to help.

Yes... that's what I see.  If I use this:

   colorhold=color=0xe6e65c:similarity=0.25:blend=0.5

Then the "yellow box" stays yellow and everything else becomes gray scale...
like I'm watching a black and white video.  But I don't want ANY video...
I ONLY want the yellow box floating around the screen.

Now I did find something that works (colorhold + chromakey)

   colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1

but this ONLY works if I use ffplay, so perhaps I'm not using it
correctly.

**IF** I use ffplay, then this does (mostly) what I want:

   ffplay -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1"

I ONLY see the yellow box (although it's a bit spotty), but pretty much
all of the rest of the video is completely black.  That's what I want.

BUT, if I use ffmpeg:

   ffmpeg -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1" test-highlight.mkv

Then it behaves as if the chromakey filter isn't used at all.  If fact,
the above produces the same output (as far as I can tell) as this:

   ffmpeg -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0" test-highlight.mkv

How can I get the same results with ffmpeg that I see with ffplay?

I have similar results using only colorkey with the inverted color.  ie,
using this (sort of) works:

   ffplay -i test.mkv -vf "colorkey=color=0x1919A3:similarity=1:blend=1"

but this doesn't seem to do anything (at least visibly):

   ffmpeg -i test.mkv -vf "colorkey=color=0x1919A3:similarity=1:blend=1" test-highlight.mkv


Here's the complete output for ffmpeg colorhold,chromakey:

$ ffmpeg -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1" test-highlight.mkv
ffmpeg version N-96974-g425b6a9a2c Copyright (c) 2000-2020 the FFmpeg developers
   built with gcc 9 (GCC)
   configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-static --disable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-libbluray --enable-libcdio
   libavutil      56. 42.100 / 56. 42.100
   libavcodec     58. 75.100 / 58. 75.100
   libavformat    58. 41.100 / 58. 41.100
   libavdevice    58.  9.103 / 58.  9.103
   libavfilter     7. 77.100 /  7. 77.100
   libswscale      5.  6.101 /  5.  6.101
   libswresample   3.  6.100 /  3.  6.100
   libpostproc    55.  6.100 / 55.  6.100
Input #0, matroska,webm, from 'test.mkv':
   Metadata:
     ENCODER         : Lavf58.29.100
   Duration: 00:01:27.36, start: 0.000000, bitrate: 2479 kb/s
     Stream #0:0: Video: h264 (High), yuv420p(progressive), 720x480 [SAR 32:27 DAR 16:9], 30 fps, 30 tbr, 1k tbn, 60 tbc (default)
     Metadata:
       ENCODER         : Lavc58.54.100 libx264
       DURATION        : 00:01:27.333000000
     Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s (default)
     Metadata:
       ENCODER         : Lavc58.54.100 ac3
       DURATION        : 00:01:27.356000000
Stream mapping:
   Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
   Stream #0:1 -> #0:1 (ac3 (native) -> vorbis (libvorbis))
Press [q] to stop, [?] for help
[swscaler @ 0x2447600] No accelerated colorspace conversion found from yuv420p to argb.
[libx264 @ 0x21ea280] using SAR=32/27
[libx264 @ 0x21ea280] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x21ea280] profile High 4:4:4 Predictive, level 3.0, 4:4:4, 8-bit
[libx264 @ 0x21ea280] 264 - core 157 r2980 34c06d1 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'test-highlight.mkv':
   Metadata:
     encoder         : Lavf58.41.100
     Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv444p, 720x480 [SAR 32:27 DAR 16:9], q=-1--1, 30 fps, 1k tbn, 30 tbc (default)
     Metadata:
       DURATION        : 00:01:27.333000000
       encoder         : Lavc58.75.100 libx264
     Side data:
       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
     Stream #0:1: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 48000 Hz, stereo, fltp (default)
     Metadata:
       DURATION        : 00:01:27.356000000
       encoder         : Lavc58.75.100 libvorbis
frame= 2620 fps= 45 q=-1.0 Lsize=    6972kB time=00:01:27.35 bitrate= 653.9kbits/s speed= 1.5x
video:5839kB audio:1076kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: 0.828422%
[libx264 @ 0x21ea280] frame I:11    Avg QP:20.07  size: 12820
[libx264 @ 0x21ea280] frame P:665   Avg QP:23.54  size:  6011
[libx264 @ 0x21ea280] frame B:1944  Avg QP:28.26  size:   946
[libx264 @ 0x21ea280] consecutive B-frames:  0.6%  1.1%  0.6% 97.7%
[libx264 @ 0x21ea280] mb I  I16..4:  6.1% 79.0% 14.9%
[libx264 @ 0x21ea280] mb P  I16..4:  1.0%  3.7%  1.3%  P16..4: 15.8% 11.1%  6.7%  0.0%  0.0%    skip:60.4%
[libx264 @ 0x21ea280] mb B  I16..4:  0.1%  0.4%  0.0%  B16..8: 17.4%  2.3%  0.4%  direct: 1.0%  skip:78.4%  L0:48.7% L1:43.0% BI: 8.3%
[libx264 @ 0x21ea280] 8x8 transform intra:66.9% inter:68.0%
[libx264 @ 0x21ea280] coded y,u,v intra: 45.1% 0.9% 0.3% inter: 8.8% 0.1% 0.0%
[libx264 @ 0x21ea280] i16 v,h,dc,p: 61% 31%  4%  4%
[libx264 @ 0x21ea280] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 13% 29%  4%  4%  6%  3%  6%  4%
[libx264 @ 0x21ea280] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 27% 12%  4%  6%  7%  5%  6%  4%
[libx264 @ 0x21ea280] Weighted P-Frames: Y:0.3% UV:0.2%
[libx264 @ 0x21ea280] ref P L0: 39.3% 13.3% 36.0% 11.3%  0.1%
[libx264 @ 0x21ea280] ref B L0: 68.3% 25.3%  6.4%
[libx264 @ 0x21ea280] ref B L1: 90.3%  9.7%
[libx264 @ 0x21ea280] kb/s:547.63
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Hans Carlson-2
Can anyone explain to me why this displays only the yellow bar with
everything else black:

   ffplay -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2"

but this displays all bars in gray scale except the yellow bar which is
in color:

   ffmpeg -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2" TEST-smptehdbars-yellow-only.mkv

What I want is ONLY the yellow bar and everything else black, as in the
ffplay command.  How can I get the same thing with ffmpeg?

Or an alternate way to accomplish the same thing.

Complete output for ffmpeg command:

$ ffmpeg -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2" TEST-smptehdbars-yellow-only.mkv
ffmpeg version N-96974-g425b6a9a2c Copyright (c) 2000-2020 the FFmpeg developers
   built with gcc 9 (GCC)
   configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-static --disable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-libbluray --enable-libcdio
   libavutil      56. 42.100 / 56. 42.100
   libavcodec     58. 75.100 / 58. 75.100
   libavformat    58. 41.100 / 58. 41.100
   libavdevice    58.  9.103 / 58.  9.103
   libavfilter     7. 77.100 /  7. 77.100
   libswscale      5.  6.101 /  5.  6.101
   libswresample   3.  6.100 /  3.  6.100
   libpostproc    55.  6.100 / 55.  6.100
Input #0, lavfi, from 'smptehdbars=duration=5':
   Duration: N/A, start: 0.000000, bitrate: N/A
     Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
   Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[swscaler @ 0x40bcd80] No accelerated colorspace conversion found from yuv420p to argb.
[libx264 @ 0x40b0140] using SAR=1/1
[libx264 @ 0x40b0140] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x40b0140] profile High 4:4:4 Predictive, level 1.3, 4:4:4, 8-bit
[libx264 @ 0x40b0140] 264 - core 157 r2980 34c06d1 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'TEST-smptehdbars-yellow-only.mkv':
   Metadata:
     encoder         : Lavf58.41.100
     Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv444p, 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 1k tbn, 25 tbc
     Metadata:
       encoder         : Lavc58.75.100 libx264
     Side data:
       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[Parsed_smptehdbars_0 @ 0x406e580] EOF timestamp not reliableitrate=   2.8kbits/s speed=3.97x
frame=  125 fps=0.0 q=-1.0 Lsize=       5kB time=00:00:04.88 bitrate=   7.9kbits/s speed=7.58x
video:3kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 44.947208%
[libx264 @ 0x40b0140] frame I:1     Avg QP:13.57  size:   552
[libx264 @ 0x40b0140] frame P:31    Avg QP: 9.23  size:    23
[libx264 @ 0x40b0140] frame B:93    Avg QP:12.67  size:    15
[libx264 @ 0x40b0140] consecutive B-frames:  0.8%  0.0%  0.0% 99.2%
[libx264 @ 0x40b0140] mb I  I16..4: 73.7% 15.3% 11.0%
[libx264 @ 0x40b0140] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:100.0%
[libx264 @ 0x40b0140] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%  L0: 0.0% L1:100.0% BI: 0.0%
[libx264 @ 0x40b0140] 8x8 transform intra:15.3%
[libx264 @ 0x40b0140] coded y,u,v intra: 5.6% 0.3% 0.2% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x40b0140] i16 v,h,dc,p: 76% 20%  4%  0%
[libx264 @ 0x40b0140] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25%  7% 68%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x40b0140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 55% 24% 20%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x40b0140] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x40b0140] kb/s:4.20
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

kumowoon1025
In reply to this post by Hans Carlson-2
Hello..

>> I think colorkey filter can still do this. Basically you want the converse of what color keying does right? It should work the same (that is the opposite) way, and you just have to invert the alpha value.
>
> I'm not quite sure what you mean by invert the alpha value.  I think you mean invert the color I'm using... ie, if want to KEEP colors very close to e6e65c (I've refined the color since my first post), then the "invert" of that would be 1919A3 (at least according to an "opposite color tool" I found).
>
> So... after some experimenting...
>
> colorkey sort of works if I use the "invert" color and max similarity and blend values:
>
>  colorkey=color=0x1919A3:similarity=1:blend=1
>
> But the yellow box is pretty faint and there's still too much of the video still visible.  NOTE: this ONLY works if I use ffplay, not ffmpeg (see below).
>
Sorry I wasn’t clear, that is not what I meant at all and in fact I am surprised that produced results that you describe as “sort of works.” I’m kind of curious, is the material something you could share?

What I meant was use colorkey to get the exact opposite of what you’re looking for, then you can use any one of a number of methods to get the difference from the original. (To put it conceptually, if you key out the subject, you’d be left with everything else, so if you subtract that from the whole, you should get only what you want.)

>> try using colorkey or colorhold with higher similarity values first.
>
> colorhold does seem to work, but as Dan Bridges points out...
>
>> Note, this filter will only make the discriminated stuff gray, not black
>> or transparent.  Perhaps someone else will be able to help.
>
> Yes... that's what I see.  If I use this:
>
>  colorhold=color=0xe6e65c:similarity=0.25:blend=0.5
>
> Then the "yellow box" stays yellow and everything else becomes gray scale... like I'm watching a black and white video.  But I don't want ANY video... I ONLY want the yellow box floating around the screen.
>
> Now I did find something that works (colorhold + chromakey)
>
>  colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1
>
> but this ONLY works if I use ffplay, so perhaps I'm not using it correctly.
>
> **IF** I use ffplay, then this does (mostly) what I want:
>
>  ffplay -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1"
>
> I ONLY see the yellow box (although it's a bit spotty), but pretty much all of the rest of the video is completely black.  That's what I want.
>
Okay, I am not sure if you are just trying a bunch of combinations but I don’t really understand how that works (what is similar to black in terms of chroma???)

> BUT, if I use ffmpeg:
>
>  ffmpeg -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1" test-highlight.mkv
>
> Then it behaves as if the chromakey filter isn't used at all.  If fact, the above produces the same output (as far as I can tell) as this:
>
>  ffmpeg -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0" test-highlight.mkv
>
> How can I get the same results with ffmpeg that I see with ffplay?
>
> I have similar results using only colorkey with the inverted color.  ie, using this (sort of) works:
>
>  ffplay -i test.mkv -vf "colorkey=color=0x1919A3:similarity=1:blend=1"
>
> but this doesn't seem to do anything (at least visibly):
>
>  ffmpeg -i test.mkv -vf "colorkey=color=0x1919A3:similarity=1:blend=1" test-highlight.mkv
I am guessing here, but it is probably because every time you switch from working with RGB then Y’CbCr, it erodes all the meaning from your filter configurations.

I’m sorry I wasn’t clear the first time around, I did not think you would invert your target color.
Try this…
First, choose rgb or yuv, then stick to one. (The video is yuv so I would choose that.) Then, add an alpha channel to serve as the mask. It might be added/converted automatically before the keying filters, but then it might switch from yuv to argb and back, which you probably would not like. If yuv, yuva444p would be sufficient in this case. If you really don’t to work in yuv, I think any of the plain rgb formats with alpha would work (rgba, argb, etc).
ffmpeg -i $INPUT -filter_complex "format=yuva444p”

Chroma key out the box (or color key, if you went that route)
ffmpeg -i $INPUT -filter_complex "format=yuva444p,chromakey=0xC8438A:yuv=1”

At this point the box you’re trying  to isolate should have alpha 0, which is the inverse of what you want. So all you need to do is invert the alpha values.

There’s probably a way to invert the values of just a single plane/channel, but I don't know how. Instead, there’s a filter that inverts (takes 1’s complement, i believe) of all pixel values, called “negate”.
Since it inverts values, obviously if you use it twice in series, the result is more or less identical to the input.
This is useful because it has an option, “negate_alpha” that controls whether the filter works on the alpha channel or not. We want to invert just the alpha values, we can achieve this by inverting everything, then inverting everything except the alpha back.
ffmpeg -i $INPUT -filter_complex "format=yuva444p,chromakey=0xC8438A:yuv=1,negate=negate_alpha=1,negate=negate_alpha=0”

That should give you the yellow box sort of rotoscoped out. You might still have to refine the mask, which you can do by isolating the alpha plane as a separate movie then working on that.

> Here's the complete output for ffmpeg colorhold,chromakey:
>
> $ ffmpeg -i test.mkv -vf "colorhold=color=0xe6e65c:similarity=0.25:blend=0.0,chromakey=color=black:similarity=.1" test-highlight.mkv

Really stumped on what chromakey does when you give it black, which is essentially no chroma. Does it just do the smart thing and key out everything with no color?
I think that would be the logical way to do this actually, remove color information other than the one you want, then extract just the areas with color. if you were to do this, you would need much more complex filtering. In yuv, you could check where u and v are both 0, but in rgb, I think it varies. Flip flopping the colors is kinda hacky but easier, probably faster too.

> Can anyone explain to me why this displays only the yellow bar with everything else black:
>
>  ffplay -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2"
>
> but this displays all bars in gray scale except the yellow bar which is in color:
>
>  ffmpeg -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2" TEST-smptehdbars-yellow-only.mkv
>
> What I want is ONLY the yellow bar and everything else black, as in the ffplay command.  How can I get the same thing with ffmpeg?

A rudimentary explanation, but I think it's like the renderer used by ffplay draws on a black screen, and libx264 uses a white canvas.

Regards,
Ted Park

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Hans Carlson-2
On Tue, 17 Mar 2020, Ted Park wrote:

> Sorry I wasn’t clear, that is not what I meant at all and in fact I am
> surprised that produced results that you describe as “sort of works.”
> I’m kind of curious, is the material something you could share?

I came up with an example I think might illustrate the video and goal
better.  See below.

> Try this…
>
> First, choose rgb or yuv, then stick to one. (The video is yuv so I
> would choose that.) Then, add an alpha channel to serve as the mask. It
> might be added/converted automatically before the keying filters, but
> then it might switch from yuv to argb and back, which you probably would
> not like. If yuv, yuva444p would be sufficient in this case. If you
> really don’t to work in yuv, I think any of the plain rgb formats with
> alpha would work (rgba, argb, etc).
>
> ffmpeg -i $INPUT -filter_complex "format=yuva444p”
>
> Chroma key out the box (or color key, if you went that route)
> ffmpeg -i $INPUT -filter_complex "format=yuva444p,chromakey=0xC8438A:yuv=1”

I'm assuming 0xC8438A is the YCbCr equivalent of the RGB value 0xe6e65c
that I was using?  My assumption is based on this converter
(http://www.picturetopeople.org/color_converter.html), that says RGB
0xe6e65c (230,230,92) is YCbCr (200,67,138) 0xc8438a.

> ffmpeg -i $INPUT -filter_complex "format=yuva444p,chromakey=0xC8438A:yuv=1,negate=negate_alpha=1,negate=negate_alpha=0”
>
> That should give you the yellow box sort of rotoscoped out. You might
> still have to refine the mask, which you can do by isolating the alpha
> plane as a separate movie then working on that.

I had to use "chromakey=color=0xC8438A:similarity=0.1" and then this does
work... but again ONLY if ffplay is used.  If ffmpeg is used then it looks
exactly like $INPUT.

I'm not sure what you mean by "refine the mask" and "isolating the alpha
plane as a separate movie".

>> What I want is ONLY the yellow bar and everything else black, as in the
>> ffplay command.  How can I get the same thing with ffmpeg?
>
> A rudimentary explanation, but I think it's like the renderer used by
> ffplay draws on a black screen, and libx264 uses a white canvas.

Is there a way to tell libx264 to use a black canvas?  Or I can use a
different codec and/or format? I don't really care what the output
codec/format is as you will see with the end goal, explained below.

So... maybe I should back up a bit and provide A) a TEST VIDEO and B) a
better explanation of my END GOAL.

The TEST VIDEO can be generated using the "life" filter and some other
bits.  It will basically be "life" with a 6 section grid overlay where a
yellow box moves from section to section.  I see the exact same behavior
using this test video as I do with the real video.

First create a filter script file.  This isn't really necessary, but I
found it easier to adjust where and when the yellow square appears by
simply editing this file, rather than 1 really long command line.

Save this as life-boxes.filter.  By all means change or add new drawbox
entries, just be sure the last one does NOT end with ','.  The drawgrid
and drawtext filters are not necessary, they just help show where and when
the yellow box (drawbox) shows up.

--------------- CUT -----------------
drawgrid=w=200:h=200:color=black,

drawtext=text='1':fontsize=40:fontcolor=white:x=10:y=10,
drawtext=text='2':fontsize=40:fontcolor=white:x=210:y=10,
drawtext=text='3':fontsize=40:fontcolor=white:x=410:y=10,
drawtext=text='4':fontsize=40:fontcolor=white:x=10:y=210,
drawtext=text='5':fontsize=40:fontcolor=white:x=210:y=210,
drawtext=text='6':fontsize=40:fontcolor=white:x=410:y=210,

drawtext=text='%{pts}':fontsize=30:fontcolor=white:x=10:y=main_h-max_glyph_h-10,

drawbox=enable='between(t, 0, 1.96)':w=50:h=50:x=75:y=75:color=0xffff00,
drawbox=enable='between(t, 2, 2.96)':w=50:h=50:x=275:y=75:color=0xffff00,
drawbox=enable='between(t, 3, 4.96)':w=50:h=50:x=275:y=275:color=0xffff00,
drawbox=enable='between(t, 5, 7.96)':w=50:h=50:x=475:y=75:color=0xffff00,
drawbox=enable='between(t, 8, 8.96)':w=50:h=50:x=75:y=275:color=0xffff00,
drawbox=enable='between(t, 9,10.96)':w=50:h=50:x=475:y=275:color=0xffff00,
drawbox=enable='between(t,11,11.96)':w=50:h=50:x=275:y=275:color=0xffff00,
drawbox=enable='between(t,12,14.96)':w=50:h=50:x=275:y=75:color=0xffff00,
drawbox=enable='between(t,15,16.96)':w=50:h=50:x=475:y=275:color=0xffff00,
drawbox=enable='between(t,17,19.96)':w=50:h=50:x=75:y=75:color=0xffff00
--------------- CUT -----------------

Then run the following to generate the "life-boxes.mkv" test video:

   ffmpeg -f lavfi -i "life=size=600x400:life_color=0x00ff00:death_color=0xff0000:mold_color=0x0000ff:mold=10,format=yuv420p" -filter_complex_script life-boxes.filter -t 20 life-boxes.mkv

A couple notes about the test video:

   1) the yellow box will only be in one section at a time.
   2) which section and when the yellow box appears is unknown.

Obviously the where and when IS known in the test video, but neither is
known in the real video.

The END GOAL is to figure out which section and most importantly WHEN the
yellow box appears.  So, given the above test video I want to end up with
something like this:

The first number is the section number (left-right,top-bottom) and the 2nd
number is the absolute time it appeared.

   1, 0  # section 1, timecode 0 seconds
   2, 2  # section 2, timecode 2 seconds
   5, 3  # section 5, timecode 3 seconds
   3, 5  # section 3, timecode 5 seconds
   4, 8  # section 4, timecode 8 seconds
   6, 9  # section 6, timecode 9 seconds
   5,11  # section 5, timecode 11 seconds
   2,12  # section 2, timecode 12 seconds
   6,15  # section 6, timecode 15 seconds
   1,17  # section 1, timecode 17 seconds

I don't expect ffmpeg to produce that output (or anything close to that)
directly.  I fully expect to use ffprobe or verbose/debug output or some
other method to actually get the info.

Exactly HOW I go about this I haven't fully figured out, but it seemed to
me the 1st step was to somehow isolate the yellow box.  I figured if I
could get the yellow box on a completely black (or transparent)
background, then there should be some way I could distinguish between a
frame that's entirely black/transparent (1 color) vs a frame that contains
some yellow (ie, the box).  Maybe I'd use blackdetect in some way or maybe
I generate png files for each frame and then manipulate them with
imagemagick or some other image processing tool.  Again, I haven't fully
figured it all out.

In terms of figuring out WHERE the box appears, if there's no
filter/method that could give me the location of the box, I think I could
crop the video into 6 separate files (1 for each section), then process
each file separately to determine WHEN the yellow box appears in that
section.  But perhaps there's a better way to do that.

Soo.... trying some of the previous commands using the above generated
video (life-boxes.mkv), I get these results...

NOTE: The RGB 0xffff00 value is the color of the yellow box found in
life-boxes.filter.  The YCbCr 0xd21092 value is the RGB -> YCbCr
conversion of 0xffff00 (according to
http://www.picturetopeople.org/color_converter.html).

My original (trial and error/colorhold,chromakey) method.  Using ffplay,
this works. ie, all I see is the yellow box moving around on a black
background:

   ffplay -i life-boxes.mkv -vf "colorhold=color=0xffff00:similarity=0.1,chromakey=color=black:similarity=.2"

If I change that to ffmpeg, then the yellow box is in color, but I still
see the grid lines and "life" is now gray scale:

   ffmpeg -i life-boxes.mkv -vf "colorhold=color=0xffff00:similarity=0.1,chromakey=color=black:similarity=.2" life-boxes-colorhold.mkv

With both of these, I don't see any difference.  They look exactly like
life-boxes.mkv... at least visually.

   ffmpeg -i life-boxes.mkv -vf "format=yuva444p,chromakey=color=0xd21092:similarity=0.1:yuv=1" life-boxes-chromakey.mkv

   ffmpeg -i life-boxes.mkv -vf "format=yuva444p,chromakey=color=0xd21092:similarity=0.1:yuv=1,negate=negate_alpha=1,negate=negate_alpha=0" life-boxes-chromakey-negate.mkv

BUT... if ffplay is used...

This one shows "life" in color (just like life-boxes.mkv), and the yellow
box is sort of a mixture between black and yellow.  Increasing the
similarity to 0.4 makes the yellow box completely black, but then it's too
high once the negate filters are added:

   ffplay -i life-boxes.mkv -vf "format=yuva444p,chromakey=color=0xd21092:similarity=0.1:yuv=1"

And this one looks very similar to my "colorhold,chromakey" command using
ffplay.  ie, only the yellow box is displayed and everything else is
black.  But this only works if ffplay is used:

   ffplay -i life-boxes.mkv -vf "format=yuva444p,chromakey=color=0xd21092:similarity=0.1:yuv=1,negate=negate_alpha=1,negate=negate_alpha=0"

And using the RGB color works as well... as long as ffplay is used:

   ffplay -i life-boxes.mkv -vf "format=yuva444p,chromakey=color=0xffff00:similarity=0.1,negate=negate_alpha=1,negate=negate_alpha=0"

Soo... given the above END GOAL, is there a better way to separate the
yellow box from the rest of the video and determine at least WHEN it
appears?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Carl Eugen Hoyos-2
In reply to this post by Hans Carlson-2
Am Di., 17. März 2020 um 00:38 Uhr schrieb Hans Carlson <[hidden email]>:

>
> Can anyone explain to me why this displays only the yellow bar with
> everything else black:
>
>    ffplay -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2"
>
> but this displays all bars in gray scale except the yellow bar which is
> in color:
>
>    ffmpeg -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2" TEST-smptehdbars-yellow-only.mkv
>
> What I want is ONLY the yellow bar and everything else black, as in the
> ffplay command.  How can I get the same thing with ffmpeg?

You need to also use the overlay filter.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Hans Carlson-2
On Wed, 18 Mar 2020, Carl Eugen Hoyos wrote:

> Am Di., 17. März 2020 um 00:38 Uhr schrieb Hans Carlson <[hidden email]>:
>>
>> Can anyone explain to me why this displays only the yellow bar with
>> everything else black:
>>
>>    ffplay -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2"
>>
>> but this displays all bars in gray scale except the yellow bar which is
>> in color:
>>
>>    ffmpeg -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2" TEST-smptehdbars-yellow-only.mkv
>>
>> What I want is ONLY the yellow bar and everything else black, as in the
>> ffplay command.  How can I get the same thing with ffmpeg?
>
> You need to also use the overlay filter.

Can you expand on that a bit?  What am I overlaying?  I only have one
input.

And why does the above command work using ffplay, but not ffmpeg?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Remove everything but a single color (range)

Carl Eugen Hoyos-2
Am Mi., 18. März 2020 um 02:51 Uhr schrieb Hans Carlson <[hidden email]>:

>
> On Wed, 18 Mar 2020, Carl Eugen Hoyos wrote:
>
> > Am Di., 17. März 2020 um 00:38 Uhr schrieb Hans Carlson <[hidden email]>:
> >>
> >> Can anyone explain to me why this displays only the yellow bar with
> >> everything else black:
> >>
> >>    ffplay -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2"
> >>
> >> but this displays all bars in gray scale except the yellow bar which is
> >> in color:
> >>
> >>    ffmpeg -f lavfi -i 'smptehdbars=duration=5' -vf "colorhold=color=0xbcc906:similarity=0.25,chromakey=color=black:similarity=.2" TEST-smptehdbars-yellow-only.mkv
> >>
> >> What I want is ONLY the yellow bar and everything else black, as in the
> >> ffplay command.  How can I get the same thing with ffmpeg?
> >
> > You need to also use the overlay filter.
>
> Can you expand on that a bit?  What am I overlaying?  I only have one
> input.

You have to add a second one (for example the "color" filter) to
achieve what you want.

> And why does the above command work using ffplay, but not ffmpeg?

To make testing infinitely harder (as you found out), ffplay was changed
some time ago to overlay by default (instead of showing what is
"underneath" the transparency layer).

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".