[FFmpeg-cvslog] avutil/hwcontext_cuda: Only handle CUDA hardware frames

2020-04-06 Thread Timo Rothenpieler
ffmpeg | branch: master | Timo Rothenpieler  | Mon Apr  
6 19:33:01 2020 +0200| [30b28f9a83ec095f5684fecb04a42619a6675989] | committer: 
Timo Rothenpieler

avutil/hwcontext_cuda: Only handle CUDA hardware frames

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=30b28f9a83ec095f5684fecb04a42619a6675989
---

 libavutil/hwcontext_cuda.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 95402a1460..58d128a280 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -212,6 +212,10 @@ static int cuda_transfer_data(AVHWFramesContext *ctx, 
AVFrame *dst,
 CUcontext dummy;
 int i, ret;
 
+if ((src->hw_frames_ctx && 
((AVHWFramesContext*)src->hw_frames_ctx->data)->format != AV_PIX_FMT_CUDA) ||
+(dst->hw_frames_ctx && 
((AVHWFramesContext*)dst->hw_frames_ctx->data)->format != AV_PIX_FMT_CUDA))
+return AVERROR(ENOSYS);
+
 ret = CHECK_CU(cu->cuCtxPushCurrent(hwctx->cuda_ctx));
 if (ret < 0)
 return ret;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] scale_vulkan: correctly copy the colormatrix

2020-04-06 Thread Lynne
ffmpeg | branch: master | Lynne  | Mon Apr  6 19:15:51 2020 
+0100| [ca76a5ba1a35e317d0fb327fffe3ad9add6b7e61] | committer: Lynne

scale_vulkan: correctly copy the colormatrix

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ca76a5ba1a35e317d0fb327fffe3ad9add6b7e61
---

 libavfilter/vf_scale_vulkan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_scale_vulkan.c b/libavfilter/vf_scale_vulkan.c
index c5c64ae96c..4f1e484bc9 100644
--- a/libavfilter/vf_scale_vulkan.c
+++ b/libavfilter/vf_scale_vulkan.c
@@ -251,7 +251,7 @@ static av_cold int init_filter(AVFilterContext *ctx, 
AVFrame *in)
 
 for (int y = 0; y < 3; y++)
 for (int x = 0; x < 3; x++)
-par->yuv_matrix[x][y] = tmp_mat[y][x];
+par->yuv_matrix[x][y] = tmp_mat[x][y];
 
 par->yuv_matrix[3][3] = 1.0;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] dnn-layer-mathbinary-test: add unit test for subtraction

2020-04-06 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Sat Mar 21 
10:58:11 2020 +0800| [bbc64799dce727aaa73522353eaf01b11ad79755] | committer: 
Guo, Yejun

dnn-layer-mathbinary-test: add unit test for subtraction

Signed-off-by: Guo, Yejun 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bbc64799dce727aaa73522353eaf01b11ad79755
---

 tests/dnn/.gitignore  |   1 +
 tests/dnn/Makefile|   1 +
 tests/dnn/dnn-layer-mathbinary-test.c | 173 ++
 tests/fate/dnn.mak|   5 +
 4 files changed, 180 insertions(+)

diff --git a/tests/dnn/.gitignore b/tests/dnn/.gitignore
index 5eedaaa56d..d78c5c1aec 100644
--- a/tests/dnn/.gitignore
+++ b/tests/dnn/.gitignore
@@ -2,3 +2,4 @@
 /dnn-layer-depth2space-test
 /dnn-layer-maximum-test
 /dnn-layer-pad-test
+/dnn-layer-mathbinary-test
diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile
index e1bfe3fc91..1f96710821 100644
--- a/tests/dnn/Makefile
+++ b/tests/dnn/Makefile
@@ -1,6 +1,7 @@
 DNNTESTPROGS += dnn-layer-pad
 DNNTESTPROGS += dnn-layer-conv2d
 DNNTESTPROGS += dnn-layer-depth2space
+DNNTESTPROGS += dnn-layer-mathbinary
 DNNTESTPROGS += dnn-layer-maximum
 
 DNNTESTOBJS  := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) 
