Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-14 Thread Wei Gao
2015-10-14 14:31 GMT+08:00 Timo Rothenpieler :

> Hi
>>
>> I have check the error, for some card, yes, just like what I said above,
>> some cards does not support double type, so we must check the opencl
>> extension: cl_khr_fp64 before the kernel compile. If the device support,
>> we use GPU, else, we use CPU or use float type, Is it OK?
>>
>> Thanks
>> Best regards
>>
>>
> Of course, if there's a way to only fall back to floats if doubles are not
> available, that'd be preferable.
>
Hi

A simple idea is that

1. Check whether the device support cl_khr_fp64
2. Set a macro in build option. you can reference the unsharp filter, the
code is as follow:

snprintf(build_opts, 96, "-D LU_RADIUS_X=%d -D LU_RADIUS_Y=%d -D
CH_RADIUS_X=%d -D CH_RADIUS_Y=%d",
2*unsharp->luma.steps_x+1, 2*unsharp->luma.steps_y+1,
2*unsharp->chroma.steps_x+1, 2*unsharp->chroma.steps_y+1);
unsharp->opencl_ctx.program = av_opencl_compile("unsharp", build_opts);

use the macro to decide whether to use double or float at the compile stage

Do you think it is OK?

Thanks
Best regards
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-14 Thread Timo Rothenpieler

Hi

I have check the error, for some card, yes, just like what I said above,
some cards does not support double type, so we must check the opencl
extension: cl_khr_fp64 before the kernel compile. If the device support,
we use GPU, else, we use CPU or use float type, Is it OK?

Thanks
Best regards



Of course, if there's a way to only fall back to floats if doubles are 
not available, that'd be preferable.




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 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-13 Thread Timothy Gu
On Tue, Oct 13, 2015 at 3:28 AM Timo Rothenpieler 
wrote:

> > Hi
> >
> > I use your filter, but the kernel can't pass the compile, you should
> consider the "double" type in the kernel, some GPU card does not support
> double type
> > I add "#pragma OPENCL_EXTENSION cl_khr_fp64: enable " to the kernel, but
> it does not works
> >
> > I will check the error tomorrow
>
> I tested this filter on Nvidia on Linux, using driver 355 and on the
> Intel CPU-based OpenCL SDK so far.
> Using floats potentially has an impact on the keying quality.
>

Segfaults here with ffmpeg -f lavfi -i allrgb -vf chromakey=green:opencl=1
-f null -

gdb doesn't give anything useful:

$ gdb ffmpeg_g
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ffmpeg_g...done.
(gdb) r -loglevel debug -f lavfi -i allrgb -vf chromakey=green:opencl=1 -f
null -
Starting program: /home/timothy-gu/ffmpeg/ffmpeg/ffmpeg_g -loglevel debug
-f lavfi -i allrgb -vf chromakey=green:opencl=1 -f null -
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
ffmpeg version N-75973-g3cff255 Copyright (c) 2000-2015 the FFmpeg
developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac
--enable-libfreetype --enable-libmp3lame --enable-libopus
--enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264
--enable-nonfree --extra-ldflags='-L/opt/intel/opencl-1.2-5.0.0.57/lib64
-Wl,-rpath,/opt/intel/opencl-1.2-5.0.0.57/lib64' --enable-opencl
  libavutil  55.  3.100 / 55.  3.100
  libavcodec 57.  5.100 / 57.  5.100
  libavformat57.  3.100 / 57.  3.100
  libavdevice57.  0.100 / 57.  0.100
  libavfilter 6. 11.100 /  6. 11.100
  libswscale  4.  0.100 /  4.  0.100
  libswresample   2.  0.100 /  2.  0.100
  libpostproc54.  0.100 / 54.  0.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging
