[FFmpeg-devel] [PATCH] avfilter/vf_chromakey: Add chromakey video filter

2015-09-18 Thread Timo Rothenpieler
---
 Changelog  |   1 +
 MAINTAINERS|   1 +
 doc/filters.texi   |  45 ++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/version.h  |   2 +-
 libavfilter/vf_chromakey.c | 211 +
 7 files changed, 261 insertions(+), 1 deletion(-)
 create mode 100644 libavfilter/vf_chromakey.c

diff --git a/Changelog b/Changelog
index 653317f..db9064d 100644
--- a/Changelog
+++ b/Changelog
@@ -7,6 +7,7 @@ version :
 - ocr filter
 - alimiter filter
 - stereowiden filter
+- chromakey filter
 
 
 version 2.8:
diff --git a/MAINTAINERS b/MAINTAINERS
index 4a50430..12da0cd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -359,6 +359,7 @@ Filters:
   avf_avectorscope.cPaul B Mahol
   avf_showcqt.c Muhammad Faiz
   vf_blend.cPaul B Mahol
+  vf_chromakey.cTimo Rothenpieler
   vf_colorchannelmixer.cPaul B Mahol
   vf_colorbalance.c Paul B Mahol
   vf_colorkey.c Timo Rothenpieler
diff --git a/doc/filters.texi b/doc/filters.texi
index 4a55e59..0446204 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3556,6 +3556,51 @@ 
boxblur=luma_radius=min(h\,w)/10:luma_power=1:chroma_radius=min(cw\,ch)/10:chrom
 @end example
 @end itemize
 
+@section chromakey
+YUV colorspace color/chroma keying.
+
+The filter accepts the following options:
+
+@table @option
+@item color
+The color which will be replaced with transparency.
+
+@item similarity
+Similarity percentage with the key color.
+
+0.01 matches only the exact key color, while 1.0 matches everything.
+
+@item blend
+Blend percentage.
+
+0.0 makes pixels either fully transparent, or not transparent at all.
+
+Higher values result in semi-transparent pixels, with a higher transparency
+the more similar the pixels color is to the key color.
+
+@item yuv
+Signals that the color passed is already in YUV instead of RGB.
+
+Litteral colors like "green" or "red" don't make sense with this enabled 
anymore.
+This can be used to pass exact YUV values as hexadecimal numbers.
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Make every green pixel in the input image transparent:
+@example
+ffmpeg -i input.png -vf chromakey=green out.png
+@end example
+
+@item
+Overlay a greenscreen-video on top of a static black background.
+@example
+ffmpeg -f lavfi -i color=c=black:s=1280x720 -i video.mp4 -shortest 
-filter_complex 
"[1:v]chromakey=0x70de77:0.1:0.2[ckout];[0:v][ckout]overlay[out]" -map "[out]" 
output.mkv
+@end example
+@end itemize
+
 @section codecview
 
 Visualize information exported by some codecs.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 05effd6..2aa8603 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -102,6 +102,7 @@ OBJS-$(CONFIG_BLACKDETECT_FILTER)+= 
vf_blackdetect.o
 OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
 OBJS-$(CONFIG_BLEND_FILTER)  += vf_blend.o dualinput.o 
framesync.o
 OBJS-$(CONFIG_BOXBLUR_FILTER)+= vf_boxblur.o
+OBJS-$(CONFIG_CHROMAKEY_FILTER)  += vf_chromakey.o
 OBJS-$(CONFIG_CODECVIEW_FILTER)  += vf_codecview.o
 OBJS-$(CONFIG_COLORBALANCE_FILTER)   += vf_colorbalance.o
 OBJS-$(CONFIG_COLORCHANNELMIXER_FILTER)  += vf_colorchannelmixer.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index cab4564..5075fca 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -124,6 +124,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(BLACKFRAME, blackframe, vf);
 REGISTER_FILTER(BLEND,  blend,  vf);
 REGISTER_FILTER(BOXBLUR,boxblur,vf);
