[FFmpeg-devel] [OPENCL] a idea to get a better performance of the OPENCL video filter

weixuan wang batmanwwx at gmail.com
Tue Jun 25 06:01:03 CEST 2013


* *

*Hi:*

* *

*I found that there are two video filters having the OPENCL supports in the
latest trunk. The two video filters are deshake video filter and unsharp
video filter. when I used all of the two filters with the OPENCL, i find
out a idea to get a better performance of them.*

*In these OPENCL filters, they first copy the input frame buffer into the
input OPENCL buffer like this:*

*av_opencl_buffer_write_image(unsharp->opencl_ctx.cl_inbuf,*

*unsharp->opencl_ctx.cl_inbuf_size,0, in->data,
unsharp->opencl_ctx.in_plane_size,*

*unsharp->opencl_ctx.plane_num);*

*the in->data is the input frame buffer and the
unsharp->opencl_ctx.cl_inbuf is the input OPENCL buffer.*

*They use the input OPENCL buffer to run the kernel and get the output
OPENCL buffer. They then copy the output OPENCL buffer into the output
frame buffer like this:*

*av_opencl_buffer_read_image(out->data, unsharp->opencl_ctx.out_plane_size,*

*unsharp->opencl_ctx.plane_num, unsharp->opencl_ctx.cl_outbuf,*

*unsharp->opencl_ctx.cl_outbuf_size);*

*the out->data is the output frame buffer and the unsharp->opencl_ctx.cl_
outbuf is the output OPENCL buffer.*

*if I use two or more video filters with the OPENCL, the time of the data
copying will be very long. So I have a idea:*

*if the first video filter is using the OPENCL and the next video filter is
using the OPENCL too, we can remove the output data copying of the first
video filter and the input data copying of the next video filter. we can
directly use the output OPENCL buffer of the first video filter as the
input OPENCL buffer of the next video filter. *

*to implement this function, each OPENCL video filter need a OPENCL buffer
to store the OPENCL share buffer and this buffer must can be transferred to
the next video filter. so I want to use the (uint8_t
*data[AV_NUM_DATA_POINTERS]) of the AVFrame struct to store the OPENCL
share buffer. The data[] of the AVFrame has 8 pointers and only used 4 of
them. So I want to use the data[5] of the AVFrame to store the OPENCL share
buffer of the video filter. *

*the design is :*

*static int filter_frame(AVFilterLink *link, AVFrame *in)*

* return ff_filter_frame(outlink, out);*

*the in is the input AVFrame. *

*the out is the output AVFrame .*

*I use the in->data[5] as the input OPENCL buffer and run the kernel. I
then use the out ->data[5] as the output OPENCL buffer.*

* *

*If the next video filter is using the OPENCL, it can directly use the
in->data[5] as the input OPENCL buffer and run the kernel.*

* *

*This design can save lots of time of the data copying of the OPENCL buffer
in the video filter.*

* *

*Is this design can be accepted? If it can be accepted, I will submit a
patch of it as soon as possible*

* *

*Thx.*

* *


More information about the ffmpeg-devel mailing list