level) with argument 'debug'.
Reading option '-f' ... matched as option 'f' (force format) with argument
'lavfi'.
Reading option '-i' ... matched as input file with argument 'allrgb'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with
argument 'chromakey=green:opencl=1'.
Reading option '-f' ... matched as option 'f' (force format) with argument
'null'.
Reading option '-' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file allrgb.
Applying option f (force format) with argument lavfi.
Successfully parsed a group of options.
Opening an input file: allrgb.
detected 4 logical cores
[New Thread 0x7fffed3b9700 (LWP 13438)]
[New Thread 0x7fffecbb8700 (LWP 13439)]
[New Thread 0x7fffec3b7700 (LWP 13440)]
[New Thread 0x7fffebbb6700 (LWP 13441)]
[New Thread 0x7fffeb3b5700 (LWP 13442)]
[Parsed_allrgb_0 @ 0x1bb0fa0] size:4096x4096 rate:25/1 duration:-1.00
sar:1/1
[AVFilterGraph @ 0x1baff00] query_formats: 2 queried, 1 merged, 0 already
done, 0 delayed
[lavfi @ 0x1baf700] All info found
Input #0, lavfi, from 'allrgb':
  Duration: N/A, start: 0.00, bitrate: N/A
Stream #0:0, 1, 1/25: Video: rawvideo, 1 reference frame (RGB[24] /
0x18424752), rgb24, 4096x4096 [SAR 1:1 DAR 1:1], 1/25, 25 tbr, 25 tbn, 25
tbc
Successfully opened the file.
Parsing a group of options: output file -.
Applying option vf (set video filters) with argument
chromakey=green:opencl=1.
Applying option f (force format) with argument null.
Successfully parsed a group of options.
Opening an output file: -.
Successfully opened the file.
[New Thread 0x7fffe4bb2700 (LWP 13443)]
[New Thread 0x7fffe43b1700 (LWP 13444)]
[New Thread 0x7fffe3bb0700 (LWP 13445)]
[New Thread 0x7fffe33af700 (LWP 13446)]
[New Thread 0x7fffe2bae700 (LWP 13447)]
[Parsed_chromakey_0 @ 0x1bb52a0] Setting 'color' to value 'green'
[Parsed_chromakey_0 @ 0x1bb52a0] Setting 'opencl' to value '1'
[OPENCLUTILS @ 0x1510100] Could not get device ID: DEVICE NOT FOUND:
[OPENCLUTILS @ 0x1510100] Platform Name: Intel(R) Corporation, Device Name:
Intel(R) Core(TM) i7-4510U CPU @ 2.00GHz
[New Thread 0x7fffdb6b8700 (LWP 13448)]
[New Thread 

Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-13 Thread highgod0401

From: Timo Rothenpieler
Date: 2015-10-10 17:47
To: FFmpeg development discussions and patches
CC: highgod0401
Subject: Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL 
acceleration
> Could you please fix it?
> 
> Thanks
> 
> Best regards

curl
https://github.com/BtbN/FFmpeg/commit/29294c283a656cf809461cbae21d612b5a0f2159.patch
| git apply

That works for me, the patch is not in git format-patch format, so git
am can't apply it.

I also attached the two patches in format-patch format, in case you
realy want to use git am.

Hi

I use your filter, but the kernel can't pass the compile, you should consider 
the "double" type in the kernel, some GPU card does not support double type
I add "#pragma OPENCL_EXTENSION cl_khr_fp64: enable " to the kernel, but it 
does not works

I will check the error tomorrow

Thanks
Best regards
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-13 Thread Wei Gao
2015-10-13 18:27 GMT+08:00 Timo Rothenpieler :

> Hi
>>
>> I use your filter, but the kernel can't pass the compile, you should
>> consider the "double" type in the kernel, some GPU card does not support
>> double type
>> I add "#pragma OPENCL_EXTENSION cl_khr_fp64: enable " to the kernel, but
>> it does not works
>>
>> I will check the error tomorrow
>>
>
> I tested this filter on Nvidia on Linux, using driver 355 and on the Intel
> CPU-based OpenCL SDK so far.
> Using floats potentially has an impact on the keying quality.
>
Hi

I have check the error, for some card, yes, just like what I said above,
some cards does not support double type, so we must check the opencl
extension: cl_khr_fp64 before the kernel compile. If the device support, we
use GPU, else, we use CPU or use float type, Is it OK?

Thanks
Best regards
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-11 Thread highgod0401

From: Timo Rothenpieler
Date: 2015-10-10 17:47
To: FFmpeg development discussions and patches
CC: highgod0401
Subject: Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL 
acceleration
> Could you please fix it?
> 
> Thanks
> 
> Best regards

curl
https://github.com/BtbN/FFmpeg/commit/29294c283a656cf809461cbae21d612b5a0f2159.patch
| git apply

That works for me, the patch is not in git format-patch format, so git
am can't apply it.

I also attached the two patches in format-patch format, in case you
realy want to use git am.

Hi
I will check them. 

Thanks
Best regards
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-10 Thread Timo Rothenpieler
> Could you please fix it?
> 
> Thanks
> 
> Best regards

curl
https://github.com/BtbN/FFmpeg/commit/29294c283a656cf809461cbae21d612b5a0f2159.patch
| git apply

That works for me, the patch is not in git format-patch format, so git
am can't apply it.

I also attached the two patches in format-patch format, in case you
realy want to use git am.
From e231220729cb956523a869006932cd2e2680e621 Mon Sep 17 00:00:00 2001
From: Timo Rothenpieler 
Date: Thu, 24 Sep 2015 14:03:26 +0200
Subject: [PATCH 1/2] avutil/opencl: Display build log on compile error

---
 libavutil/opencl.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/libavutil/opencl.c b/libavutil/opencl.c
index 8686493..2469ba4 100644
--- a/libavutil/opencl.c
+++ b/libavutil/opencl.c
@@ -452,8 +452,9 @@ cl_program av_opencl_compile(const char *program_name, 
const char *build_opts)
 cl_int status;
 int kernel_code_idx = 0;
 const char *kernel_source;
-size_t kernel_code_len;
+size_t kernel_code_len, build_log_len;
 char* ptr = NULL;
+char* build_log = NULL;
 cl_program program = NULL;
 
 LOCK_OPENCL;
@@ -485,6 +486,19 @@ cl_program av_opencl_compile(const char *program_name, 
const char *build_opts)
 if (status != CL_SUCCESS) {
 av_log(_ctx, AV_LOG_ERROR,
"Compilation failed with OpenCL program: %s\n", program_name);
+
+status = clGetProgramBuildInfo(program, opencl_ctx.device_id, 
CL_PROGRAM_BUILD_LOG, 0, NULL, _log_len);
+if (status != CL_SUCCESS)
+goto end;
+
+build_log = av_malloc(build_log_len);
+
+status = clGetProgramBuildInfo(program, opencl_ctx.device_id, 
CL_PROGRAM_BUILD_LOG, build_log_len, build_log, NULL);
+if (status != CL_SUCCESS)
+goto end;
+
+av_log(_ctx, AV_LOG_DEBUG, "OpenCL Build Log:\n%s\n", 
build_log);
+
 program = NULL;
 goto end;
 }
@@ -492,6 +506,7 @@ cl_program av_opencl_compile(const char *program_name, 
const char *build_opts)
 opencl_ctx.kernel_code[kernel_code_idx].is_compiled = 1;
 end:
 UNLOCK_OPENCL;
+av_free(build_log);
 return program;
 }
 