$(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
diff --git a/tests/dnn/dnn-layer-mathbinary-test.c 
b/tests/dnn/dnn-layer-mathbinary-test.c
new file mode 100644
index 00..1243784b07
--- /dev/null
+++ b/tests/dnn/dnn-layer-mathbinary-test.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2020
+ *
+ * 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
+ */
+
+#include 
+#include 
+#include 
+#include "libavfilter/dnn/dnn_backend_native_layer_mathbinary.h"
+
+#define EPSON 0.1
+
+static int test_sub_broadcast_input0(void)
+{
+DnnLayerMathBinaryParams params;
+DnnOperand operands[2];
+int32_t input_indexes[1];
+float input[1*1*2*3] = {
+-3, 2.5, 2, -2.1, 7.8, 100
+};
+float *output;
+
+params.bin_op = DMBO_SUB;
+params.input0_broadcast = 1;
+params.input1_broadcast = 0;
+params.v = 7.28;
+
+operands[0].data = input;
+operands[0].dims[0] = 1;
+operands[0].dims[1] = 1;
+operands[0].dims[2] = 2;
+operands[0].dims[3] = 3;
+operands[1].data = NULL;
+
+input_indexes[0] = 0;
+dnn_execute_layer_math_binary(operands, input_indexes, 1, ¶ms);
+
+output = operands[1].data;
+for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
+float expected_output = params.v - input[i];
+if (fabs(output[i] - expected_output) > EPSON) {
+printf("at index %d, output: %f, expected_output: %f\n", i, 
output[i], expected_output);
+av_freep(&output);
+return 1;
+}
+}
+
+av_freep(&output);
+return 0;
+}
+
+static int test_sub_broadcast_input1(void)
+{
+DnnLayerMathBinaryParams params;
+DnnOperand operands[2];
+int32_t input_indexes[1];
+float input[1*1*2*3] = {
+-3, 2.5, 2, -2.1, 7.8, 100
+};
+float *output;
+
+params.bin_op = DMBO_SUB;
+params.input0_broadcast = 0;
+params.input1_broadcast = 1;
+params.v = 7.28;
+
+operands[0].data = input;
+operands[0].dims[0] = 1;
+operands[0].dims[1] = 1;
+operands[0].dims[2] = 2;
+operands[0].dims[3] = 3;
+operands[1].data = NULL;
+
+input_indexes[0] = 0;
+dnn_execute_layer_math_binary(operands, input_indexes, 1, ¶ms);
+
+output = operands[1].data;
+for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
+float expected_output = input[i] - params.v;
+if (fabs(output[i] - expected_output) > EPSON) {
+printf("at index %d, output: %f, expected_output: %f\n", i, 
output[i], expected_output);
+av_freep(&output);
+return 1;
+}
+}
+
+av_freep(&output);
+return 0;
+}
+
+static int test_sub_no_broadcast(void)
+{
+DnnLayerMathBinaryParams params;
+DnnOperand operands[3];
+int32_t input_indexes[2];
+float input0[1*1*2*3] = {
+-3, 2.5, 2, -2.1, 7.8, 100
+};
+float input1[1*1*2*3] = {
+-1, 2, 3, -21, 8, 10.0
+};
+float *output;
+
+params.bin_op = DMBO_SUB;
+params.input0_broadcast = 0;
+params.input1_broadcast = 0;
+
+  

[FFmpeg-cvslog] dnn_backend_native_layer_mathbinary: add sub support

2020-04-06 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Fri Mar 20 
20:55:38 2020 +0800| [ffa1561608f513b3a5d3d1568f75126f21bce663] | committer: 
Guo, Yejun

dnn_backend_native_layer_mathbinary: add sub support

more math binary operations will be added here

Signed-off-by: Guo, Yejun 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ffa1561608f513b3a5d3d1568f75126f21bce663
---

 libavfilter/dnn/Makefile   |   1 +
 libavfilter/dnn/dnn_backend_native.h   |   1 +
 .../dnn/dnn_backend_native_layer_mathbinary.c  | 113 +
 .../dnn/dnn_backend_native_layer_mathbinary.h  |  49 +
 libavfilter/dnn/dnn_backend_native_layers.c|   2 +
 tools/python/convert_from_tensorflow.py|  55 +-
 tools/python/convert_header.py |   2 +-
 7 files changed, 219 insertions(+), 4 deletions(-)

diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index 171f00e502..ce529587e1 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -5,6 +5,7 @@ OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_pad
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_conv2d.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_depth2space.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_maximum.o
+OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_mathbinary.o
 
 DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
 
diff --git a/libavfilter/dnn/dnn_backend_native.h 
b/libavfilter/dnn/dnn_backend_native.h
index 53ed22c5e2..5d76d87915 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -41,6 +41,7 @@ typedef enum {
 DLT_DEPTH_TO_SPACE = 2,
 DLT_MIRROR_PAD = 3,
 DLT_MAXIMUM = 4,
+DLT_MATH_BINARY = 5,
 DLT_COUNT
 } DNNLayerType;
 
diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c 
b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
new file mode 100644
index 00..3b8bab82bc
--- /dev/null
+++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2020
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * DNN native backend implementation.
+ */
+
+#include "dnn_backend_native.h"
+#include "libavutil/avassert.h"
+#include "dnn_backend_native_layer_mathbinary.h"
+
+int dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, 
int file_size)
+{
+DnnLayerMathBinaryParams *params;
+int dnn_size = 0;
+int input_index = 0;
+params = av_malloc(sizeof(*params));
+if (!params)
+return 0;
+
+params->bin_op = (int32_t)avio_rl32(model_file_context);
+dnn_size += 4;
+
+params->input0_broadcast = (int32_t)avio_rl32(model_file_context);
+dnn_size += 4;
+if (params->input0_broadcast) {
+params->v = av_int2float(avio_rl32(model_file_context));
+} else {
+layer->input_operand_indexes[input_index] = 
(int32_t)avio_rl32(model_file_context);
+input_index++;
+}
+dnn_size += 4;
+
+params->input1_broadcast = (int32_t)avio_rl32(model_file_context);
+dnn_size += 4;
+if (params->input1_broadcast) {
+params->v = av_int2float(avio_rl32(model_file_context));
+} else {
+layer->input_operand_indexes[input_index] = 
(int32_t)avio_rl32(model_file_context);
+input_index++;
+}
+dnn_size += 4;
+
+layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
+dnn_size += 4;
+layer->params = params;
+
+return dnn_size;
+}
+
+int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t 
*input_operand_indexes,
+ int32_t output_operand_index, const void 
*parameters)
+{
+const DnnOperand *input = &operands[input_operand_indexes[0]];
+DnnOperand *output = &operands[output_operand_index];
+const DnnLayerMathBinaryParams *params = (const DnnLayerMathBinaryParams 
*)parameters;
+int dims_count;
+const float *src;
+float *dst;
+
+for (int i = 0; i < 4; ++i)
+output->dims[i] = input->dims[i];
+
+output->

[FFmpeg-cvslog] avfilter/vf_derain.c: put all the calculation in model file.

2020-04-06 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Fri Mar 20 
20:54:07 2020 +0800| [7e4527e8fa1f8f0bba6a7f7cadc407813f17fbd1] | committer: 
Guo, Yejun

avfilter/vf_derain.c: put all the calculation in model file.

currently, the model outputs the rain, and so need a subtraction
in filter c code to get the final derain result.

I've sent a PR to update the model file and accepted, see at
https://github.com/XueweiMeng/derain_filter/pull/3

Signed-off-by: Guo, Yejun 
Signed-off-by: Steven Liu 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7e4527e8fa1f8f0bba6a7f7cadc407813f17fbd1
---

 doc/filters.texi| 7 +--
 libavfilter/vf_derain.c | 6 +-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index dce396e3fd..59933634cb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8878,6 +8878,7 @@ delogo=x=0:y=0:w=100:h=77:band=10
 
 @end itemize
 
+@anchor{derain}
 @section derain
 
 Remove the rain in the input image/video by applying the derain methods based 
on
@@ -8932,6 +8933,8 @@ Note that different backends use different file formats. 
TensorFlow and native
 backend can load files for only its format.
 @end table
 
+It can also be finished with @ref{dnn_processing} filter.
+
 @section deshake
 
 Attempt to fix small changes in horizontal and/or vertical shift. This
@@ -9201,9 +9204,9 @@ Set the output name of the dnn network.
 
 @itemize
 @item
-Halve the red channle of the frame with format rgb24:
+Remove rain in rgb24 frame with can.pb (see @ref{derain} filter):
 @example
-ffmpeg -i input.jpg -vf 
format=rgb24,dnn_processing=model=halve_first_channel.model:input=dnn_in:output=dnn_out:dnn_backend=native
 out.native.png
+./ffmpeg -i rain.jpg -vf 
format=rgb24,dnn_processing=dnn_backend=tensorflow:model=can.pb:input=x:output=y
 derain.jpg
 @end example
 
 @item
diff --git a/libavfilter/vf_derain.c b/libavfilter/vf_derain.c
index 89f9d5a2ed..74322602b0 100644
--- a/libavfilter/vf_derain.c
+++ b/libavfilter/vf_derain.c
@@ -100,7 +100,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFilterLink *outlink = ctx->outputs[0];
 DRContext *dr_context = ctx->priv;
 DNNReturnType dnn_result;
-int pad_size;
 
 AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 if (!out) {
@@ -129,15 +128,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 out->width  = dr_context->output.width;
 outlink->h  = dr_context->output.height;
 outlink->w  = dr_context->output.width;
-pad_size= (in->height - out->height) >> 1;
 
 for (int i = 0; i < out->height; i++){
 for(int j = 0; j < out->width * 3; j++){
 int k = i * out->linesize[0] + j;
 int t = i * out->width * 3 + j;
-
-int t_in =  (i + pad_size) * in->width * 3 + j + pad_size * 3;
-out->data[0][k] = CLIP((int)float 
*)dr_context->input.data)[t_in] - ((float *)dr_context->output.data)[t]) * 
255), 0, 255);
+out->data[0][k] = CLIP((int)float 
*)dr_context->output.data)[t]) * 255), 0, 255);
 }
 }
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avfilter/vf_dnn_processing.c: fix typo for the linesize of dnn data

