[FFmpeg-cvslog] FATE/dnn: add unit test for dnn conv2d layer

2019-09-19 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Thu Sep  5 
14:00:39 2019 +0800| [24f507301b4774bb1b082c594d1ce8885b5cabd8] | committer: 
Pedro Arthur

FATE/dnn: add unit test for dnn conv2d layer

'make fate-dnn-layer-conv2d' to run the test

Signed-off-by: Guo, Yejun 
Signed-off-by: Pedro Arthur 

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

 tests/dnn/Makefile|   1 +
 tests/dnn/dnn-layer-conv2d-test.c | 238 ++
 tests/fate/dnn.mak|   5 +
 3 files changed, 244 insertions(+)

diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile
index fabed7510f..3adefe89cd 100644
--- a/tests/dnn/Makefile
+++ b/tests/dnn/Makefile
@@ -1,4 +1,5 @@
 DNNTESTPROGS += dnn-layer-pad
+DNNTESTPROGS += dnn-layer-conv2d
 
 DNNTESTOBJS  := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) 
$(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
 DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
diff --git a/tests/dnn/dnn-layer-conv2d-test.c 
b/tests/dnn/dnn-layer-conv2d-test.c
new file mode 100644
index 00..afc5391484
--- /dev/null
+++ b/tests/dnn/dnn-layer-conv2d-test.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2019 Guo Yejun
+ *
+ * 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_conv2d.h"
+
+#define EPSON 0.1
+
+static int test_with_same_dilate(void)
+{
+// the input data and expected data are generated with below python code.
+/*
+x = tf.placeholder(tf.float32, shape=[1, None, None, 3])
+y = tf.layers.conv2d(x, 2, 3, activation=tf.nn.tanh, padding='same', 
dilation_rate=(2, 2), bias_initializer=tf.keras.initializers.he_normal())
+data = np.random.rand(1, 5, 6, 3);
+
+sess=tf.Session()
+sess.run(tf.global_variables_initializer())
+
+weights = dict([(var.name, sess.run(var)) for var in 
tf.trainable_variables()])
+kernel = weights['conv2d/kernel:0']
+kernel = np.transpose(kernel, [3, 0, 1, 2])
+print("kernel:")
+print(kernel.shape)
+print(list(kernel.flatten()))
+
+bias = weights['conv2d/bias:0']
+print("bias:")
+print(bias.shape)
+print(list(bias.flatten()))
+
+output = sess.run(y, feed_dict={x: data})
+
+print("input:")
+print(data.shape)
+print(list(data.flatten()))
+
+print("output:")
+print(output.shape)
+print(list(output.flatten()))
+*/
+
+ConvolutionalParams params;
+DnnOperand operands[2];
+int32_t input_indexes[1];
+float input[1*5*6*3] = {
+0.7012556460308194, 0.4233847954643357, 0.19515900664313612, 
0.16343083004926495, 0.5758261611052848, 0.9510767434014871, 
0.11014085055947687,
+0.906327053637727, 0.8136794715542507, 0.45371764543639526, 
0.5768443343523952, 0.19543668786046986, 0.15648326047898609, 
0.2099500241141279,
+0.17658777090552413, 0.059335724777169196, 0.1729991838469117, 
0.8150514704819208, 0.4435535466703049, 0.3752188477566878, 0.749936650421431,
+0.6823494635284907, 0.10776389679424747, 0.34247481674596836, 
0.5147867256244629, 0.9063709728129032, 0.12423605800856818, 0.6064872945412728,
+0.5891681538551459, 0.9865836236466314, 0.9002163879294677, 
0.003968273184274618, 0.8628374809643967, 0.1327176268279583, 
0.8449799925703798,
+0.1937671869354366, 0.41524410152707425, 0.02038786604756837, 
0.49792466069597496, 0.8881874553848784, 0.9683921035597336, 0.4122972568010813,
+0.843553550993252, 0.9588482762501964, 0.5190350762645546, 
0.4283584264145317, 0.09781496073714646, 0.9501058833776156, 0.8665541760152776,
+0.31669272550095806, 0.07133074675453632, 0.606438007334886, 
0.7007157020538224, 0.4827996264130444, 0.5167615606392761, 0.6385043039312651,
+0.23069664707810555, 0.058233497329354456, 0.06323892961591071, 
0.24816458893245974, 0.8646369065257812, 0.24742185893094837, 
0.09991225948167437,
+0.625700606979606, 0.7678541502111257, 0.6215834594679912, 
0.5623003956582483, 0.07389123942681242, 0.7659100715711249, 0.486061471642225,
+0.9947455699829012, 0.9094911797643259, 0.7644355876253265, 
0.05384315321492239, 0.13565394382783613, 0.9810628204953316, 
0.007386389078887889,
+0.22

[FFmpeg-cvslog] FATE/dnn: add unit test for dnn depth_to_space layer

2019-09-19 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Thu Sep  5 
14:00:54 2019 +0800| [b766a13dba383df065869527aec87843d2183bc1] | committer: 
Pedro Arthur

FATE/dnn: add unit test for dnn depth_to_space layer

'make fate-dnn-layer-depth2space' to run the test

Signed-off-by: Guo, Yejun 
Signed-off-by: Pedro Arthur 

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

 tests/dnn/Makefile |   1 +
 tests/dnn/dnn-layer-depth2space-test.c | 100 +
 tests/fate/dnn.mak |   5 ++
 3 files changed, 106 insertions(+)

diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile
index 3adefe89cd..3cb5f6d7aa 100644
--- a/tests/dnn/Makefile
+++ b/tests/dnn/Makefile
@@ -1,5 +1,6 @@
 DNNTESTPROGS += dnn-layer-pad
 DNNTESTPROGS += dnn-layer-conv2d
+DNNTESTPROGS += dnn-layer-depth2space
 
 DNNTESTOBJS  := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) 
$(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
 DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
diff --git a/tests/dnn/dnn-layer-depth2space-test.c 
b/tests/dnn/dnn-layer-depth2space-test.c
new file mode 100644
index 00..87118de795
--- /dev/null
+++ b/tests/dnn/dnn-layer-depth2space-test.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2019 Guo Yejun
+ *
+ * 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.h"
+#include "libavfilter/dnn/dnn_backend_native_layer_depth2space.h"
+
+#define EPSON 0.1
+
+static int test(void)
+{
+// the input data and expected data are generated with below python code.
+/*
+x = tf.placeholder(tf.float32, shape=[1, None, None, 4])
+y = tf.depth_to_space(x, 2)
+data = np.random.rand(1, 5, 3, 4);
+
+sess=tf.Session()
+sess.run(tf.global_variables_initializer())
+
+output = sess.run(y, feed_dict={x: data})
+
+print("input:")
+print(data.shape)
+print(list(data.flatten()))
+
+print("output:")
+print(output.shape)
+print(list(output.flatten()))
+*/
+
+DnnOperand operands[2];
+int32_t input_indexes[1];
+float input[1*5*3*4] = {
+0.09771065121566602, 0.6336807372403175, 0.5142416549709786, 
0.8027206567330333, 0.2154276025069397, 0.12112878462616772, 0.913936596765778,
+0.38881443647542646, 0.5850447615898835, 0.9311499327398275, 
0.3613660929428246, 0.5420722002125493, 0.6002131190230359, 0.44800665702299525,
+0.7271322557896777, 0.3869293511885826, 0.5144404769364138, 
0.6910844856987723, 0.6142102742269762, 0.6249991371621018, 0.45663376215836626,
+0.19523477129943423, 0.2483895888532045, 0.64326768256278, 
0.5485877602998981, 0.45442067849873546, 0.529374943304256, 0.30439850391811885,
+0.11961343361340993, 0.2909643484561082, 0.9810970344127848, 
0.8886928489786549, 0.6112237084436409, 0.8852482695156674, 0.9110868043114374,
+0.21242780027585217, 0.7101536973207572, 0.9709717457443375, 
0.2702666770969332, 0.7718295953780221, 0.3957005164588574, 0.24383544252475453,
+0.040143453532367035, 0.26358051835323115, 0.013130251443791319, 
0.3016550481482074, 0.03582340459943956, 0.718025513612361, 0.09844204177633753,
+0.04433767496953056, 0.6221895044119757, 0.6190414032940228, 
0.8963550834625371, 0.5642449700064629, 0.2482982014723497, 0.17824909294583013,
+0.024401882408643272, 0.21742800875253465, 0.6794724473181843, 
0.4814830479242237
+};
+float expected_output[1*10*6*1] = {
+0.097710654, 0.63368076, 0.2154276, 0.12112878, 0.58504474, 
0.93114996, 0.51424164, 0.80272067, 0.9139366, 0.38881445,
+0.3613661, 0.5420722, 0.6002131, 0.44800666, 0.5144405, 0.6910845, 
0.45663378, 0.19523478, 0.72713226, 0.38692936,
+0.61421025, 0.62499917, 0.24838959, 0.6432677, 0.54858774, 0.4544207, 
0.11961343, 0.29096434, 0.6112237, 0.88524824,
+0.52937496, 0.3043985, 0.98109704, 0.88869286, 0.9110868, 0.2124278, 
0.7101537, 0.97097176, 0.3957005, 0.24383545,
+0.013130251, 0.30165505, 0.27026668, 0.7718296, 0.040143453, 
0.26358053, 0.035823405, 0.7180255, 0.09844204,
+0.044337675, 0.8963551, 0.564245, 0.024401883, 0.21742801, 0.6221895, 
0.6190414, 0.2482982, 0.17824909, 0.679472

[FFmpeg-cvslog] libavfilter/dnn: separate conv2d layer from dnn_backend_native.c to a new file

2019-09-19 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Thu Sep  5 
14:00:28 2019 +0800| [5f058dd693c4bebcd6a293da4630441f3540902f] | committer: 
Pedro Arthur

libavfilter/dnn: separate conv2d layer from dnn_backend_native.c to a new file

the logic is that one layer in one separated source file to make
the source files simple for maintaining.

Signed-off-by: Guo, Yejun 
Signed-off-by: Pedro Arthur 

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

 libavfilter/dnn/Makefile  |   1 +
 libavfilter/dnn/dnn_backend_native.c  |  80 +
 libavfilter/dnn/dnn_backend_native.h  |  13 ---
 libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 101 ++
 libavfilter/dnn/dnn_backend_native_layer_conv2d.h |  39 +
 libavfilter/dnn/dnn_backend_tf.c  |   1 +
 6 files changed, 143 insertions(+), 92 deletions(-)

diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index 83938e5693..40b848b442 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -1,6 +1,7 @@
 OBJS-$(CONFIG_DNN)   += dnn/dnn_interface.o
 OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_pad.o
+OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_conv2d.o
 
 DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
 
diff --git a/libavfilter/dnn/dnn_backend_native.c 
b/libavfilter/dnn/dnn_backend_native.c
index f56cd81187..5dabd151c0 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -26,6 +26,7 @@
 #include "dnn_backend_native.h"
 #include "libavutil/avassert.h"
 #include "dnn_backend_native_layer_pad.h"
+#include "dnn_backend_native_layer_conv2d.h"
 
 static DNNReturnType set_input_output_native(void *model, DNNInputData *input, 
const char *input_name, const char **output_names, uint32_t nb_output)
 {
@@ -281,85 +282,6 @@ DNNModel *ff_dnn_load_model_native(const char 
*model_filename)
 return model;
 }
 
-#define CLAMP_TO_EDGE(x, w) ((x) < 0 ? 0 : ((x) >= (w) ? (w - 1) : (x)))
-
-static int convolve(DnnOperand *operands, const int32_t 
*input_operand_indexes, int32_t output_operand_index, const ConvolutionalParams 
*conv_params)
-{
-float *output;
-int32_t input_operand_index = input_operand_indexes[0];
-int number = operands[input_operand_index].dims[0];
-int height = operands[input_operand_index].dims[1];
-int width = operands[input_operand_index].dims[2];
-int channel = operands[input_operand_index].dims[3];
-const float *input = operands[input_operand_index].data;
-
-int radius = conv_params->kernel_size >> 1;
-int src_linesize = width * conv_params->input_num;
-int filter_linesize = conv_params->kernel_size * conv_params->input_num;
-int filter_size = conv_params->kernel_size * filter_linesize;
-int pad_size = (conv_params->padding_method == VALID) ? 
(conv_params->kernel_size - 1) / 2 * conv_params->dilation : 0;
-
-DnnOperand *output_operand = &operands[output_operand_index];
-output_operand->dims[0] = number;
-output_operand->dims[1] = height - pad_size * 2;
-output_operand->dims[2] = width - pad_size * 2;
-output_operand->dims[3] = conv_params->output_num;
-output_operand->length = calculate_operand_data_length(output_operand);
-output_operand->data = av_realloc(output_operand->data, 
output_operand->length);
-if (!output_operand->data)
-return -1;
-output = output_operand->data;
-
-av_assert0(channel == conv_params->input_num);
-
-for (int y = pad_size; y < height - pad_size; ++y) {
-for (int x = pad_size; x < width - pad_size; ++x) {
-for (int n_filter = 0; n_filter < conv_params->output_num; 
++n_filter) {
-output[n_filter] = conv_params->biases[n_filter];
-
-for (int ch = 0; ch < conv_params->input_num; ++ch) {
-for (int kernel_y = 0; kernel_y < 
conv_params->kernel_size; ++kernel_y) {
-for (int kernel_x = 0; kernel_x < 
conv_params->kernel_size; ++kernel_x) {
-float input_pel;
-if (conv_params->padding_method == 
SAME_CLAMP_TO_EDGE) {
-int y_pos = CLAMP_TO_EDGE(y + (kernel_y - 
radius) * conv_params->dilation, height);
-int x_pos = CLAMP_TO_EDGE(x + (kernel_x - 
radius) * conv_params->dilation, width);
-input_pel = input[y_pos * src_linesize + x_pos 
* conv_params->input_num + ch];
-} else {
-int y_pos = y + (kernel_y - radius) * 
conv_params->dilation;
-int x_pos = x + (kernel_x - radius) * 
conv_params->dilation;
-  

[FFmpeg-cvslog] libavfilter/dnn: separate depth_to_space layer from dnn_backend_native.c to a new file

2019-09-19 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Thu Sep  5 
14:00:46 2019 +0800| [48133fad056e9173a39333fc5f7d4a724a47a028] | committer: 
Pedro Arthur

libavfilter/dnn: separate depth_to_space layer from dnn_backend_native.c to a 
new file

the logic is that one layer in one separated source file to make
the source files simple for maintaining.

Signed-off-by: Guo, Yejun 
Signed-off-by: Pedro Arthur 

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

 libavfilter/dnn/Makefile   |  1 +
 libavfilter/dnn/dnn_backend_native.c   | 44 +-
 libavfilter/dnn/dnn_backend_native.h   |  4 --
 .../dnn/dnn_backend_native_layer_depth2space.c | 71 ++
 .../dnn/dnn_backend_native_layer_depth2space.h | 39 
 libavfilter/dnn/dnn_backend_tf.c   |  1 +
 6 files changed, 113 insertions(+), 47 deletions(-)

diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index 40b848b442..63a35e7dd5 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -2,6 +2,7 @@ OBJS-$(CONFIG_DNN)   += 
dnn/dnn_interface.o
 OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_pad.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_conv2d.o
+OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_depth2space.o
 
 DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
 
diff --git a/libavfilter/dnn/dnn_backend_native.c 
b/libavfilter/dnn/dnn_backend_native.c
index 5dabd151c0..be548c6d46 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -27,6 +27,7 @@
 #include "libavutil/avassert.h"
 #include "dnn_backend_native_layer_pad.h"
 #include "dnn_backend_native_layer_conv2d.h"
+#include "dnn_backend_native_layer_depth2space.h"
 
 static DNNReturnType set_input_output_native(void *model, DNNInputData *input, 
const char *input_name, const char **output_names, uint32_t nb_output)
 {
@@ -282,49 +283,6 @@ DNNModel *ff_dnn_load_model_native(const char 
*model_filename)
 return model;
 }
 
-static int depth_to_space(DnnOperand *operands, const int32_t 
*input_operand_indexes, int32_t output_operand_index, int block_size)
-{
-float *output;
-int32_t input_operand_index = input_operand_indexes[0];
-int number = operands[input_operand_index].dims[0];
-int height = operands[input_operand_index].dims[1];
-int width = operands[input_operand_index].dims[2];
-int channels = operands[input_operand_index].dims[3];
-const float *input = operands[input_operand_index].data;
-
-int y, x, by, bx, ch;
-int new_channels = channels / (block_size * block_size);
-int output_linesize = width * channels;
-int by_linesize = output_linesize / block_size;
-int x_linesize = new_channels * block_size;
-
-DnnOperand *output_operand = &operands[output_operand_index];
-output_operand->dims[0] = number;
-output_operand->dims[1] = height * block_size;
-output_operand->dims[2] = width * block_size;
-output_operand->dims[3] = new_channels;
-output_operand->length = calculate_operand_data_length(output_operand);
-output_operand->data = av_realloc(output_operand->data, 
output_operand->length);
-if (!output_operand->data)
-return -1;
-output = output_operand->data;
-
-for (y = 0; y < height; ++y){
-for (x = 0; x < width; ++x){
-for (by = 0; by < block_size; ++by){
-for (bx = 0; bx < block_size; ++bx){
-for (ch = 0; ch < new_channels; ++ch){
-output[by * by_linesize + x * x_linesize + bx * 
new_channels + ch] = input[ch];
-}
-input += new_channels;
-}
-}
-}
-output += output_linesize;
-}
-return 0;
-}
-
 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData 
*outputs, uint32_t nb_output)
 {
 ConvolutionalNetwork *network = (ConvolutionalNetwork *)model->model;
diff --git a/libavfilter/dnn/dnn_backend_native.h 
b/libavfilter/dnn/dnn_backend_native.h
index aa5c77..a74d1381c2 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -90,10 +90,6 @@ typedef struct InputParams{
 int height, width, channels;
 } InputParams;
 
-typedef struct DepthToSpaceParams{
-int block_size;
-} DepthToSpaceParams;
-
 // Represents simple feed-forward convolutional network.
 typedef struct ConvolutionalNetwork{
 Layer *layers;
diff --git a/libavfilter/dnn/dnn_backend_native_layer_depth2space.c 
b/libavfilter/dnn/dnn_backend_native_layer_depth2space.c
new file mode 100644
index 00..a248764681
--- /dev/null
+++ b/libavfilter/dnn/dnn_backend_native_layer_depth2s

[FFmpeg-cvslog] avfilter/vf_v360: add ball projection format

2019-09-19 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Thu Sep 19 18:36:19 
2019 +0200| [b632ad81c5f44d0c47b44c5a87084b30f33bed5e] | committer: Paul B Mahol

avfilter/vf_v360: add ball projection format

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

 doc/filters.texi  |  3 ++
 libavfilter/v360.h|  1 +
 libavfilter/vf_v360.c | 88 +++
 3 files changed, 92 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 06ce7ec069..1f65b097d6 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -18060,6 +18060,9 @@ If diagonal field of view is set it overrides 
horizontal and vertical field of v
 @item mercator
 Mercator format.
 
+@item ball
+Ball format, gives significant distortion toward the back.
+
 @end table
 
 @item interp
diff --git a/libavfilter/v360.h b/libavfilter/v360.h
index cb968dab46..50ed91ed89 100644
--- a/libavfilter/v360.h
+++ b/libavfilter/v360.h
@@ -40,6 +40,7 @@ enum Projections {
 CUBEMAP_1_6,
 STEREOGRAPHIC,
 MERCATOR,
+BALL,
 NB_PROJECTIONS,
 };
 
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index f8d3be80a5..1d614d75e2 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -66,6 +66,7 @@ static const AVOption v360_options[] = {
 {  "c1x6", "cubemap 1x6",0, 
AV_OPT_TYPE_CONST,  {.i64=CUBEMAP_1_6}, 0,   0, FLAGS, "in" 
},
 {"sg", "stereographic",  0, 
AV_OPT_TYPE_CONST,  {.i64=STEREOGRAPHIC},   0,   0, FLAGS, "in" 
},
 {  "mercator", "mercator",   0, 
AV_OPT_TYPE_CONST,  {.i64=MERCATOR},0,   0, FLAGS, "in" 
},
+{  "ball", "ball",   0, 
AV_OPT_TYPE_CONST,  {.i64=BALL},0,   0, FLAGS, "in" 
},
 {"output", "set output projection",OFFSET(out), 
AV_OPT_TYPE_INT,{.i64=CUBEMAP_3_2}, 0,NB_PROJECTIONS-1, FLAGS, 
"out" },
 { "e", "equirectangular",0, 
AV_OPT_TYPE_CONST,  {.i64=EQUIRECTANGULAR}, 0,   0, FLAGS, 
"out" },
 {  "equirect", "equirectangular",0, 
AV_OPT_TYPE_CONST,  {.i64=EQUIRECTANGULAR}, 0,   0, FLAGS, 
"out" },
@@ -81,6 +82,7 @@ static const AVOption v360_options[] = {
 {  "c1x6", "cubemap 1x6",0, 
AV_OPT_TYPE_CONST,  {.i64=CUBEMAP_1_6}, 0,   0, FLAGS, 
"out" },
 {"sg", "stereographic",  0, 
AV_OPT_TYPE_CONST,  {.i64=STEREOGRAPHIC},   0,   0, FLAGS, 
"out" },
 {  "mercator", "mercator",   0, 
AV_OPT_TYPE_CONST,  {.i64=MERCATOR},0,   0, FLAGS, 
"out" },
+{  "ball", "ball",   0, 
AV_OPT_TYPE_CONST,  {.i64=BALL},0,   0, FLAGS, 
"out" },
 {"interp", "set interpolation method",  OFFSET(interp), 
AV_OPT_TYPE_INT,{.i64=BILINEAR},0, NB_INTERP_METHODS-1, FLAGS, 
"interp" },
 {  "near", "nearest neighbour",  0, 
AV_OPT_TYPE_CONST,  {.i64=NEAREST}, 0,   0, FLAGS, 
"interp" },
 {   "nearest", "nearest neighbour",  0, 
AV_OPT_TYPE_CONST,  {.i64=NEAREST}, 0,   0, FLAGS, 
"interp" },
@@ -1583,6 +1585,80 @@ static void mercator_to_xyz(const V360Context *s,
 }
 
 /**
+ * Calculate frame position in ball format for corresponding 3D coordinates on 
sphere.
+ *
+ * @param s filter context
+ * @param vec coordinates on sphere
+ * @param width frame width
+ * @param height frame height
+ * @param us horizontal coordinates for interpolation window
+ * @param vs vertical coordinates for interpolation window
+ * @param du horizontal relative coordinate
+ * @param dv vertical relative coordinate
+ */
+static void xyz_to_ball(const V360Context *s,
+const float *vec, int width, int height,
+uint16_t us[4][4], uint16_t vs[4][4], float *du, float 
*dv)
+{
+const float l = hypotf(vec[0], vec[1]);
+const float r = sinf(acosf(-vec[2]) * 0.5f);
+float uf, vf;
+int ui, vi;
+
+uf = (1.f - r * vec[0] / l) * width  / 2.f;
+vf = (1.f + r * vec[1] / l) * height / 2.f;
+ui = floorf(uf);
+vi = floorf(vf);
+
+*du = uf - ui;
+*dv = vf - vi;
+
+for (int i = -1; i < 3; i++) {
+for (int j = -1; j < 3; j++) {
+us[i + 1][j + 1] = mod(ui + j, width);
+vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);
+}
+}
+}
+
+/**
+ * Calculate 3D coordinates on sphere for corresponding frame position in ball 
format.
+ *
+ * @param s filter context
+ * @param i horizontal position on frame [0, width)
+ * @par

[FFmpeg-cvslog] avformat/mpegts: add support for EPG extraction from mpegts

2019-09-19 Thread Anthony Delannoy
ffmpeg | branch: master | Anthony Delannoy  | Wed 
Aug 21 11:46:56 2019 +0200| [a221af1f5eea7313472b1cbeaa566b66d025fea6] | 
committer: Marton Balint

avformat/mpegts: add support for EPG extraction from mpegts

Signed-off-by: Marton Balint 

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

 libavformat/mpegts.c | 60 +++-
 tests/ref/fate/mpegts-probe-latm |  3 ++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 63ac071619..587ed33327 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -168,6 +168,8 @@ struct MpegTSContext {
 /** filters for various streams specified by PMT + for the PAT and PMT */
 MpegTSFilter *pids[NB_PID_MAX];
 int current_pid;
+
+AVStream *epg_stream;
 };
 
 #define MPEGTS_OPTIONS \
@@ -2499,6 +2501,60 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 }
 }
 
+static void eit_cb(MpegTSFilter *filter, const uint8_t *section, int 
section_len)
+{
+MpegTSContext *ts = filter->u.section_filter.opaque;
+const uint8_t *p, *p_end;
+SectionHeader h1, *h = &h1;
+
+/*
+ * Sometimes we receive EPG packets but SDT table do not have
+ * eit_pres_following or eit_sched turned on, so we open EPG
+ * stream directly here.
+ */
+if (!ts->epg_stream) {
+ts->epg_stream = avformat_new_stream(ts->stream, NULL);
+if (!ts->epg_stream)
+return;
+ts->epg_stream->id = EIT_PID;
+ts->epg_stream->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+ts->epg_stream->codecpar->codec_id = AV_CODEC_ID_EPG;
+}
+
+if (ts->epg_stream->discard == AVDISCARD_ALL)
+return;
+
+p_end = section + section_len - 4;
+p = section;
+
+if (parse_section_header(h, &p, p_end) < 0)
+return;
+if (h->tid < EIT_TID || h->tid > OEITS_END_TID)
+return;
+
+av_log(ts->stream, AV_LOG_TRACE, "EIT: tid received = %.02x\n", h->tid);
+
+/**
+ * Service_id 0x is reserved, it indicates that the current EIT table
+ * is scrambled.
+ */
+if (h->id == 0x) {
+av_log(ts->stream, AV_LOG_TRACE, "Scrambled EIT table received.\n");
+return;
+}
+
+/**
+ * In case we receive an EPG packet before mpegts context is fully
+ * initialized.
+ */
+if (!ts->pkt)
+return;
+
+new_data_packet(section, section_len, ts->pkt);
+ts->pkt->stream_index = ts->epg_stream->index;
+ts->stop_parse = 1;
+}
+
 static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int 
section_len)
 {
 MpegTSContext *ts = filter->u.section_filter.opaque;
@@ -2985,8 +3041,8 @@ static int mpegts_read_header(AVFormatContext *s)
 seek_back(s, pb, pos);
 
 mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
-
 mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);
+mpegts_open_section_filter(ts, EIT_PID, eit_cb, ts, 1);
 
 handle_packets(ts, probesize / ts->raw_packet_size);
 /* if could not find service, enable auto_guess */
@@ -3241,8 +3297,10 @@ MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext 
*s)
 ts->raw_packet_size = TS_PACKET_SIZE;
 ts->stream = s;
 ts->auto_guess = 1;
+
 mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
 mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);
+mpegts_open_section_filter(ts, EIT_PID, eit_cb, ts, 1);
 
 return ts;
 }
diff --git a/tests/ref/fate/mpegts-probe-latm b/tests/ref/fate/mpegts-probe-latm
index 13aea2bcfd..6fa9b623f3 100644
--- a/tests/ref/fate/mpegts-probe-latm
+++ b/tests/ref/fate/mpegts-probe-latm
@@ -12,3 +12,6 @@ codec_name=hevc
 [STREAM]
 codec_name=aac_latm
 [/STREAM]
+[STREAM]
+codec_name=epg
+[/STREAM]

___
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/dnn: fix inclusion guard in dnn/dnn_backend_native_layer_depth2space.h

2019-09-19 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Thu Sep 19 21:28:10 
2019 +0200| [862e020f93149af6ef9269690da210a5261b2b51] | committer: Marton 
Balint

avfilter/dnn: fix inclusion guard in dnn/dnn_backend_native_layer_depth2space.h

Fixes fate-source failure.

Signed-off-by: Marton Balint 

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

 libavfilter/dnn/dnn_backend_native_layer_depth2space.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native_layer_depth2space.h 
b/libavfilter/dnn/dnn_backend_native_layer_depth2space.h
index 7a051af918..8708be83b9 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_depth2space.h
+++ b/libavfilter/dnn/dnn_backend_native_layer_depth2space.h
@@ -24,8 +24,8 @@
  */
 
 
-#ifndef AVFILTER_DNN_DNN_BACKEND_NATIVE_DEPTH2SPACE_H
-#define AVFILTER_DNN_DNN_BACKEND_NATIVE_DEPTH2SPACE_H
+#ifndef AVFILTER_DNN_DNN_BACKEND_NATIVE_LAYER_DEPTH2SPACE_H
+#define AVFILTER_DNN_DNN_BACKEND_NATIVE_LAYER_DEPTH2SPACE_H
 
 #include "../dnn_interface.h"
 #include "libavformat/avio.h"

___
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] avcodec: add EPG codec ID

2019-09-19 Thread Anthony Delannoy
ffmpeg | branch: master | Anthony Delannoy  | Wed 
Aug 21 11:36:15 2019 +0200| [81bb71761ac3bcac6d70c66267636753494174cc] | 
committer: Marton Balint

avcodec: add EPG codec ID

Signed-off-by: Marton Balint 

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

 libavcodec/avcodec.h| 1 +
 libavcodec/codec_desc.c | 6 ++
 libavcodec/version.h| 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 0ec3e73865..c91ee4af5b 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -690,6 +690,7 @@ enum AVCodecID {
 AV_CODEC_ID_TTF = 0x18000,
 
 AV_CODEC_ID_SCTE_35, ///< Contain timestamp estimated through PCR of 
program stream.
+AV_CODEC_ID_EPG,
 AV_CODEC_ID_BINTEXT= 0x18800,
 AV_CODEC_ID_XBIN,
 AV_CODEC_ID_IDF,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index d2c6863d3c..0602ecb1b5 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3198,6 +3198,12 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("SCTE 35 Message Queue"),
 },
 {
+.id= AV_CODEC_ID_EPG,
+.type  = AVMEDIA_TYPE_DATA,
+.name  = "epg",
+.long_name = NULL_IF_CONFIG_SMALL("Electronic Program Guide"),
+},
+{
 .id= AV_CODEC_ID_BINTEXT,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "bintext",
diff --git a/libavcodec/version.h b/libavcodec/version.h
index c7a2bd0bdc..bef8dfba38 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  57
+#define LIBAVCODEC_VERSION_MINOR  58
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

___
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] avformat/mpegts: add all well known PIDs and TIDs to mpegts.h

2019-09-19 Thread Anthony Delannoy
ffmpeg | branch: master | Anthony Delannoy  | Fri 
Jul 26 11:41:00 2019 +0200| [5e51c1aeb5b3497ce37f3eddab4c252125d54221] | 
committer: Marton Balint

avformat/mpegts: add all well known PIDs and TIDs to mpegts.h

Signed-off-by: Marton Balint 

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

 libavformat/mpegts.h | 74 +++-
 1 file changed, 68 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 272e2be4f7..ecc3d3374c 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -30,17 +30,79 @@
 #define TS_MAX_PACKET_SIZE 204
 
 #define NB_PID_MAX 8192
+#define USUAL_SECTION_SIZE 1024 /* except EIT which is limited to 4096 */
 #define MAX_SECTION_SIZE 4096
 
 /* pids */
-#define PAT_PID 0x
-#define SDT_PID 0x0011
+#define PAT_PID 0x /* Program Association Table */
+#define CAT_PID 0x0001 /* Conditional Access Table */
+#define TSDT_PID0x0002 /* Transport Stream Description Table */
+#define IPMP_PID0x0003
+/* PID from 0x0004 to 0x000F are reserved */
+#define NIT_PID 0x0010 /* Network Information Table */
+#define SDT_PID 0x0011 /* Service Description Table */
+#define BAT_PID 0x0011 /* Bouquet Association Table */
+#define EIT_PID 0x0012 /* Event Information Table */
+#define RST_PID 0x0013 /* Running Status Table */
+#define TDT_PID 0x0014 /* Time and Date Table */
+#define TOT_PID 0x0014
+#define NET_SYNC_PID0x0015
+#define RNT_PID 0x0016 /* RAR Notification Table */
+/* PID from 0x0017 to 0x001B are reserved for future use */
+/* PID value 0x001C allocated to link-local inband signalling shall not be
+ * used on any broadcast signals. It shall only be used between devices in a
+ * controlled environment. */
+#define LINK_LOCAL_PID  0x001C
+#define MEASUREMENT_PID 0x001D
+#define DIT_PID 0x001E /* Discontinuity Information Table */
+#define SIT_PID 0x001F /* Selection Information Table */
+/* PID from 0x0020 to 0x1FFA may be assigned as needed to PMT, elementary
+ * streams and other data tables */
+/* PID 0x1FFB is used by DigiCipher 2/ATSC MGT metadata */
+/* PID from 0x1FFC to 0x1FFE may be assigned as needed to PMT, elementary
+ * streams and other data tables */
+#define NULL_PID0x1FFF /* Null packet (used for fixed bandwidth 
padding) */
 
 /* table ids */
-#define PAT_TID   0x00
-#define PMT_TID   0x02
-#define M4OD_TID  0x05
-#define SDT_TID   0x42
+#define PAT_TID 0x00 /* Program Association section */
+#define CAT_TID 0x01 /* Conditional Access section */
+#define PMT_TID 0x02 /* Program Map section */
+#define TSDT_TID0x03 /* Transport Stream Description section */
+/* TID from 0x04 to 0x3F are reserved */
+#define M4OD_TID0x05
+#define NIT_TID 0x40 /* Network Information section - actual network */
+#define ONIT_TID0x41 /* Network Information section - other network */
+#define SDT_TID 0x42 /* Service Description section - actual TS */
+/* TID from 0x43 to 0x45 are reserved for future use */
+#define OSDT_TID0x46 /* Service Descrition section - other TS */
+/* TID from 0x47 to 0x49 are reserved for future use */
+#define BAT_TID 0x4A /* Bouquet Association section */
+#define UNT_TID 0x4B /* Update Notification Table section */
+#define DFI_TID 0x4C /* Downloadable Font Info section */
+/* TID 0x4D is reserved for future use */
+#define EIT_TID 0x4E /* Event Information section - actual TS */
+#define OEIT_TID0x4F /* Event Information section - other TS */
+#define EITS_START_TID  0x50 /* Event Information section schedule - actual TS 
*/
+#define EITS_END_TID0x5F /* Event Information section schedule - actual TS 
*/
+#define OEITS_START_TID 0x60 /* Event Information section schedule - other TS 
*/
+#define OEITS_END_TID   0x6F /* Event Information section schedule - other TS 
*/
+#define TDT_TID 0x70 /* Time Date section */
+#define RST_TID 0x71 /* Running Status section */
+#define ST_TID  0x72 /* Stuffing section */
+#define TOT_TID 0x73 /* Time Offset section */
+#define AIT_TID 0x74 /* Application Inforamtion section */
+#define CT_TID  0x75 /* Container section */
+#define RCT_TID 0x76 /* Related Content section */
+#define CIT_TID 0x77 /* Content Identifier section */
+#define MPE_FEC_TID 0x78 /* MPE-FEC section */
+#define RPNT_TID0x79 /* Resolution Provider Notification section */
+#define MPE_IFEC_TID0x7A /* MPE-IFEC section */
+#define PROTMT_TID  0x7B /* Protection Message section */
+/* TID from 0x7C to 0x7D are reserved for future use */
+#define DIT_TID 0x7E /* Discontinuity Information section */
+#define SIT_TID 0x7F /* Selection Information section */
+/*

[FFmpeg-cvslog] lavc/cook: Remove an incorrect comment.

2019-09-19 Thread Carl Eugen Hoyos
ffmpeg | branch: master | Carl Eugen Hoyos  | Fri Sep 20 
01:36:13 2019 +0200| [f9f9d5943f794f7dc9f5c02d32f6038ad0fede2d] | committer: 
Carl Eugen Hoyos

lavc/cook: Remove an incorrect comment.

Multichannel cook was implemented in 67da3182.

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

 libavcodec/cook.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index c5f68c98ba..aa11205166 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -60,7 +60,7 @@
 #define MONO0x101
 #define STEREO  0x102
 #define JOINT_STEREO0x103
-#define MC_COOK 0x200   // multichannel Cook, not supported
+#define MC_COOK 0x200
 
 #define SUBBAND_SIZE20
 #define MAX_SUBPACKETS   5

___
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] avformat/movenc: don't hardcode the colr box size

2019-09-19 Thread James Almer
ffmpeg | branch: master | James Almer  | Thu Sep 19 21:32:40 
2019 -0300| [179e15dc976510993ba28d7e41559d257b53aff6] | committer: James Almer

avformat/movenc: don't hardcode the colr box size

Signed-off-by: James Almer 

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

 libavformat/movenc.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index edddfeeb00..c824ff5ba1 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1867,6 +1867,8 @@ static int mov_write_gama_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra
 
 static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track)
 {
+int64_t pos = avio_tell(pb);
+
 // Ref (MOV): 
https://developer.apple.com/library/mac/technotes/tn2162/_index.html#//apple_ref/doc/uid/DTS40013070-CH1-TNTAG9
 // Ref (MP4): ISO/IEC 14496-12:2012
 
@@ -1903,7 +1905,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track)
 /* We should only ever be called by MOV or MP4. */
 av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
 
-avio_wb32(pb, 18 + (track->mode == MODE_MP4));
+avio_wb32(pb, 0); /* size */
 ffio_wfourcc(pb, "colr");
 if (track->mode == MODE_MP4)
 ffio_wfourcc(pb, "nclx");
@@ -1940,10 +1942,9 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track)
 if (track->mode == MODE_MP4) {
 int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
 avio_w8(pb, full_range << 7);
-return 19;
-} else {
-return 18;
 }
+
+return update_size(pb, pos);
 }
 
 static void find_compressor(char * compressor_name, int len, MOVTrack *track)

___
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] avcodec/libvpxenc: add ROI-based encoding support for VP8/VP9

2019-09-19 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Thu Sep 12 
18:25:21 2019 +0800| [ecd026a48d63166d97f074f072d36ade1b5d270b] | committer: 
James Zern

avcodec/libvpxenc: add ROI-based encoding support for VP8/VP9

example command line to verify it:
./ffmpeg -i input.stream -vf addroi=0:0:iw/3:ih/3:-0.8 -c:v libvpx -b:v 2M 
tmp.webm

Signed-off-by: Guo, Yejun 
Signed-off-by: James Zern 

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

 libavcodec/libvpxenc.c | 193 +
 libavcodec/version.h   |   2 +-
 2 files changed, 194 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index feb52ea0dd..95100b5516 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -116,6 +116,11 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+/**
+ * If the driver does not support ROI then warn the first time we
+ * encounter a frame with ROI side data.
+ */
+int roi_warned;
 } VPxContext;
 
 /** String mappings for enum vp8e_enc_control_id */
@@ -1057,6 +1062,185 @@ static int queue_frames(AVCodecContext *avctx, AVPacket 
*pkt_out)
 return size;
 }
 
+static int set_roi_map(AVCodecContext *avctx, const AVFrameSideData *sd, int 
frame_width, int frame_height,
+   vpx_roi_map_t *roi_map, int block_size, int segment_cnt)
+{
+/**
+ * range of vpx_roi_map_t.delta_q[i] is [-63, 63]
+ */
+#define MAX_DELTA_Q 63
+
+const AVRegionOfInterest *roi = NULL;
+int nb_rois;
+uint32_t self_size;
+int segment_id;
+
+/* record the mapping from delta_q to "segment id + 1" in 
segment_mapping[].
+ * the range of delta_q is [-MAX_DELTA_Q, MAX_DELTA_Q],
+ * and its corresponding array index is [0, 2 * MAX_DELTA_Q],
+ * and so the length of the mapping array is 2 * MAX_DELTA_Q + 1.
+ * "segment id + 1", so we can say there's no mapping if the value of 
array element is zero.
+ */
+int segment_mapping[2 * MAX_DELTA_Q + 1] = { 0 };
+
+memset(roi_map, 0, sizeof(*roi_map));
+
+/* segment id 0 in roi_map is reserved for the areas not covered by 
AVRegionOfInterest.
+ * segment id 0 in roi_map is also for the areas with 
AVRegionOfInterest.qoffset near 0.
+ * (delta_q of segment id 0 is 0).
+ */
+segment_mapping[MAX_DELTA_Q] = 1;
+segment_id = 1;
+
+roi = (const AVRegionOfInterest*)sd->data;
+self_size = roi->self_size;
+if (!self_size || sd->size % self_size) {
+av_log(avctx, AV_LOG_ERROR, "Invalid AVRegionOfInterest.self_size.\n");
+return AVERROR(EINVAL);
+}
+nb_rois = sd->size / self_size;
+
+/* This list must be iterated from zero because regions are
+ * defined in order of decreasing importance. So discard less
+ * important areas if they exceed the segment count.
+ */
+for (int i = 0; i < nb_rois; i++) {
+int delta_q;
+int mapping_index;
+
+roi = (const AVRegionOfInterest*)(sd->data + self_size * i);
+if (!roi->qoffset.den) {
+av_log(avctx, AV_LOG_ERROR, "AVRegionOfInterest.qoffset.den must 
not be zero.\n");
+return AVERROR(EINVAL);
+}
+
+delta_q = (int)(roi->qoffset.num * 1.0f / roi->qoffset.den * 
MAX_DELTA_Q);
+delta_q = av_clip(delta_q, -MAX_DELTA_Q, MAX_DELTA_Q);
+
+mapping_index = delta_q + MAX_DELTA_Q;
+if (!segment_mapping[mapping_index]) {
+if (segment_id == segment_cnt) {
+av_log(avctx, AV_LOG_WARNING,
+   "ROI only supports %d segments (and segment 0 is 
reserved for non-ROIs), skipping the left ones.\n",
+   segment_cnt);
+break;
+}
+
+segment_mapping[mapping_index] = segment_id + 1;
+roi_map->delta_q[segment_id] = delta_q;
+segment_id++;
+}
+}
+
+roi_map->rows = (frame_height + block_size - 1) / block_size;
+roi_map->cols = (frame_width  + block_size - 1) / block_size;
+roi_map->roi_map = av_mallocz_array(roi_map->rows * roi_map->cols, 
sizeof(*roi_map->roi_map));
+if (!roi_map->roi_map) {
+av_log(avctx, AV_LOG_ERROR, "roi_map alloc failed.\n");
+return AVERROR(ENOMEM);
+}
+
+/* This list must be iterated in reverse, so for the case that
+ * two regions are overlapping, the more important area takes effect.
+ */
+for (int i = nb_rois - 1; i >= 0; i--) {
+int delta_q;
+int mapping_value;
+int starty, endy, startx, endx;
+
+roi = (const AVRegionOfInterest*)(sd->data + self_size * i);
+
+starty = av_clip(roi->top / block_size, 0, roi_map->rows);
+endy   = av_clip((roi->bottom + block_size - 1) / block_size, 0, 
roi_map->rows);
+startx = av_clip(roi->left / block_size, 0, roi_map->cols);
+endx   = av_clip((roi

[FFmpeg-cvslog] Delete unused branch in libaomenc

2019-09-19 Thread elliottk
ffmpeg | branch: master | elliottk  | Sun 
Sep 15 14:02:50 2019 -0700| [ea673a0edb4b32cab54344faedb41bc3473730eb] | 
committer: James Zern

Delete unused branch in libaomenc

this branch is leftover from libvpxenc+vp8

Signed-off-by: James Zern 

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

 libavcodec/libaomenc.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 7f47707a09..e06697c1bf 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -572,15 +572,11 @@ static av_cold int aom_init(AVCodecContext *avctx,
 enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
   AV_ROUND_NEAR_INF);
 } else if (enccfg.rc_end_usage != AOM_Q) {
-if (enccfg.rc_end_usage == AOM_CQ) {
-enccfg.rc_target_bitrate = 100;
-} else {
-enccfg.rc_end_usage = AOM_Q;
-ctx->crf = 32;
-av_log(avctx, AV_LOG_WARNING,
-   "Neither bitrate nor constrained quality specified, using 
default CRF of %d\n",
-   ctx->crf);
-}
+enccfg.rc_end_usage = AOM_Q;
+ctx->crf = 32;
+av_log(avctx, AV_LOG_WARNING,
+   "Neither bitrate nor constrained quality specified, using 
default CRF of %d\n",
+   ctx->crf);
 }
 
 if (avctx->qmin >= 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".