-- 
2.6.0

From b8fb80312b925e94bd33cca49c21c222b572d24d Mon Sep 17 00:00:00 2001
From: Timo Rothenpieler 
Date: Thu, 24 Sep 2015 16:59:04 +0200
Subject: [PATCH 2/2] avfilter/vf_chromakey: Add OpenCL acceleration

Signed-off-by: Timo Rothenpieler 
---
 doc/filters.texi  |   5 +
 libavfilter/chromakey_opencl_kernel.h |  98 +++
 libavfilter/opencl_allkernels.c   |   2 +
 libavfilter/vf_chromakey.c| 179 +-
 4 files changed, 283 insertions(+), 1 deletion(-)
 create mode 100644 libavfilter/chromakey_opencl_kernel.h

diff --git a/doc/filters.texi b/doc/filters.texi
index 9ab7d43..1270cc9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3735,6 +3735,11 @@ 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.
+
+@item opencl
+If set to 1, specify using OpenCL capabilities, only available if
+FFmpeg was configured with @code{--enable-opencl}. Default value is 0.
+
 @end table
 
 @subsection Examples
diff --git a/libavfilter/chromakey_opencl_kernel.h 
b/libavfilter/chromakey_opencl_kernel.h
new file mode 100644
index 000..56bbc79
--- /dev/null
+++ b/libavfilter/chromakey_opencl_kernel.h
@@ -0,0 +1,98 @@
+/*
+ * 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 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFILTER_CHROMAKEY_OPENCL_KERNEL_H
+#define AVFILTER_CHROMAKEY_OPENCL_KERNEL_H
+
+#include "libavutil/opencl.h"
+
+const char *ff_kernel_chromakey_opencl = AV_OPENCL_KERNEL(
+
+inline unsigned char get_pixel(global unsigned char *src,
+   int x,
+   int y,
+   int w,
+   int h,
+   int linesize,
+   int hsub_log2,
+   int 

Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-09 Thread Timo Rothenpieler


Using this sample: https://btbn.de/files/chromakey_sample.mp4

ffmpeg -f lavfi -i color=c=black:s=1280x720 -i chromakey_sample.mp4 -an
-c:v libx264 -preset veryfast -crf 18 -shortest -filter_complex
"[1:v]chromakey=0x70de77:0.1:0.2:0:1[ckout];[0:v][ckout]overlay[out]"
-map "[out]" -y output.mkv

The last parameter to the chromakey filter enables opencl acceleration.

Hi,

Could you please send the patch as attachments? I merge the code, but some 
compile errors occur.

Thanks
Best regards



You can pull from my github, the patches are in the chromakey branch:

https://github.com/BtbN/FFmpeg/tree/chromakey

If you want just the chromakey patch itself:

https://github.com/BtbN/FFmpeg/commit/29294c283a656cf809461cbae21d612b5a0f2159.patch



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 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-09 Thread highgod0401

From: Timo Rothenpieler
Date: 2015-10-09 16:41
To: FFmpeg development discussions and patches
CC: highgod0401
Subject: Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL 
acceleration
>
> Using this sample: https://btbn.de/files/chromakey_sample.mp4
>
> ffmpeg -f lavfi -i color=c=black:s=1280x720 -i chromakey_sample.mp4 -an
> -c:v libx264 -preset veryfast -crf 18 -shortest -filter_complex
> "[1:v]chromakey=0x70de77:0.1:0.2:0:1[ckout];[0:v][ckout]overlay[out]"
> -map "[out]" -y output.mkv
>
> The last parameter to the chromakey filter enables opencl acceleration.
>
> Hi,
>
> Could you please send the patch as attachments? I merge the code, but some 
> compile errors occur.
>
> Thanks
> Best regards
>

You can pull from my github, the patches are in the chromakey branch:

https://github.com/BtbN/FFmpeg/tree/chromakey

If you want just the chromakey patch itself:

https://github.com/BtbN/FFmpeg/commit/29294c283a656cf809461cbae21d612b5a0f2159.patch

Hi
OK, I will test as soon as possible

Thanks
Best regards
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-09 Thread highgod0401

From: Timo Rothenpieler
Date: 2015-10-09 16:41
To: FFmpeg development discussions and patches
CC: highgod0401
Subject: Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL 
acceleration
>
> Using this sample: https://btbn.de/files/chromakey_sample.mp4
>
> ffmpeg -f lavfi -i color=c=black:s=1280x720 -i chromakey_sample.mp4 -an
> -c:v libx264 -preset veryfast -crf 18 -shortest -filter_complex
> "[1:v]chromakey=0x70de77:0.1:0.2:0:1[ckout];[0:v][ckout]overlay[out]"
> -map "[out]" -y output.mkv
>
> The last parameter to the chromakey filter enables opencl acceleration.
>
> Hi,
>
> Could you please send the patch as attachments? I merge the code, but some 
> compile errors occur.
>
> Thanks
> Best regards
>

You can pull from my github, the patches are in the chromakey branch:

https://github.com/BtbN/FFmpeg/tree/chromakey

If you want just the chromakey patch itself:

https://github.com/BtbN/FFmpeg/commit/29294c283a656cf809461cbae21d612b5a0f2159.patch

Hi

I downloaded and merged the patch again, but the error still exists as follow:

$ git am opencl_chromakey.patch
Applying: avfilter/vf_chromakey: Add OpenCL acceleration
fatal: corrupt patch at line 380
Patch failed at 0001 avfilter/vf_chromakey: Add OpenCL acceleration
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".

I check the code,
These codes are in the patch of corrupt patch at line 380.
@@ -192,6 +368,7 @@ AVFilter ff_vf_chromakey = {
 .priv_size = sizeof(ChromakeyContext),
 .priv_class= _class,
 .init  = initialize_chromakey,
+.uninit= uninitialize_chromakey,
 .query_formats = query_formats,
 .inputs= chromakey_inputs,
 .outputs   = chromakey_outputs,
the following codes are the latest ffmpeg master branch codes.
AVFilter ff_vf_chromakey = {
.name  = "chromakey",
.description   = NULL_IF_CONFIG_SMALL("Turns a certain color into 
transparency. Operates on YUV colors."),
.priv_size = sizeof(ChromakeyContext),
.priv_class= _class,
.init  = initialize_chromakey,
.query_formats = query_formats,
.inputs= chromakey_inputs,
.outputs   = chromakey_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | 
AVFILTER_FLAG_SLICE_THREADS,
};
I think this is the reason why the conflict occurs.

Could you please fix it?

Thanks

Best regards
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-10-07 Thread highgod0401

From: Timo Rothenpieler
Date: 2015-09-30 19:27
To: FFmpeg development discussions and patches
Subject: Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL 
acceleration
>> ping once again
>>
>> Hi
> Could you describe how to verify it, and how can I test it?
> 
> Thanks
> Best regards
> 

Using this sample: https://btbn.de/files/chromakey_sample.mp4

ffmpeg -f lavfi -i color=c=black:s=1280x720 -i chromakey_sample.mp4 -an
-c:v libx264 -preset veryfast -crf 18 -shortest -filter_complex
"[1:v]chromakey=0x70de77:0.1:0.2:0:1[ckout];[0:v][ckout]overlay[out]"
-map "[out]" -y output.mkv

The last parameter to the chromakey filter enables opencl acceleration.

Hi,

Could you please send the patch as attachments? I merge the code, but some 
compile errors occur.

Thanks
Best regards




___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-09-30 Thread Timo Rothenpieler
> I'm not quite sure of what I think of this software/opencl hybrid
> approach. On one hand, it's good that they share the "user interface"
> (options etc.). On the other hand, the OpenCL part duplicates the
> entire actual filter code. And unlike with asm, there's no good way to
> test that they do the same thing. Also, the amount of OpenCL
> boilerplate looks a bit high, considering that it already uses shared
> OpenCL utility code.
> 
> But since there are already 2 other filters which do this, there's not
> much of a reason to reject this, assuming it works and it's reasonably
> equivalent to software filtering.

Yes, it's not exactly pretty. I thought about ways to add more
abstraction, but most filters are way to different in how they work and
what parameters they require.

If more simple filters gain OpenCL support, it should be possible to add
a basic "Run CL kernel on frame" abstraction which reduces the amount of
boilerplate needed.



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 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-09-30 Thread wm4
On Thu, 24 Sep 2015 17:12:25 +0200
Timo Rothenpieler  wrote:

> Signed-off-by: Timo Rothenpieler 
> ---
>  doc/filters.texi  |   5 +
>  libavfilter/chromakey_opencl_kernel.h |  98 +++
>  libavfilter/opencl_allkernels.c   |   2 +
>  libavfilter/vf_chromakey.c| 179 
> +-
>  4 files changed, 283 insertions(+), 1 deletion(-)
>  create mode 100644 libavfilter/chromakey_opencl_kernel.h
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 044876c..4faf4b9 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -3734,6 +3734,11 @@ 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.
> +
> +@item opencl
> +If set to 1, specify using OpenCL capabilities, only available if
> +FFmpeg was configured with @code{--enable-opencl}. Default value is 0.
> +
>  @end table
>  
>  @subsection Examples
> diff --git a/libavfilter/chromakey_opencl_kernel.h 
> b/libavfilter/chromakey_opencl_kernel.h
> new file mode 100644
> index 000..56bbc79
> --- /dev/null
> +++ b/libavfilter/chromakey_opencl_kernel.h
> @@ -0,0 +1,98 @@
> +/*
> + * 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 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#ifndef AVFILTER_CHROMAKEY_OPENCL_KERNEL_H
> +#define AVFILTER_CHROMAKEY_OPENCL_KERNEL_H
> +
> +#include "libavutil/opencl.h"
> +
> +const char *ff_kernel_chromakey_opencl = AV_OPENCL_KERNEL(
> +
> +inline unsigned char get_pixel(global unsigned char *src,
> +   int x,
> +   int y,
> +   int w,
> +   int h,
> +   int linesize,
> +   int hsub_log2,
> +   int vsub_log2,
> +   unsigned char def)
> +{
> +if (x < 0 || x >= w || y < 0 || x >= w)
> +return def;
> +
> +x >>= hsub_log2;
> +y >>= vsub_log2;
> +
> +return src[linesize * y + x];
> +}
> +
> +kernel void chromakey(global unsigned char *src_u,
> +  global unsigned char *src_v,
> +  global unsigned char *dst,
> +  int linesize_u,
> +  int linesize_v,
> +  int linesize_a,
> +  int height,
> +  int width,
> +  int hsub_log2,
> +  int vsub_log2,
> +  unsigned char chromakey_u,
> +  unsigned char chromakey_v,
> +  float similarity,
> +  float blend
> + )
> +{
> +int x = get_global_id(0);
> +int y = get_global_id(1);
> +unsigned char res;
> +
> +int xo, yo, du, dv;
> +double diff = 0.0;
> +
> +if (x >= width || y >= height)
> +return;
> +
> +for (yo = 0; yo < 3; yo++) {
> +for (xo = 0; xo < 3; xo++) {
> +du = get_pixel(src_u, x + xo - 1, y + yo - 1, width, height, 
> linesize_u, hsub_log2, vsub_log2, chromakey_u);
> +dv = get_pixel(src_v, x + xo - 1, y + yo - 1, width, height, 
> linesize_v, hsub_log2, vsub_log2, chromakey_v);
> +
> +du -= chromakey_u;
> +dv -= chromakey_v;
> +
> +diff += sqrt((du * du + dv * dv) / (double)(255.0 * 255.0));
> +}
> +}
> +
> +diff /= 9.0;
> +
> +if (blend > 0.0001) {
> +res = clamp((diff - similarity) / blend, 0.0, 1.0) * 255.0;
> +} else {
> +res = (diff > similarity) ? 255 : 0;
> +}
> +
> +dst[linesize_a * y + x] = res;
> +}
> +
> +);
> +
> +#endif /* AVFILTER_CHROMAKEY_OPENCL_KERNEL_H */
> diff --git a/libavfilter/opencl_allkernels.c b/libavfilter/opencl_allkernels.c
> index 6d80fa8..fc05e66 100644
> --- a/libavfilter/opencl_allkernels.c
> +++ b/libavfilter/opencl_allkernels.c
> @@ -23,6 +23,7 @@
>  #include "libavutil/opencl.h"
>  #include "deshake_opencl_kernel.h"
>  