2020-04-06 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Sat Mar 21 
17:33:26 2020 +0800| [2114c4241891849323fd65e56f1ab6f70375a291] | committer: 
Guo, Yejun

avfilter/vf_dnn_processing.c: fix typo for the linesize of dnn data

Signed-off-by: Guo, Yejun 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2114c4241891849323fd65e56f1ab6f70375a291
---

 libavfilter/vf_dnn_processing.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index fabe4f1d01..cf589acedf 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -329,7 +329,7 @@ static int copy_from_frame_to_dnn(DnnProcessingContext 
*ctx, const AVFrame *fram
 if (dnn_input->dt == DNN_FLOAT) {
 sws_scale(ctx->sws_gray8_to_grayf32, (const uint8_t 
**)frame->data, frame->linesize,
   0, frame->height, (uint8_t * const*)(&dnn_input->data),
-  (const int [4]){frame->linesize[0] * sizeof(float), 0, 
0, 0});
+  (const int [4]){frame->width * 3 * sizeof(float), 0, 0, 
0});
 } else {
 av_assert0(dnn_input->dt == DNN_UINT8);
 av_image_copy_plane(dnn_input->data, bytewidth,
@@ -369,7 +369,7 @@ static int copy_from_dnn_to_frame(DnnProcessingContext 
*ctx, AVFrame *frame)
 case AV_PIX_FMT_BGR24:
 if (dnn_output->dt == DNN_FLOAT) {
 sws_scale(ctx->sws_grayf32_to_gray8, (const uint8_t *[4]){(const 
uint8_t *)dnn_output->data, 0, 0, 0},
-  (const int[4]){frame->linesize[0] * sizeof(float), 0, 0, 
0},
+  (const int[4]){frame->width * 3 * sizeof(float), 0, 0, 
0},
   0, frame->height, (uint8_t * const*)frame->data, 
frame->linesize);
 
 } else {

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".