+REGISTER_FILTER(CHROMAKEY,  chromakey,  vf);
 REGISTER_FILTER(CODECVIEW,  codecview,  vf);
 REGISTER_FILTER(COLORBALANCE,   colorbalance,   vf);
 REGISTER_FILTER(COLORCHANNELMIXER, colorchannelmixer, vf);
diff --git a/libavfilter/version.h b/libavfilter/version.h
index e918184..9d44fd0 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVFILTER_VERSION_MAJOR   6
-#define LIBAVFILTER_VERSION_MINOR   5
+#define LIBAVFILTER_VERSION_MINOR   6
 #define LIBAVFILTER_VERSION_MICRO 100
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
diff --git a/libavfilter/vf_chromakey.c b/libavfilter/vf_chromakey.c
new file mode 100644
index 000..4809e39
--- /dev/null
+++ b/libavfilter/vf_chromakey.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2015 Timo Rothenpieler 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 

Re: [FFmpeg-devel] [PATCH] avfilter/vf_chromakey: Add chromakey video filter

2015-09-18 Thread Paul B Mahol
On 9/18/15, Timo Rothenpieler  wrote:
> ---
>  Changelog  |   1 +
>  MAINTAINERS|   1 +
>  doc/filters.texi   |  45 ++
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/version.h  |   2 +-
>  libavfilter/vf_chromakey.c | 211
> +
>  7 files changed, 261 insertions(+), 1 deletion(-)
>  create mode 100644 libavfilter/vf_chromakey.c
>
> diff --git a/Changelog b/Changelog
> index 653317f..db9064d 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -7,6 +7,7 @@ version :
>  - ocr filter
>  - alimiter filter
>  - stereowiden filter
> +- chromakey filter
>
>
>  version 2.8:
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 4a50430..12da0cd 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -359,6 +359,7 @@ Filters:
>avf_avectorscope.cPaul B Mahol
>avf_showcqt.c Muhammad Faiz
>vf_blend.cPaul B Mahol
> +  vf_chromakey.cTimo Rothenpieler
>vf_colorchannelmixer.cPaul B Mahol
>vf_colorbalance.c Paul B Mahol
>vf_colorkey.c Timo Rothenpieler
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 4a55e59..0446204 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -3556,6 +3556,51 @@
> boxblur=luma_radius=min(h\,w)/10:luma_power=1:chroma_radius=min(cw\,ch)/10:chrom
>  @end example
>  @end itemize
>
> +@section chromakey
> +YUV colorspace color/chroma keying.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +@item color
> +The color which will be replaced with transparency.
> +
> +@item similarity
> +Similarity percentage with the key color.
> +
> +0.01 matches only the exact key color, while 1.0 matches everything.
> +
> +@item blend
> +Blend percentage.
> +
> +0.0 makes pixels either fully transparent, or not transparent at all.
> +
> +Higher values result in semi-transparent pixels, with a higher transparency
> +the more similar the pixels color is to the key color.
> +
> +@item yuv
> +Signals that the color passed is already in YUV instead of RGB.
> +
> +Litteral colors like "green" or "red" don't make sense with this enabled
> anymore.
> +This can be used to pass exact YUV values as hexadecimal numbers.
> +@end table
> +
> +@subsection Examples
> +
> +@itemize
> +@item
> +Make every green pixel in the input image transparent:
> +@example
> +ffmpeg -i input.png -vf chromakey=green out.png
> +@end example
> +
> +@item
> +Overlay a greenscreen-video on top of a static black background.
> +@example
> +ffmpeg -f lavfi -i color=c=black:s=1280x720 -i video.mp4 -shortest
> -filter_complex
> "[1:v]chromakey=0x70de77:0.1:0.2[ckout];[0:v][ckout]overlay[out]" -map
> "[out]" output.mkv
> +@end example
> +@end itemize
> +
>  @section codecview
>
>  Visualize information exported by some codecs.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 05effd6..2aa8603 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -102,6 +102,7 @@ OBJS-$(CONFIG_BLACKDETECT_FILTER)+=
> vf_blackdetect.o
>  OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
>  OBJS-$(CONFIG_BLEND_FILTER)  += vf_blend.o dualinput.o
> framesync.o
>  OBJS-$(CONFIG_BOXBLUR_FILTER)+= vf_boxblur.o
> +OBJS-$(CONFIG_CHROMAKEY_FILTER)  += vf_chromakey.o
>  OBJS-$(CONFIG_CODECVIEW_FILTER)  += vf_codecview.o
>  OBJS-$(CONFIG_COLORBALANCE_FILTER)   += vf_colorbalance.o
>  OBJS-$(CONFIG_COLORCHANNELMIXER_FILTER)  += vf_colorchannelmixer.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index cab4564..5075fca 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -124,6 +124,7 @@ void avfilter_register_all(void)
>  REGISTER_FILTER(BLACKFRAME, blackframe, vf);
>  REGISTER_FILTER(BLEND,  blend,  vf);
>  REGISTER_FILTER(BOXBLUR,boxblur,vf);
> +REGISTER_FILTER(CHROMAKEY,  chromakey,  vf);
>  REGISTER_FILTER(CODECVIEW,  codecview,  vf);
>  REGISTER_FILTER(COLORBALANCE,   colorbalance,   vf);
>  REGISTER_FILTER(COLORCHANNELMIXER, colorchannelmixer, vf);
> diff --git a/libavfilter/version.h b/libavfilter/version.h
> index e918184..9d44fd0 100644
> --- a/libavfilter/version.h
> +++ b/libavfilter/version.h
> @@ -30,7 +30,7 @@
>  #include "libavutil/version.h"
>
>  #define LIBAVFILTER_VERSION_MAJOR   6
> -#define LIBAVFILTER_VERSION_MINOR   5
> +#define LIBAVFILTER_VERSION_MINOR   6
>  #define LIBAVFILTER_VERSION_MICRO 100
>
>  #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
> diff --git a/libavfilter/vf_chromakey.c b/libavfilter/vf_chromakey.c
> new file mode 100644
> index 000..4809e39
> --- /dev/null
> +++ b/libavfilter/vf_chromakey.c
> @@ 