Re: [FFmpeg-devel] [PATCH 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-09-30 Thread Timo Rothenpieler
>> ping once again
>>
>> Hi
> Could you describe how to verify it, and how can I test it?
> 
> Thanks
> Best regards
> 

Using this sample: https://btbn.de/files/chromakey_sample.mp4

ffmpeg -f lavfi -i color=c=black:s=1280x720 -i chromakey_sample.mp4 -an
-c:v libx264 -preset veryfast -crf 18 -shortest -filter_complex
"[1:v]chromakey=0x70de77:0.1:0.2:0:1[ckout];[0:v][ckout]overlay[out]"
-map "[out]" -y output.mkv

The last parameter to the chromakey filter enables opencl acceleration.



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 3/3][RFC] avfilter/vf_chromakey: Add OpenCL acceleration

2015-09-29 Thread Timo Rothenpieler
> Signed-off-by: Timo Rothenpieler 
> ---
>  doc/filters.texi  |   5 +
>  libavfilter/chromakey_opencl_kernel.h |  98 +++
>  libavfilter/opencl_allkernels.c   |   2 +
>  libavfilter/vf_chromakey.c| 179 
> +-
>  4 files changed, 283 insertions(+), 1 deletion(-)
>  create mode 100644 libavfilter/chromakey_opencl_kernel.h
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 044876c..4faf4b9 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -3734,6 +3734,11 @@ 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.
> +
> +@item opencl
> +If set to 1, specify using OpenCL capabilities, only available if
> +FFmpeg was configured with @code{--enable-opencl}. Default value is 0.
> +
>  @end table
>  
>  @subsection Examples
> diff --git a/libavfilter/chromakey_opencl_kernel.h 
> b/libavfilter/chromakey_opencl_kernel.h
> new file mode 100644
> index 000..56bbc79
> --- /dev/null
> +++ b/libavfilter/chromakey_opencl_kernel.h
> @@ -0,0 +1,98 @@
> +/*
> + * 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 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#ifndef AVFILTER_CHROMAKEY_OPENCL_KERNEL_H
> +#define AVFILTER_CHROMAKEY_OPENCL_KERNEL_H
> +
> +#include "libavutil/opencl.h"
> +
> +const char *ff_kernel_chromakey_opencl = AV_OPENCL_KERNEL(
> +
> +inline unsigned char get_pixel(global unsigned char *src,
> +   int x,
> +   int y,
> +   int w,
> +   int h,
> +   int linesize,
> +   int hsub_log2,
> +   int vsub_log2,
> +   unsigned char def)
> +{
> +if (x < 0 || x >= w || y < 0 || x >= w)
> +return def;
> +
> +x >>= hsub_log2;
> +y >>= vsub_log2;
> +
> +return src[linesize * y + x];
> +}
> +
> +kernel void chromakey(global unsigned char *src_u,
> +  global unsigned char *src_v,
> +  global unsigned char *dst,
> +  int linesize_u,
> +  int linesize_v,
> +  int linesize_a,
> +  int height,
> +  int width,
> +  int hsub_log2,
> +  int vsub_log2,
> +  unsigned char chromakey_u,
> +  unsigned char chromakey_v,
> +  float similarity,
> +  float blend
> + )
> +{
> +int x = get_global_id(0);
> +int y = get_global_id(1);
> +unsigned char res;
> +
> +int xo, yo, du, dv;
> +double diff = 0.0;
> +
> +if (x >= width || y >= height)
> +return;
> +
> +for (yo = 0; yo < 3; yo++) {
> +for (xo = 0; xo < 3; xo++) {
> +du = get_pixel(src_u, x + xo - 1, y + yo - 1, width, height, 
> linesize_u, hsub_log2, vsub_log2, chromakey_u);
> +dv = get_pixel(src_v, x + xo - 1, y + yo - 1, width, height, 
> linesize_v, hsub_log2, vsub_log2, chromakey_v);
> +
> +du -= chromakey_u;
> +dv -= chromakey_v;
> +
> +diff += sqrt((du * du + dv * dv) / (double)(255.0 * 255.0));
> +}
> +}
> +
> +diff /= 9.0;
> +
> +if (blend > 0.0001) {
> +res = clamp((diff - similarity) / blend, 0.0, 1.0) * 255.0;
> +} else {
> +res = (diff > similarity) ? 255 : 0;
> +}
> +
> +dst[linesize_a * y + x] = res;
> +}
> +
> +);
> +
> +#endif /* AVFILTER_CHROMAKEY_OPENCL_KERNEL_H */
> diff --git a/libavfilter/opencl_allkernels.c b/libavfilter/opencl_allkernels.c
> index 6d80fa8..fc05e66 100644
> --- a/libavfilter/opencl_allkernels.c
> +++ b/libavfilter/opencl_allkernels.c
> @@ -23,6 +23,7 @@
>  #include "libavutil/opencl.h"
>  #include "deshake_opencl_kernel.h"
>  #include "unsharp_opencl_kernel.h"
> +#include "chromakey_opencl_kernel.h"
>  #endif