Re: [FFmpeg-devel] [PATCH] avfilter/vf_chromakey: Add chromakey video filter

2015-09-18 Thread Paul B Mahol
On 9/18/15, Paul B Mahol  wrote:
> On 9/18/15, Timo Rothenpieler  wrote:
>> ---
>>  Changelog  |   1 +
>>  MAINTAINERS|   1 +
>>  doc/filters.texi   |  45 ++
>>  libavfilter/Makefile   |   1 +
>>  libavfilter/allfilters.c   |   1 +
>>  libavfilter/version.h  |   2 +-
>>  libavfilter/vf_chromakey.c | 211
>> +
>>  7 files changed, 261 insertions(+), 1 deletion(-)
>>  create mode 100644 libavfilter/vf_chromakey.c
>>
> Otherwise looks good, gonna test it.
>

Have you explored way how to handle borders?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter/vf_chromakey: Add chromakey video filter

2015-09-18 Thread Timo Rothenpieler


Have you explored way how to handle borders?


You mean the outmost pixels, where the calculation is slightly inaccurate?
Or the greenscreen spilling into the object because of light reflections?

The first could be addressed by adjusting the value for the 
out-of-bounds pixels.


The later is harder to fix, and maybe even needs another filter for 
spill reduction which filters out the greenscreen color.


You can already get quite good results by playing with the similarity 
and blend values, eliminating most of the spill.





signature.asc
Description: OpenPGP digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter/vf_chromakey: Add chromakey video filter

2015-09-18 Thread Paul B Mahol
On 9/18/15, Timo Rothenpieler  wrote:
>>
>> Have you explored way how to handle borders?
>
> You mean the outmost pixels, where the calculation is slightly inaccurate?
> Or the greenscreen spilling into the object because of light reflections?

Yes, the first one.

>
> The first could be addressed by adjusting the value for the
> out-of-bounds pixels.

This one is quite more obvious. Gonna write patch?

>
> The later is harder to fix, and maybe even needs another filter for
> spill reduction which filters out the greenscreen color.
>
> You can already get quite good results by playing with the similarity
> and blend values, eliminating most of the spill.
>
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel