Re: [FFmpeg-devel] [PATCH 2/2] avcodec/fitsdec: Prevent division by 0 with huge data_max

2019-07-15 Thread Reimar Döffinger
On 16.07.2019, at 00:50, Michael Niedermayer  wrote:

> Fixes: division by 0
> Fixes: 
> 15657/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FITS_fuzzer-5738154838982656
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
> libavcodec/fitsdec.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> index 4f452422ef..fe941f199d 100644
> --- a/libavcodec/fitsdec.c
> +++ b/libavcodec/fitsdec.c
> @@ -174,7 +174,7 @@ static int fits_read_header(AVCodecContext *avctx, const 
> uint8_t **ptr, FITSHead
> return AVERROR_INVALIDDATA;
> }
> av_log(avctx, AV_LOG_WARNING, "data min/max indicates a blank 
> image\n");
> -header->data_max ++;
> +header->data_max += fabs(header->data_max) / 1000 + 1;

This is really non-obvious, both by itself, in where/how it causes the division 
by 0 and that the error here isn't worse than the division by 0 for example, 
and why this constant was chosen.
Also why a division and not a multiply by the inverse?
Why not * (1.0f / (1 << 24)) for example, which for single-precision IEEE I 
think should result in exactly 1 ULP (well, possibly 2 with rounding) 
increments?
Why is this even using floating-point? And why not double-precision at least?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/sanm: Check extradata_size before allocations

2019-07-15 Thread Reimar Döffinger
On 16.07.2019, at 00:50, Michael Niedermayer  wrote:

> Fixes: Leaks
> Fixes: 
> 15349/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SANM_fuzzer-5102530557640704
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
> libavcodec/sanm.c | 9 -
> 1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
> index 25aee7220f..60e2f4c624 100644
> --- a/libavcodec/sanm.c
> +++ b/libavcodec/sanm.c
> @@ -491,6 +491,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
> 
> ctx->avctx   = avctx;
> ctx->version = !avctx->extradata_size;
> +if (!ctx->version && avctx->extradata_size < 1026) {
> +av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n");
> +return AVERROR_INVALIDDATA;
> +}
> 
> avctx->pix_fmt = ctx->version ? AV_PIX_FMT_RGB565 : AV_PIX_FMT_PAL8;
> 
> @@ -506,11 +510,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
> if (!ctx->version) {
> int i;
> 
> -if (avctx->extradata_size < 1026) {
> -av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n");
> -return AVERROR_INVALIDDATA;
> -}

This seems quite a bit less obvious.
Is that the only error return case, and is adding the cleanup code complex 
enough that this is the better choice?
Either way I'd recommend a comment like
// early sanity check before allocations to avoid need for deallocation code.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] how to create sub project / git repo under FFMPEG

2019-07-15 Thread Guo, Yejun
Hi Michael,

With the development of ffmpeg dnn module, there is a need to get a git repo, 
controlled by FFMPEG, to hold dnn materials, such as training scripts, trained 
parameters etc, as discussed at 
http://ffmpeg.org/pipermail/ffmpeg-devel/2019-June/245750.html.

Could you please let me know how to create a sub project / git repo under 
FFMPEG? thanks.

Best Regards,
Yejun

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

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

[FFmpeg-devel] [PATCH 4/4] dnn: convert tf.pad to native model in python script, and load/execute it in the c code.

2019-07-15 Thread Guo, Yejun
since tf.pad is enabled, the conv2d(valid) changes back to its original 
behavior.

Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/dnn_backend_native.c| 35 +
 libavfilter/dnn/dnn_backend_native.h|  2 +-
 tools/python/convert_from_tensorflow.py | 23 +-
 3 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native.c 
b/libavfilter/dnn/dnn_backend_native.c
index 82e900b..09c583b 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -25,6 +25,7 @@
 
 #include "dnn_backend_native.h"
 #include "libavutil/avassert.h"
+#include "dnn_backend_native_layer_pad.h"
 
 static DNNReturnType set_input_output_native(void *model, DNNInputData *input, 
const char *input_name, const char **output_names, uint32_t nb_output)
 {
@@ -32,6 +33,7 @@ static DNNReturnType set_input_output_native(void *model, 
DNNInputData *input, c
 InputParams *input_params;
 ConvolutionalParams *conv_params;
 DepthToSpaceParams *depth_to_space_params;
+LayerPadParams *pad_params;
 int cur_width, cur_height, cur_channels;
 int32_t layer;
 
@@ -77,6 +79,12 @@ static DNNReturnType set_input_output_native(void *model, 
DNNInputData *input, c
 cur_height *= depth_to_space_params->block_size;
 cur_width *= depth_to_space_params->block_size;
 break;
+case MIRROR_PAD:
+pad_params = (LayerPadParams *)network->layers[layer].params;
+cur_height = cur_height + pad_params->paddings[1][0] + 
pad_params->paddings[1][1];
+cur_width = cur_width + pad_params->paddings[2][0] + 
pad_params->paddings[2][1];
+cur_channels = cur_channels + pad_params->paddings[3][0] + 
pad_params->paddings[3][1];
+break;
 default:
 return DNN_ERROR;
 }
@@ -110,6 +118,7 @@ DNNModel *ff_dnn_load_model_native(const char 
*model_filename)
 DNNLayerType layer_type;
 ConvolutionalParams *conv_params;
 DepthToSpaceParams *depth_to_space_params;
+LayerPadParams *pad_params;
 
 model = av_malloc(sizeof(DNNModel));
 if (!model){
@@ -207,6 +216,23 @@ DNNModel *ff_dnn_load_model_native(const char 
*model_filename)
 network->layers[layer].type = DEPTH_TO_SPACE;
 network->layers[layer].params = depth_to_space_params;
 break;
+case MIRROR_PAD:
+pad_params = av_malloc(sizeof(LayerPadParams));
+if (!pad_params){
+avio_closep(&model_file_context);
+ff_dnn_free_model_native(&model);
+return NULL;
+}
+pad_params->mode = (int32_t)avio_rl32(model_file_context);
+dnn_size += 4;
+for (i = 0; i < 4; ++i) {
+pad_params->paddings[i][0] = avio_rl32(model_file_context);
+pad_params->paddings[i][1] = avio_rl32(model_file_context);
+dnn_size += 8;
+}
+network->layers[layer].type = MIRROR_PAD;
+network->layers[layer].params = pad_params;
+break;
 default:
 avio_closep(&model_file_context);
 ff_dnn_free_model_native(&model);
@@ -314,6 +340,7 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel 
*model, DNNData *output
 InputParams *input_params;
 ConvolutionalParams *conv_params;
 DepthToSpaceParams *depth_to_space_params;
+LayerPadParams *pad_params;
 
 if (network->layers_num <= 0 || network->layers[0].type != INPUT || 
!network->layers[0].output){
 return DNN_ERROR;
@@ -348,6 +375,14 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel 
*model, DNNData *output
 cur_width *= depth_to_space_params->block_size;
 cur_channels /= depth_to_space_params->block_size * 
depth_to_space_params->block_size;
 break;
+case MIRROR_PAD:
+pad_params = (LayerPadParams *)network->layers[layer].params;
+dnn_execute_layer_pad(network->layers[layer - 1].output, 
network->layers[layer].output,
+  pad_params, 1, cur_height, cur_width, 
cur_channels);
+cur_height = cur_height + pad_params->paddings[1][0] + 
pad_params->paddings[1][1];
+cur_width = cur_width + pad_params->paddings[2][0] + 
pad_params->paddings[2][1];
+cur_channels = cur_channels + pad_params->paddings[3][0] + 
pad_params->paddings[3][1];
+break;
 case INPUT:
 return DNN_ERROR;
 }
diff --git a/libavfilter/dnn/dnn_backend_native.h 
b/libavfilter/dnn/dnn_backend_native.h
index 532103c..c615d59 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -30,7 +30,7 @@
 #include "../dnn_interface.h"
 #include "libavformat/avio.h"
 
-typedef enum {INPUT, CONV, DEPTH_TO_SPACE} DNNLayerType;
+typedef enum {INPUT, CONV, DEPTH_TO_SPACE

[FFmpeg-devel] [PATCH 3/4] fate: add unit test for dnn-layer-pad

2019-07-15 Thread Guo, Yejun
'make fate-dnn-layer-pad' to run the test

Signed-off-by: Guo, Yejun 
---
 tests/Makefile |   5 +-
 tests/dnn/Makefile |  11 +++
 tests/dnn/dnn-layer-pad-test.c | 201 +
 tests/fate/dnn.mak |   8 ++
 4 files changed, 224 insertions(+), 1 deletion(-)
 create mode 100644 tests/dnn/Makefile
 create mode 100644 tests/dnn/dnn-layer-pad-test.c
 create mode 100644 tests/fate/dnn.mak

diff --git a/tests/Makefile b/tests/Makefile
index 624292d..0ef571b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -10,7 +10,8 @@ FFMPEG=ffmpeg$(PROGSSUF)$(EXESUF)
 $(AREF): CMP=
 
 APITESTSDIR := tests/api
-FATE_OUTDIRS = tests/data tests/data/fate tests/data/filtergraphs 
tests/data/lavf tests/data/lavf-fate tests/data/pixfmt tests/vsynth1 
$(APITESTSDIR)
+DNNTESTSDIR := tests/dnn
+FATE_OUTDIRS = tests/data tests/data/fate tests/data/filtergraphs 
tests/data/lavf tests/data/lavf-fate tests/data/pixfmt tests/vsynth1 
$(APITESTSDIR) $(DNNTESTSDIR)
 OUTDIRS += $(FATE_OUTDIRS)
 
 $(VREF): tests/videogen$(HOSTEXESUF) | tests/vsynth1
@@ -85,6 +86,7 @@ FILTERDEMDECENCMUX = $(call ALLYES, $(1:%=%_FILTER) 
$(2)_DEMUXER $(3)_DECODER $(
 PARSERDEMDEC   = $(call ALLYES, $(1)_PARSER $(2)_DEMUXER $(3)_DECODER)
 
 include $(SRC_PATH)/$(APITESTSDIR)/Makefile
+include $(SRC_PATH)/$(DNNTESTSDIR)/Makefile
 
 include $(SRC_PATH)/tests/fate/acodec.mak
 include $(SRC_PATH)/tests/fate/vcodec.mak
@@ -118,6 +120,7 @@ include $(SRC_PATH)/tests/fate/cover-art.mak
 include $(SRC_PATH)/tests/fate/dca.mak
 include $(SRC_PATH)/tests/fate/demux.mak
 include $(SRC_PATH)/tests/fate/dfa.mak
+include $(SRC_PATH)/tests/fate/dnn.mak
 include $(SRC_PATH)/tests/fate/dnxhd.mak
 include $(SRC_PATH)/tests/fate/dpcm.mak
 include $(SRC_PATH)/tests/fate/ea.mak
diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile
new file mode 100644
index 000..b2e6680
--- /dev/null
+++ b/tests/dnn/Makefile
@@ -0,0 +1,11 @@
+DNNTESTPROGS += dnn-layer-pad
+
+DNNTESTOBJS  := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) 
$(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
+DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
+-include $(wildcard $(DNNTESTOBJS:.o=.d))
+
+$(DNNTESTPROGS): %$(EXESUF): %.o $(FF_DEP_LIBS)
+   $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(filter %.o,$^) $(FF_EXTRALIBS) 
$(ELIBS)
+
+testclean::
+   $(RM) $(addprefix $(DNNTESTSDIR)/,$(CLEANSUFFIXES) *-test$(EXESUF))
diff --git a/tests/dnn/dnn-layer-pad-test.c b/tests/dnn/dnn-layer-pad-test.c
new file mode 100644
index 000..fe8eaca
--- /dev/null
+++ b/tests/dnn/dnn-layer-pad-test.c
@@ -0,0 +1,201 @@
+/*
+ * 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_pad.h"
+
+#define EPSON 0.1
+
+static int test_with_mode_symmetric(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.pad(x, [[0, 0], [2, 3], [3, 2], [0, 0]], 'SYMMETRIC')
+data = np.arange(48).reshape(1, 4, 4, 3);
+
+sess=tf.Session()
+sess.run(tf.global_variables_initializer())
+output = sess.run(y, feed_dict={x: data})
+
+print(list(data.flatten()))
+print(list(output.flatten()))
+print(data.shape)
+print(output.shape)
+*/
+
+LayerPadParams params;
+float input[1*4*4*3] = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 
40, 41, 42, 43, 44, 45, 46, 47
+};
+float expected_output[1*9*9*3] = {
+18.0, 19.0, 20.0, 15.0, 16.0, 17.0, 12.0, 13.0, 14.0, 12.0, 13.0, 
14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 21.0, 22.0, 23.0, 
18.0, 19.0, 20.0, 6.0, 7.0, 8.0, 3.0,
+4.0, 5.0, 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 
9.0, 10.0, 11.0, 9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 6.0, 7.0, 8.0, 3.0, 4.0, 5.0, 
0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0,
+4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 9.0, 10.0, 11.0, 6.0, 7.0, 
8.0, 18.0, 19.0, 20.0, 15.0, 16.0, 17.0, 12.0, 13.0, 14.0, 12.0, 13.0, 14.0, 
15.0, 16.0, 17.0, 18.0, 19.0, 20.0,
+   

[FFmpeg-devel] [PATCH 1/4] libavfilter/dnn: move dnn files from libavfilter to libavfilter/dnn

2019-07-15 Thread Guo, Yejun
it is expected that there will be more files to support native mode,
so put all the dnn codes under libavfilter/dnn

The main change of this patch is to move the file location, see below:
modified:   libavfilter/Makefile
new file:   libavfilter/dnn/Makefile
renamed:libavfilter/dnn_backend_native.c -> 
libavfilter/dnn/dnn_backend_native.c
renamed:libavfilter/dnn_backend_native.h -> 
libavfilter/dnn/dnn_backend_native.h
renamed:libavfilter/dnn_backend_tf.c -> libavfilter/dnn/dnn_backend_tf.c
renamed:libavfilter/dnn_backend_tf.h -> libavfilter/dnn/dnn_backend_tf.h
renamed:libavfilter/dnn_interface.c -> libavfilter/dnn/dnn_interface.c

Signed-off-by: Guo, Yejun 
---
 libavfilter/Makefile |   3 +-
 libavfilter/dnn/Makefile |   6 +
 libavfilter/dnn/dnn_backend_native.c | 389 ++
 libavfilter/dnn/dnn_backend_native.h |  74 +
 libavfilter/dnn/dnn_backend_tf.c | 603 +++
 libavfilter/dnn/dnn_backend_tf.h |  38 +++
 libavfilter/dnn/dnn_interface.c  |  63 
 libavfilter/dnn_backend_native.c | 389 --
 libavfilter/dnn_backend_native.h |  74 -
 libavfilter/dnn_backend_tf.c | 603 ---
 libavfilter/dnn_backend_tf.h |  38 ---
 libavfilter/dnn_interface.c  |  63 
 12 files changed, 1174 insertions(+), 1169 deletions(-)
 create mode 100644 libavfilter/dnn/Makefile
 create mode 100644 libavfilter/dnn/dnn_backend_native.c
 create mode 100644 libavfilter/dnn/dnn_backend_native.h
 create mode 100644 libavfilter/dnn/dnn_backend_tf.c
 create mode 100644 libavfilter/dnn/dnn_backend_tf.h
 create mode 100644 libavfilter/dnn/dnn_interface.c
 delete mode 100644 libavfilter/dnn_backend_native.c
 delete mode 100644 libavfilter/dnn_backend_native.h
 delete mode 100644 libavfilter/dnn_backend_tf.c
 delete mode 100644 libavfilter/dnn_backend_tf.h
 delete mode 100644 libavfilter/dnn_interface.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 455c809..450d781 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -26,9 +26,8 @@ OBJS-$(HAVE_THREADS) += pthread.o
 
 # subsystems
 OBJS-$(CONFIG_QSVVPP)+= qsvvpp.o
-DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn_backend_tf.o
-OBJS-$(CONFIG_DNN)   += dnn_interface.o 
dnn_backend_native.o $(DNN-OBJS-yes)
 OBJS-$(CONFIG_SCENE_SAD) += scene_sad.o
+include $(SRC_PATH)/libavfilter/dnn/Makefile
 
 # audio filters
 OBJS-$(CONFIG_ABENCH_FILTER) += f_bench.o
diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
new file mode 100644
index 000..1d12ade
--- /dev/null
+++ b/libavfilter/dnn/Makefile
@@ -0,0 +1,6 @@
+OBJS-$(CONFIG_DNN)   += dnn/dnn_interface.o
+OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native.o
+
+DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
+
+OBJS-$(CONFIG_DNN)   += $(DNN-OBJS-yes)
diff --git a/libavfilter/dnn/dnn_backend_native.c 
b/libavfilter/dnn/dnn_backend_native.c
new file mode 100644
index 000..82e900b
--- /dev/null
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -0,0 +1,389 @@
+/*
+ * Copyright (c) 2018 Sergey Lavrushkin
+ *
+ * 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"
+
+static DNNReturnType set_input_output_native(void *model, DNNInputData *input, 
const char *input_name, const char **output_names, uint32_t nb_output)
+{
+ConvolutionalNetwork *network = (ConvolutionalNetwork *)model;
+InputParams *input_params;
+ConvolutionalParams *conv_params;
+DepthToSpaceParams *depth_to_space_params;
+int cur_width, cur_height, cur_channels;
+int32_t layer;
+
+if (network->layers_num <= 0 || network->layers[0].type != INPUT){
+return DNN_ERROR;
+}
+else{
+input_params = (InputParams *)network->layers[0].params;
+input_params->width = cur_width = input->width;
+input_params->height = cur_height = input->height;
+input_params->chann

[FFmpeg-devel] [PATCH 2/4] dnn: add layer pad which is equivalent to tf.pad

2019-07-15 Thread Guo, Yejun
the reason to add this layer first is that vf_sr uses it in its
tensorflow model, and the next plan is to update the python script
to convert tf.pad into native model.

Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/Makefile   |   1 +
 libavfilter/dnn/dnn_backend_native_layer_pad.c | 211 +
 libavfilter/dnn/dnn_backend_native_layer_pad.h |  40 +
 3 files changed, 252 insertions(+)
 create mode 100644 libavfilter/dnn/dnn_backend_native_layer_pad.c
 create mode 100644 libavfilter/dnn/dnn_backend_native_layer_pad.h

diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index 1d12ade..83938e5 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -1,5 +1,6 @@
 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
 
 DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
 
diff --git a/libavfilter/dnn/dnn_backend_native_layer_pad.c 
b/libavfilter/dnn/dnn_backend_native_layer_pad.c
new file mode 100644
index 000..aa12f7f
--- /dev/null
+++ b/libavfilter/dnn/dnn_backend_native_layer_pad.c
@@ -0,0 +1,211 @@
+/*
+ * 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 "libavutil/avassert.h"
+#include "dnn_backend_native_layer_pad.h"
+
+static int before_get_buddy(int given, int paddings, LayerPadModeParam mode)
+{
+if (mode == LPMP_SYMMETRIC) {
+return (2 * paddings - 1 - given);
+} else if (mode == LPMP_REFLECT) {
+return (2 * paddings - given);
+} else {
+av_assert0(!"should not reach here");
+return 0;
+}
+}
+
+static int after_get_buddy(int given, int border, LayerPadModeParam mode)
+{
+if (mode == LPMP_SYMMETRIC) {
+int offset = given - border;
+return (border - 1 - offset);
+} else if (mode == LPMP_REFLECT) {
+int offset = given - border;
+return (border - 2 - offset);
+} else {
+av_assert0(!"should not reach here");
+return 0;
+}
+}
+
+void dnn_execute_layer_pad(const float *input, float *output, const 
LayerPadParams *params, int number, int height, int width, int channel)
+{
+int32_t before_paddings;
+int32_t after_paddings;
+
+// suppose format is 
+int new_number = number + params->paddings[0][0] + params->paddings[0][1];
+int new_height = height + params->paddings[1][0] + params->paddings[1][1];
+int new_width = width + params->paddings[2][0] + params->paddings[2][1];
+int new_channel = channel + params->paddings[3][0] + 
params->paddings[3][1];
+
+int c_stride = channel;
+int wc_stride = c_stride * width;
+int hwc_stride = wc_stride * height;
+
+int new_c_stride = new_channel;
+int new_wc_stride = new_c_stride * new_width;
+int new_hwc_stride = new_wc_stride * new_height;
+
+// copy the original data
+for (int n = 0; n < number; n++) {
+for (int h = 0; h < height; h++) {
+for (int w = 0; w < width; w++) {
+const float *src = input + n * hwc_stride + h * wc_stride + w 
* c_stride;
+float *dst = output + (n + params->paddings[0][0]) * 
new_hwc_stride
++ (h + params->paddings[1][0]) * 
new_wc_stride
++ (w + params->paddings[2][0]) * 
new_c_stride
++ params->paddings[3][0];
+memcpy(dst, src, channel * sizeof(float));
+}
+}
+}
+
+// handle the first dimension
+before_paddings = params->paddings[0][0];
+after_paddings = params->paddings[0][1];
+for (int n = 0; n < before_paddings; n++) {
+float *dst = output + n * new_hwc_stride;
+if (params->mode == LPMP_CONSTANT) {
+for (int i = 0; i < new_hwc_stride; i++) {
+*dst = params->constant_values;
+}
+}
+else {
+int buddy = before_get_buddy(n, before_paddings, params->mode);
+float *src = output + buddy * new_hwc_stride;
+memcpy(dst, src, new_hwc_strid

Re: [FFmpeg-devel] [PATCH 1/2] dnn: add layer pad which is equivalent to tf.pad

2019-07-15 Thread Guo, Yejun

> > -Original Message-
> > From: Guo, Yejun
> > Sent: Monday, July 01, 2019 4:08 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Guo, Yejun 
> > Subject: [PATCH 1/2] dnn: add layer pad which is equivalent to tf.pad
> >
> > the reason to add this layer first is that vf_sr uses it in its
> > tensorflow model, and the next plan is to update the python script
> > to convert tf.pad into native model.
> >
> > Signed-off-by: Guo, Yejun 
> 
> this patch set is based on a previous patch at
> http://ffmpeg.org/pipermail/ffmpeg-devel/2019-June/245481.html
> (libavfilter/dnn: move dnn files from libavfilter to libavfilter/dnn)

hello, I've finished 10+ new patches locally to improve dnn module, including 
one new patch relative to pad.

I'll resend this patch set, together with the new pad relative patch.

I'll send more patches set by set, once the previous patch set is pushed, since 
the patches have dependency.

Just in case you are interested in my new patches, I've uploaded to 
https://github.com/guoyejun/ffmpeg/tree/dnn0716. 
for your convenient, I also copy the oneline log here for each patch (from 
newer to older) with 3 patch sets.

50a3353 fate: add unit test for dnn depth_to_space layer
af9e3ab dnn: separate depth_to_space layer from dnn_backend_native.c to a new 
file
41b97e4 fate: add unit test for dnn conv2d layer
4143485 dnn: separate conv2d layer from dnn_backend_native.c to a new file

870383e dnn: export operand info in python script and load in c code
650d576 dnn: change .model file format to put layer number at the end of file
d029bf8 dnn: introduce dnn operand (in c code) to hold operand infos within 
network

c9b9e1c doc/filters: update how to generate native model for derain filter
064aa45 convert_from_tensorflow.py: support conv2d with dilation
1c419a5 convert_from_tensorflow.py: add option to dump graph for visualization 
in tensorboard


I'll continue to improve dnn module, such as:
- update dnn interface since we have more operand info (names, types, dims) in 
native mode.
- optimize native conv2d layer
- add more native layers to support at least mobile net as a milestone
- add a general filter which generates analysis result (in a general side data 
for AVFrame) with dnn network.
- add a general filter which changes the content of AVFrame with dnn network.

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

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

Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for autoscale/autorotate

2019-07-15 Thread Fu, Linjie
> -Original Message-
> From: Nicolas George [mailto:geo...@nsup.org]
> Sent: Monday, July 15, 2019 22:00
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Fu, Linjie 
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for
> autoscale/autorotate
> 
> Linjie Fu (12019-07-15):
> > Add docs for autoscale/noautoscale.
> 
> This belongs in the path that adds them.

A little bit confused on this.
Improper position in doc for these options or  I need to add docs together with
code in one patch?
 
> >
> > Update information for autorotate according to ffplay.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> >  doc/ffmpeg.texi | 11 +++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> > index cd35eb49c8..040a2b53cf 100644
> > --- a/doc/ffmpeg.texi
> > +++ b/doc/ffmpeg.texi
> > @@ -735,9 +735,20 @@ Technical note -- attachments are implemented as
> codec extradata, so this
> >  option can actually be used to extract extradata from any stream, not just
> >  attachments.
> >
> > +@item -autorotate
> > +Automatically rotate the video according to file metadata. Enabled by
> > +default, use @option{-noautorotate} to disable it.
> > +
> > +@item -autoscale
> > +Automatically scale the video according to the resolution of first frame.
> > +Enabled by default, use @option{-noautoscale} to disable it.
> > +
> >  @item -noautorotate
> >  Disable automatically rotating video based on file metadata.
> >
> 
> > +@item -noautoscale
> > +Disable automatically scale video based on first frame resolution.
> 
> You neglected to explain the drawbacks.

Yes, can add something like:
"Each frame of the output raw video can in different resolutions
and is in need to be handled in following pipeline like vpp/encode."

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

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

Re: [FFmpeg-devel] [PATCH] lavf/vf_freezedetect: improve for the freeze frame detection

2019-07-15 Thread Limin Wang
On Mon, Jul 15, 2019 at 11:07:32PM +0200, Marton Balint wrote:
> 
> 
> On Mon, 15 Jul 2019, Limin Wang wrote:
> 
> [...]
> 
> >if (s->width[plane]) {
> >uint64_t plane_sad;
> >s->sad(frame->data[plane], frame->linesize[plane],
> >@@ -140,8 +146,12 @@ static int is_frozen(FreezeDetectContext *s, 
> >AVFrame *reference, AVFrame *frame)
> >}
> >}
> >emms_c();
> >-mafd = (double)sad / count / (1ULL << s->bitdepth);
> >-return (mafd <= s->noise);
> >+mafd = (double)sad /(count >> (s->bitdepth > 8));
> 
> Why? MAFD should be the mean difference normalized to [0..1].
> >>>if the bitdeth is 16, it'll divide by 1UL << 16, it'll cause the mafd is
> >>>very small. So I choose the scenecut way in the below.
> >>
> >>The metric supposed to be indepentent of the bit depth. If you get
> >>different mafd for the same source expressed in 8bit, 10bit or 16bit
> >>pixel format (provided that you use the same subsampling), then you
> >>are doing something wrong.
> >>
> >>And you can't reinvent MAFD according to your needs. It is the mean
> >>absolute difference of the whole image normalized to 0..1 in this
> >>case. If you are not calculating that, then it is not MAFD.
> >
> >Sorry, now the scenecut detection support rgb only, so I'm
> >changing it to support more format without autoscale, it'll
> >necessary to solved how to calculated mafd for
> >10bits or 12bits. Below is my understanding for the mafd
> >calculation, correct me if I'm misunderstanding. for example, if
> >the bitdepth is 8 bits, it means the pixel block is 8x8 pixel, so
> >maybe we should divide 8x8 instead of 256?
> >
> >mafd = sad / count / (bitdepth * bitdepth)
> 
> bitdepth is the bitdepth of one pixel. For 8 bit, a color component can be
> 0..255. For 16 bit, a color component can be 0..65535.
> 
> 8x8 and 16x16 pixel blocks are totally different and unrelated
> things from bit depth. Yes, SAD is usually calculated for 8x8 or
> 16x16 blocks for motion estimation or compression, not here. Here,
> SAD is the sum of absolute differences throughout the entire image,
> (width x height). Count = width * height, so SAD/count is the
> average of differences. In order to get it to [0..1] you have to
> divide by 2^bitdepth.
Thank you, I think I'm clear for the code, the 2^bitdepth is only for
normalize.

I have submited the scenecut detected change for more format support. 
For the result is little different with rgb format and I haven't good way
to sure it's expected result.  

https://patchwork.ffmpeg.org/patch/13957/

> 
> Regards,
> Marton
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 3/3] lavf/f_select: make the more pixel format usable to avoid autoscale to rgb

2019-07-15 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavfilter/f_select.c |  6 ++
 tests/ref/fate/filter-metadata-scenedetect | 16 
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
index eed8df3..35aed3f 100644
--- a/libavfilter/f_select.c
+++ b/libavfilter/f_select.c
@@ -499,6 +499,12 @@ static int query_formats(AVFilterContext *ctx)
 int ret;
 static const enum AVPixelFormat pix_fmts[] = {
 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
+AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, AV_PIX_FMT_RGBA,
+AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA, AV_PIX_FMT_GRAY8,
+AV_PIX_FMT_GRAY16, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10,
+AV_PIX_FMT_YUYV422, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10,
+AV_PIX_FMT_NV12, AV_PIX_FMT_NV21, AV_PIX_FMT_P010,
+AV_PIX_FMT_P016, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
 AV_PIX_FMT_NONE
 };
 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
diff --git a/tests/ref/fate/filter-metadata-scenedetect 
b/tests/ref/fate/filter-metadata-scenedetect
index 67c23b3..7ce2d67 100644
--- a/tests/ref/fate/filter-metadata-scenedetect
+++ b/tests/ref/fate/filter-metadata-scenedetect
@@ -1,11 +1,11 @@
 pkt_pts=1620|tag:lavfi.scene_score=1.00
-pkt_pts=4140|tag:lavfi.scene_score=0.875036
-pkt_pts=5800|tag:lavfi.scene_score=1.00
-pkt_pts=6720|tag:lavfi.scene_score=0.461625
-pkt_pts=8160|tag:lavfi.scene_score=1.00
-pkt_pts=9760|tag:lavfi.scene_score=1.00
-pkt_pts=14080|tag:lavfi.scene_score=0.838916
+pkt_pts=4140|tag:lavfi.scene_score=0.668643
+pkt_pts=5800|tag:lavfi.scene_score=0.996721
+pkt_pts=6720|tag:lavfi.scene_score=0.357390
+pkt_pts=8160|tag:lavfi.scene_score=0.886268
+pkt_pts=9760|tag:lavfi.scene_score=0.926219
+pkt_pts=14080|tag:lavfi.scene_score=0.650033
 pkt_pts=15700|tag:lavfi.scene_score=1.00
-pkt_pts=18500|tag:lavfi.scene_score=0.474948
-pkt_pts=20040|tag:lavfi.scene_score=0.379700
+pkt_pts=18500|tag:lavfi.scene_score=0.316402
+pkt_pts=20040|tag:lavfi.scene_score=0.269509
 pkt_pts=21760|tag:lavfi.scene_score=1.00
-- 
2.6.4

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

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

[FFmpeg-devel] [PATCH 2/3] fate: change the scenecut fate threshold for one more scenecut scenes

2019-07-15 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 tests/fate/filter-video.mak| 2 +-
 tests/ref/fate/filter-metadata-scenedetect | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 1042e96..60c6be1 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -734,7 +734,7 @@ SCENEDETECT_DEPS = FFPROBE LAVFI_INDEV MOVIE_FILTER 
SELECT_FILTER SCALE_FILTER \
AVCODEC AVDEVICE MOV_DEMUXER SVQ3_DECODER ZLIB
 FATE_METADATA_FILTER-$(call ALLYES, $(SCENEDETECT_DEPS)) += 
fate-filter-metadata-scenedetect
 fate-filter-metadata-scenedetect: SRC = 
$(TARGET_SAMPLES)/svq3/Vertical400kbit.sorenson3.mov
-fate-filter-metadata-scenedetect: CMD = run $(FILTER_METADATA_COMMAND) 
"sws_flags=+accurate_rnd+bitexact;movie='$(SRC)',select=gt(scene\,.4)"
+fate-filter-metadata-scenedetect: CMD = run $(FILTER_METADATA_COMMAND) 
"sws_flags=+accurate_rnd+bitexact;movie='$(SRC)',select=gt(scene\,.25)"
 
 CROPDETECT_DEPS = FFPROBE LAVFI_INDEV MOVIE_FILTER CROPDETECT_FILTER 
SCALE_FILTER \
   AVCODEC AVDEVICE MOV_DEMUXER H264_DECODER
diff --git a/tests/ref/fate/filter-metadata-scenedetect 
b/tests/ref/fate/filter-metadata-scenedetect
index d04054a..67c23b3 100644
--- a/tests/ref/fate/filter-metadata-scenedetect
+++ b/tests/ref/fate/filter-metadata-scenedetect
@@ -7,4 +7,5 @@ pkt_pts=9760|tag:lavfi.scene_score=1.00
 pkt_pts=14080|tag:lavfi.scene_score=0.838916
 pkt_pts=15700|tag:lavfi.scene_score=1.00
 pkt_pts=18500|tag:lavfi.scene_score=0.474948
+pkt_pts=20040|tag:lavfi.scene_score=0.379700
 pkt_pts=21760|tag:lavfi.scene_score=1.00
-- 
2.6.4

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

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

[FFmpeg-devel] [PATCH 1/3] lavf/f_select: support scenecut with more pixel formats

2019-07-15 Thread lance . lmwang
From: Limin Wang 

This patch haven't make other pixel format usable yet to make sure the test
result is same with rgb format.

Signed-off-by: Limin Wang 
---
 libavfilter/f_select.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
index 1132375..eed8df3 100644
--- a/libavfilter/f_select.c
+++ b/libavfilter/f_select.c
@@ -28,6 +28,8 @@
 #include "libavutil/fifo.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "audio.h"
 #include "formats.h"
@@ -144,6 +146,10 @@ typedef struct SelectContext {
 char *expr_str;
 AVExpr *expr;
 double var_values[VAR_VARS_NB];
+int bitdepth;
+int nb_planes;
+ptrdiff_t width[4];
+ptrdiff_t height[4];
 int do_scene_detect;///< 1 if the expression requires scene 
detection variables, 0 otherwise
 ff_scene_sad_fn sad;///< Sum of the absolute difference 
function (scene detect only)
 double prev_mafd;   ///< previous MAFD 
  (scene detect only)
@@ -202,6 +208,17 @@ static av_cold int init(AVFilterContext *ctx)
 static int config_input(AVFilterLink *inlink)
 {
 SelectContext *select = inlink->dst->priv;
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+
+select->bitdepth = desc->comp[0].depth;
+select->nb_planes = av_pix_fmt_count_planes(inlink->format);
+for (int plane = 0; plane < select->nb_planes; plane++) {
+ptrdiff_t line_size = av_image_get_linesize(inlink->format, inlink->w, 
plane);
+int vsub = desc->log2_chroma_h;
+
+select->width[plane] = line_size >> (select->bitdepth > 8);
+select->height[plane] = plane == 1 || plane == 2 ?  
AV_CEIL_RSHIFT(inlink->h, vsub) : inlink->h;
+}
 
 select->var_values[VAR_N]  = 0.0;
 select->var_values[VAR_SELECTED_N] = 0.0;
@@ -242,7 +259,7 @@ static int config_input(AVFilterLink *inlink)
 inlink->type == AVMEDIA_TYPE_AUDIO ? inlink->sample_rate : NAN;
 
 if (CONFIG_SELECT_FILTER && select->do_scene_detect) {
-select->sad = ff_scene_sad_get_fn(8);
+select->sad = ff_scene_sad_get_fn(select->bitdepth == 8 ? 8 : 16);
 if (!select->sad)
 return AVERROR(EINVAL);
 }
@@ -258,12 +275,21 @@ static double get_scene_score(AVFilterContext *ctx, 
AVFrame *frame)
 if (prev_picref &&
 frame->height == prev_picref->height &&
 frame->width  == prev_picref->width) {
-uint64_t sad;
+uint64_t sad = 0;
 double mafd, diff;
+int count = 0;
+
+for (int plane = 0; plane < select->nb_planes; plane++) {
+uint64_t plane_sad;
+select->sad(prev_picref->data[plane], prev_picref->linesize[plane],
+frame->data[plane], frame->linesize[plane],
+select->width[plane], select->height[plane], &plane_sad);
+sad += plane_sad;
+count += select->width[plane] * select->height[plane];
+}
 
-select->sad(prev_picref->data[0], prev_picref->linesize[0], 
frame->data[0], frame->linesize[0], frame->width * 3, frame->height, &sad);
 emms_c();
-mafd = (double)sad / (frame->width * 3 * frame->height);
+mafd = (double)sad / count;
 diff = fabs(mafd - select->prev_mafd);
 ret  = av_clipf(FFMIN(mafd, diff) / 100., 0, 1);
 select->prev_mafd = mafd;
-- 
2.6.4

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

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

[FFmpeg-devel] [PATCH 2/2] avcodec/fitsdec: Prevent division by 0 with huge data_max

2019-07-15 Thread Michael Niedermayer
Fixes: division by 0
Fixes: 
15657/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FITS_fuzzer-5738154838982656

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/fitsdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
index 4f452422ef..fe941f199d 100644
--- a/libavcodec/fitsdec.c
+++ b/libavcodec/fitsdec.c
@@ -174,7 +174,7 @@ static int fits_read_header(AVCodecContext *avctx, const 
uint8_t **ptr, FITSHead
 return AVERROR_INVALIDDATA;
 }
 av_log(avctx, AV_LOG_WARNING, "data min/max indicates a blank 
image\n");
-header->data_max ++;
+header->data_max += fabs(header->data_max) / 1000 + 1;
 }
 
 return 0;
-- 
2.22.0

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

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

[FFmpeg-devel] [PATCH 1/2] avcodec/sanm: Check extradata_size before allocations

2019-07-15 Thread Michael Niedermayer
Fixes: Leaks
Fixes: 
15349/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SANM_fuzzer-5102530557640704

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/sanm.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 25aee7220f..60e2f4c624 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -491,6 +491,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 ctx->avctx   = avctx;
 ctx->version = !avctx->extradata_size;
+if (!ctx->version && avctx->extradata_size < 1026) {
+av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n");
+return AVERROR_INVALIDDATA;
+}
 
 avctx->pix_fmt = ctx->version ? AV_PIX_FMT_RGB565 : AV_PIX_FMT_PAL8;
 
@@ -506,11 +510,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
 if (!ctx->version) {
 int i;
 
-if (avctx->extradata_size < 1026) {
-av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n");
-return AVERROR_INVALIDDATA;
-}
-
 ctx->subversion = AV_RL16(avctx->extradata);
 for (i = 0; i < PALETTE_SIZE; i++)
 ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4);
-- 
2.22.0

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

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

Re: [FFmpeg-devel] [PATCH] avcodec: add IMM5 decoder

2019-07-15 Thread Andreas Rheinhardt
Paul B Mahol:
> Signed-off-by: Paul B Mahol 
> ---
>  configure   |   1 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   7 ++
>  libavcodec/imm5.c   | 234 
>  libavformat/riff.c  |   1 +
>  7 files changed, 246 insertions(+)
>  create mode 100644 libavcodec/imm5.c
> 
> diff --git a/configure b/configure
> index 5a4f507246..d03cf43350 100755
> --- a/configure
> +++ b/configure
> @@ -2714,6 +2714,7 @@ huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp 
> llvidencdsp"
>  hymt_decoder_select="huffyuv_decoder"
>  iac_decoder_select="imc_decoder"
>  imc_decoder_select="bswapdsp fft mdct sinewin"
> +imm5_decoder_select="h264_decoder hevc_decoder"
>  indeo3_decoder_select="hpeldsp"
>  indeo4_decoder_select="ividsp"
>  indeo5_decoder_select="ividsp"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 3cd73fbcc6..39f4d9118c 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -393,6 +393,7 @@ OBJS-$(CONFIG_IFF_ILBM_DECODER)+= iff.o
>  OBJS-$(CONFIG_ILBC_DECODER)+= ilbcdec.o
>  OBJS-$(CONFIG_IMC_DECODER) += imc.o
>  OBJS-$(CONFIG_IMM4_DECODER)+= imm4.o
> +OBJS-$(CONFIG_IMM5_DECODER)+= imm5.o
>  OBJS-$(CONFIG_INDEO2_DECODER)  += indeo2.o
>  OBJS-$(CONFIG_INDEO3_DECODER)  += indeo3.o
>  OBJS-$(CONFIG_INDEO4_DECODER)  += indeo4.o ivi.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index d2f9a39ce5..fe7f773925 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -158,6 +158,7 @@ extern AVCodec ff_hymt_decoder;
>  extern AVCodec ff_idcin_decoder;
>  extern AVCodec ff_iff_ilbm_decoder;
>  extern AVCodec ff_imm4_decoder;
> +extern AVCodec ff_imm5_decoder;
>  extern AVCodec ff_indeo2_decoder;
>  extern AVCodec ff_indeo3_decoder;
>  extern AVCodec ff_indeo4_decoder;
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 2528bd89ab..da6f92b443 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -457,6 +457,7 @@ enum AVCodecID {
>  AV_CODEC_ID_AGM,
>  AV_CODEC_ID_LSCR,
>  AV_CODEC_ID_VP4,
> +AV_CODEC_ID_IMM5,
>  
>  /* various PCM "codecs" */
>  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 4d033c20ff..e6373be504 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1726,6 +1726,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
>  .long_name = NULL_IF_CONFIG_SMALL("On2 VP4"),
>  .props = AV_CODEC_PROP_LOSSY,
>  },
> +{
> +.id= AV_CODEC_ID_IMM5,
> +.type  = AVMEDIA_TYPE_VIDEO,
> +.name  = "imm5",
> +.long_name = NULL_IF_CONFIG_SMALL("Infinity IMM5"),
> +.props = AV_CODEC_PROP_LOSSY,
> +},
>  
>  /* various PCM "codecs" */
>  {
> diff --git a/libavcodec/imm5.c b/libavcodec/imm5.c
> new file mode 100644
> index 00..f6b2ce691c
> --- /dev/null
> +++ b/libavcodec/imm5.c
> @@ -0,0 +1,234 @@
> +/*
> + * Copyright (c) 2019 Paul B Mahol
> + *
> + * 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 "avcodec.h"
> +#include "bytestream.h"
> +#include "internal.h"
> +
> +typedef struct IMM5Context {
> +AVCodecContext *h264_avctx;   // wrapper context for H264
> +AVCodecContext *hevc_avctx;   // wrapper context for HEVC
> +
> +int width, height;
> +GetByteContext gbc;

width, height and gbc don't seem to be used at all.

> +
> +uint8_t *imm5_buffer;
> +int imm5_buffer_size;
> +} IMM5Context;
> +
> +static const struct IMM5_unit {
> +uint8_t bits[14];
> +uint8_t len;
> +} IMM5_units[14] = {
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x0B, 0x0F, 
> 0x88 }, 12 },
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x83, 
> 0xE2 }, 12 },
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x81, 
> 0xE8, 0x80 }, 13 },
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x0B, 0x04,

Re: [FFmpeg-devel] [PATCH] avcodec: add IMM5 decoder

2019-07-15 Thread James Almer
On 7/15/2019 6:20 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  configure   |   1 +
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   7 ++
>  libavcodec/imm5.c   | 234 
>  libavformat/riff.c  |   1 +
>  7 files changed, 246 insertions(+)
>  create mode 100644 libavcodec/imm5.c
> 
> diff --git a/configure b/configure
> index 5a4f507246..d03cf43350 100755
> --- a/configure
> +++ b/configure
> @@ -2714,6 +2714,7 @@ huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp 
> llvidencdsp"
>  hymt_decoder_select="huffyuv_decoder"
>  iac_decoder_select="imc_decoder"
>  imc_decoder_select="bswapdsp fft mdct sinewin"
> +imm5_decoder_select="h264_decoder hevc_decoder"
>  indeo3_decoder_select="hpeldsp"
>  indeo4_decoder_select="ividsp"
>  indeo5_decoder_select="ividsp"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 3cd73fbcc6..39f4d9118c 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -393,6 +393,7 @@ OBJS-$(CONFIG_IFF_ILBM_DECODER)+= iff.o
>  OBJS-$(CONFIG_ILBC_DECODER)+= ilbcdec.o
>  OBJS-$(CONFIG_IMC_DECODER) += imc.o
>  OBJS-$(CONFIG_IMM4_DECODER)+= imm4.o
> +OBJS-$(CONFIG_IMM5_DECODER)+= imm5.o
>  OBJS-$(CONFIG_INDEO2_DECODER)  += indeo2.o
>  OBJS-$(CONFIG_INDEO3_DECODER)  += indeo3.o
>  OBJS-$(CONFIG_INDEO4_DECODER)  += indeo4.o ivi.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index d2f9a39ce5..fe7f773925 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -158,6 +158,7 @@ extern AVCodec ff_hymt_decoder;
>  extern AVCodec ff_idcin_decoder;
>  extern AVCodec ff_iff_ilbm_decoder;
>  extern AVCodec ff_imm4_decoder;
> +extern AVCodec ff_imm5_decoder;
>  extern AVCodec ff_indeo2_decoder;
>  extern AVCodec ff_indeo3_decoder;
>  extern AVCodec ff_indeo4_decoder;
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 2528bd89ab..da6f92b443 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -457,6 +457,7 @@ enum AVCodecID {
>  AV_CODEC_ID_AGM,
>  AV_CODEC_ID_LSCR,
>  AV_CODEC_ID_VP4,
> +AV_CODEC_ID_IMM5,
>  
>  /* various PCM "codecs" */
>  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 4d033c20ff..e6373be504 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1726,6 +1726,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
>  .long_name = NULL_IF_CONFIG_SMALL("On2 VP4"),
>  .props = AV_CODEC_PROP_LOSSY,
>  },
> +{
> +.id= AV_CODEC_ID_IMM5,
> +.type  = AVMEDIA_TYPE_VIDEO,
> +.name  = "imm5",
> +.long_name = NULL_IF_CONFIG_SMALL("Infinity IMM5"),
> +.props = AV_CODEC_PROP_LOSSY,
> +},
>  
>  /* various PCM "codecs" */
>  {
> diff --git a/libavcodec/imm5.c b/libavcodec/imm5.c
> new file mode 100644
> index 00..f6b2ce691c
> --- /dev/null
> +++ b/libavcodec/imm5.c
> @@ -0,0 +1,234 @@
> +/*
> + * Copyright (c) 2019 Paul B Mahol
> + *
> + * 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 "avcodec.h"
> +#include "bytestream.h"
> +#include "internal.h"
> +
> +typedef struct IMM5Context {
> +AVCodecContext *h264_avctx;   // wrapper context for H264
> +AVCodecContext *hevc_avctx;   // wrapper context for HEVC
> +
> +int width, height;
> +GetByteContext gbc;
> +
> +uint8_t *imm5_buffer;
> +int imm5_buffer_size;
> +} IMM5Context;
> +
> +static const struct IMM5_unit {
> +uint8_t bits[14];
> +uint8_t len;
> +} IMM5_units[14] = {
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x0B, 0x0F, 
> 0x88 }, 12 },
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x83, 
> 0xE2 }, 12 },
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x81, 
> 0xE8, 0x80 }, 13 },
> +{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x0B, 0x04, 
> 0xA2 }, 12 },
> +{

[FFmpeg-devel] [PATCH] avcodec: add IMM5 decoder

2019-07-15 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 configure   |   1 +
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/avcodec.h|   1 +
 libavcodec/codec_desc.c |   7 ++
 libavcodec/imm5.c   | 234 
 libavformat/riff.c  |   1 +
 7 files changed, 246 insertions(+)
 create mode 100644 libavcodec/imm5.c

diff --git a/configure b/configure
index 5a4f507246..d03cf43350 100755
--- a/configure
+++ b/configure
@@ -2714,6 +2714,7 @@ huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp 
llvidencdsp"
 hymt_decoder_select="huffyuv_decoder"
 iac_decoder_select="imc_decoder"
 imc_decoder_select="bswapdsp fft mdct sinewin"
+imm5_decoder_select="h264_decoder hevc_decoder"
 indeo3_decoder_select="hpeldsp"
 indeo4_decoder_select="ividsp"
 indeo5_decoder_select="ividsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3cd73fbcc6..39f4d9118c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -393,6 +393,7 @@ OBJS-$(CONFIG_IFF_ILBM_DECODER)+= iff.o
 OBJS-$(CONFIG_ILBC_DECODER)+= ilbcdec.o
 OBJS-$(CONFIG_IMC_DECODER) += imc.o
 OBJS-$(CONFIG_IMM4_DECODER)+= imm4.o
+OBJS-$(CONFIG_IMM5_DECODER)+= imm5.o
 OBJS-$(CONFIG_INDEO2_DECODER)  += indeo2.o
 OBJS-$(CONFIG_INDEO3_DECODER)  += indeo3.o
 OBJS-$(CONFIG_INDEO4_DECODER)  += indeo4.o ivi.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d2f9a39ce5..fe7f773925 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -158,6 +158,7 @@ extern AVCodec ff_hymt_decoder;
 extern AVCodec ff_idcin_decoder;
 extern AVCodec ff_iff_ilbm_decoder;
 extern AVCodec ff_imm4_decoder;
+extern AVCodec ff_imm5_decoder;
 extern AVCodec ff_indeo2_decoder;
 extern AVCodec ff_indeo3_decoder;
 extern AVCodec ff_indeo4_decoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2528bd89ab..da6f92b443 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -457,6 +457,7 @@ enum AVCodecID {
 AV_CODEC_ID_AGM,
 AV_CODEC_ID_LSCR,
 AV_CODEC_ID_VP4,
+AV_CODEC_ID_IMM5,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 4d033c20ff..e6373be504 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1726,6 +1726,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("On2 VP4"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_IMM5,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "imm5",
+.long_name = NULL_IF_CONFIG_SMALL("Infinity IMM5"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/imm5.c b/libavcodec/imm5.c
new file mode 100644
index 00..f6b2ce691c
--- /dev/null
+++ b/libavcodec/imm5.c
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 2019 Paul B Mahol
+ *
+ * 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 "avcodec.h"
+#include "bytestream.h"
+#include "internal.h"
+
+typedef struct IMM5Context {
+AVCodecContext *h264_avctx;   // wrapper context for H264
+AVCodecContext *hevc_avctx;   // wrapper context for HEVC
+
+int width, height;
+GetByteContext gbc;
+
+uint8_t *imm5_buffer;
+int imm5_buffer_size;
+} IMM5Context;
+
+static const struct IMM5_unit {
+uint8_t bits[14];
+uint8_t len;
+} IMM5_units[14] = {
+{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x0B, 0x0F, 0x88 
}, 12 },
+{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x83, 0xE2 
}, 12 },
+{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x81, 
0xE8, 0x80 }, 13 },
+{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x0B, 0x04, 0xA2 
}, 12 },
+{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x81, 
0x28, 0x80 }, 13 },
+{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x80, 0x1E, 0xF4, 0x05, 0x80, 
0x92, 0x20 }, 13 },
+{ { 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1E, 0x9A, 0x74, 0x0B, 
0x0F, 0xC8 }, 13 },
+{ { 0x00, 0x00, 0x00, 0x01

Re: [FFmpeg-devel] [PATCH] lavf/vf_freezedetect: improve for the freeze frame detection

2019-07-15 Thread Marton Balint



On Mon, 15 Jul 2019, Limin Wang wrote:

[...]


>>>if (s->width[plane]) {
>>>uint64_t plane_sad;
>>>s->sad(frame->data[plane], frame->linesize[plane],
>>>@@ -140,8 +146,12 @@ static int is_frozen(FreezeDetectContext *s, AVFrame 
*reference, AVFrame *frame)
>>>}
>>>}
>>>emms_c();
>>>-mafd = (double)sad / count / (1ULL << s->bitdepth);
>>>-return (mafd <= s->noise);
>>>+mafd = (double)sad /(count >> (s->bitdepth > 8));
>>
>>Why? MAFD should be the mean difference normalized to [0..1].
>if the bitdeth is 16, it'll divide by 1UL << 16, it'll cause the mafd is
>very small. So I choose the scenecut way in the below.

The metric supposed to be indepentent of the bit depth. If you get
different mafd for the same source expressed in 8bit, 10bit or 16bit
pixel format (provided that you use the same subsampling), then you
are doing something wrong.

And you can't reinvent MAFD according to your needs. It is the mean
absolute difference of the whole image normalized to 0..1 in this
case. If you are not calculating that, then it is not MAFD.


Sorry, now the scenecut detection support rgb only, so I'm changing it to support 
more format without autoscale, it'll necessary to solved how to calculated mafd for
10bits or 12bits. Below is my understanding for the mafd calculation, correct me if 
I'm misunderstanding. for example, if the bitdepth is 8 bits, it means the pixel 
block is 8x8 pixel, so maybe we should divide 8x8 instead of 256?


mafd = sad / count / (bitdepth * bitdepth)


bitdepth is the bitdepth of one pixel. For 8 bit, a color component can be
0..255. For 16 bit, a color component can be 0..65535.

8x8 and 16x16 pixel blocks are totally different and unrelated things from 
bit depth. Yes, SAD is usually calculated for 8x8 or 16x16 blocks for 
motion estimation or compression, not here. Here, SAD is the sum of 
absolute differences throughout the entire image, (width x height). Count 
= width * height, so SAD/count is the average of differences. In order to 
get it to [0..1] you have to divide by 2^bitdepth.


Regards,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v6] Fix integer parameters size check in SDP fmtp line

2019-07-15 Thread Reimar Döffinger
This seems reasonable to me, but I have not been involved in any rtp code.
The commit message is maybe a bit on the verbose side, but I don't have any 
strong opinion.

On 12.07.2019, at 08:40, Olivier Maignial  wrote:

> === PROBLEM ===
> 
> I was trying to record h264 + aac streams from an RTSP server to mp4 file. 
> using this command line:
>ffmpeg -v verbose -y -i "rtsp:///my_resources" -codec copy -bsf:a 
> aac_adtstoasc test.mp4
> 
> FFmpeg then fail to record audio and output this logs:
>[rtsp @ 0xcda1f0] The profile-level-id field size is invalid (40)
>[rtsp @ 0xcda1f0] Error parsing AU headers
>...
>[rtsp @ 0xcda1f0] Could not find codec parameters for stream 1 (Audio: 
> aac, 48000 Hz, 1 channels): unspecified sample format
> 
> In SDP provided by my RTSP server I had this fmtp line:
>a=fmtp:98 streamType=5; profile-level-id=40; mode=AAC-hbr; config=1188; 
> sizeLength=13; indexLength=3; indexDeltaLength=3;
> 
> In FFmpeg code, I found a check introduced by commit 
> 24130234cd9dd733116d17b724ea4c8e12ce097a. It disallows values greater than 32 
> for fmtp line parameters.
> However, In RFC-6416 (RTP Payload Format for MPEG-4 Audio/Visual Streams) 
> give examples of "profile-level-id" values for AAC, up to 55.
> Furthermore, RFC-4566 (SDP: Session Description Protocol) do not give any 
> limit of size on interger parameters given in fmtp line.
> 
> === FIX ===
> 
> Instead of prohibit values over 32, I propose to check the possible integer 
> overflow.
> The use of strtoll allow to check the string validity and the possible 
> overflow.
> Value is then checked against INT32_MIN and INT32_MAX. Using INT32_MIN/MAX 
> ensure to have the same behavior on 32 or 64 bits platforms.
> 
> This patch fix my problem and I now can record my RTSP AAC stream to mp4.
> It has passed the full fate tests suite sucessfully.
> 
> Signed-off-by: Olivier Maignial 
> ---
> 
> Changes V6 --> V7:
>- Use long long int and strtoll. LLONG_MAX is always greather than 
> INT32_MIN while LONG_MAX can be equal to INT32_MAX. It allows to accept full 
> INT32 range.
>- Avoid to use errno
> 
> libavformat/rtpdec_mpeg4.c | 13 -
> 1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
> index 4f70599..f1cbedf 100644
> --- a/libavformat/rtpdec_mpeg4.c
> +++ b/libavformat/rtpdec_mpeg4.c
> @@ -289,15 +289,18 @@ static int parse_fmtp(AVFormatContext *s,
> for (i = 0; attr_names[i].str; ++i) {
> if (!av_strcasecmp(attr, attr_names[i].str)) {
> if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
> -int val = atoi(value);
> -if (val > 32) {
> +char *end_ptr = NULL;
> +long long int val = strtoll(value, &end_ptr, 10);
> +if (end_ptr == value || end_ptr[0] != '\0' ||
> +val < INT32_MIN || val > INT32_MAX) {
> av_log(s, AV_LOG_ERROR,
> -   "The %s field size is invalid (%d)\n",
> -   attr, val);
> +   "The %s field value is not a valid number, or 
> overflows int32: %s\n",
> +   attr, value);
> return AVERROR_INVALIDDATA;
> }
> +
> *(int *)((char *)data+
> -attr_names[i].offset) = val;
> +attr_names[i].offset) = (int) val;
> } else if (attr_names[i].type == ATTR_NAME_TYPE_STR) {
> char *val = av_strdup(value);
> if (!val)
> -- 
> 2.7.4
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH] libavformat/subfile: Fix SEEK_CUR and SEEK_END seeking

2019-07-15 Thread Andreas Rheinhardt
Up until now, when performing a SEEK_END seek, the subfile protocol
ignored the desired position (relative to EOF) and used the current
absolute offset in the input file instead.

And when performing a SEEK_CUR seek, the current position has been
ignored.

Signed-off-by: Andreas Rheinhardt 
---
Sorry for the noise of another email, but I just found out that SEEK_CUR
is buggy as well. This probably hasn't been detected earlier because
avio_seek translates SEEK_CUR to SEEK_SET internally.

 libavformat/subfile.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/subfile.c b/libavformat/subfile.c
index 2f162e0a34..5d8659c8c4 100644
--- a/libavformat/subfile.c
+++ b/libavformat/subfile.c
@@ -116,7 +116,7 @@ static int subfile_read(URLContext *h, unsigned char *buf, 
int size)
 static int64_t subfile_seek(URLContext *h, int64_t pos, int whence)
 {
 SubfileContext *c = h->priv_data;
-int64_t new_pos = -1, end;
+int64_t new_pos, end;
 int ret;
 
 if (whence == AVSEEK_SIZE || whence == SEEK_END) {
@@ -132,10 +132,10 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, 
int whence)
 new_pos = c->start + pos;
 break;
 case SEEK_CUR:
-new_pos += pos;
+new_pos = c->pos + pos;
 break;
 case SEEK_END:
-new_pos = end + c->pos;
+new_pos = end + pos;
 break;
 }
 if (new_pos < c->start)
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH] libavformat/subfile: Fix SEEK_END seeking

2019-07-15 Thread Andreas Rheinhardt
Up until now, when performing a SEEK_END seek, the subfile protocol
ignored the desired position (relative to EOF) and used the current
absolute offset in the input file instead.

Signed-off-by: Andreas Rheinhardt 
---
A situation affected by this is a concatenation of concat and subfile:
For some reason, SEEK_SIZE is not implemented for the concat protocol,
so that SEEK_END is used as a fallback. Depending on parameter
combinations, this can mean that the duration of e.g. transport streams
can't be estimated.
Sorry for not spotting this in 4877b586; the bug here was already
present in the initial commit of this protocol.

 libavformat/subfile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/subfile.c b/libavformat/subfile.c
index 2f162e0a34..8210dfb6b3 100644
--- a/libavformat/subfile.c
+++ b/libavformat/subfile.c
@@ -135,7 +135,7 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, int 
whence)
 new_pos += pos;
 break;
 case SEEK_END:
-new_pos = end + c->pos;
+new_pos = end + pos;
 break;
 }
 if (new_pos < c->start)
-- 
2.21.0

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

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

Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for autoscale/autorotate

2019-07-15 Thread Fu, Linjie
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Carl Eugen Hoyos
> Sent: Monday, July 15, 2019 23:38
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for
> autoscale/autorotate
> 
> Am Mo., 15. Juli 2019 um 12:39 Uhr schrieb Linjie Fu :
> >
> > Add docs for autoscale/noautoscale.
> >
> > Update information for autorotate according to ffplay.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> >  doc/ffmpeg.texi | 11 +++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> > index cd35eb49c8..040a2b53cf 100644
> > --- a/doc/ffmpeg.texi
> > +++ b/doc/ffmpeg.texi
> > @@ -735,9 +735,20 @@ Technical note -- attachments are implemented as
> codec extradata, so this
> >  option can actually be used to extract extradata from any stream, not just
> >  attachments.
> >
> > +@item -autorotate
> > +Automatically rotate the video according to file metadata. Enabled by
> > +default, use @option{-noautorotate} to disable it.
> > +
> > +@item -autoscale
> > +Automatically scale the video according to the resolution of first frame.
> > +Enabled by default, use @option{-noautoscale} to disable it.
> > +
> >  @item -noautorotate
> >  Disable automatically rotating video based on file metadata.
> >
> > +@item -noautoscale
> > +Disable automatically scale video based on first frame resolution.
> 
> Istn't there a "-no" option for most (all?) ffmpeg options but we only
> document one of them?

Options with OPT_BOOL flag (/* boolean -nofoo options */) can be used in this 
way.

> I believe "autorotate" and "autoscale" are sufficient if there counterparts
> are also described.
Agree, if there is docs for "-no"  option well explained. 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for autoscale/autorotate

2019-07-15 Thread Carl Eugen Hoyos
Am Mo., 15. Juli 2019 um 12:39 Uhr schrieb Linjie Fu :
>
> Add docs for autoscale/noautoscale.
>
> Update information for autorotate according to ffplay.
>
> Signed-off-by: Linjie Fu 
> ---
>  doc/ffmpeg.texi | 11 +++
>  1 file changed, 11 insertions(+)
>
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index cd35eb49c8..040a2b53cf 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -735,9 +735,20 @@ Technical note -- attachments are implemented as codec 
> extradata, so this
>  option can actually be used to extract extradata from any stream, not just
>  attachments.
>
> +@item -autorotate
> +Automatically rotate the video according to file metadata. Enabled by
> +default, use @option{-noautorotate} to disable it.
> +
> +@item -autoscale
> +Automatically scale the video according to the resolution of first frame.
> +Enabled by default, use @option{-noautoscale} to disable it.
> +
>  @item -noautorotate
>  Disable automatically rotating video based on file metadata.
>
> +@item -noautoscale
> +Disable automatically scale video based on first frame resolution.

Istn't there a "-no" option for most (all?) ffmpeg options but we only
document one of them?
I believe "autorotate" and "autoscale" are sufficient if there counterparts
are also described.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCHv4] avcodec: Add librav1e encoder

2019-07-15 Thread Derek Buitenhuis
On 15/07/2019 15:53, James Almer wrote:
>>> AV_BASE64_DECODE_SIZE(strlen(avctx->stats_in));
>>
>> I copied this directly from libtheoraenc.c which has had this for more than 
>> 10
>> years... is it wrong? Should it be changed too?
> 
> It's not wrong, that helper macro was added three years ago and it
> expands to the same code, except promoting the intermediary result to
> int64_t to prevent overflow.
> And i think it should ideally be changed in libtheora/libvpx as well, yes.

OK.

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

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

Re: [FFmpeg-devel] [PATCHv4] avcodec: Add librav1e encoder

2019-07-15 Thread James Almer
On 7/15/2019 11:23 AM, Derek Buitenhuis wrote:
> On 13/07/2019 19:37, James Almer wrote:
>> Just use av_reallocp(). Each call will make the buffer bigger, so you're
>> not really making use the no-op benefits from av_fast_realloc(), which
>> only trigger if newsize <= size.
> 
> I'll wait for your reply to Nicholas and do whichevr people agree on.

Leave it as av_fast_realloc(). My suggestion was only a NIT.

> 
>>> +ctx->pass_size = (strlen(avctx->stats_in) * 3) / 4;
>>
>> AV_BASE64_DECODE_SIZE(strlen(avctx->stats_in));
> 
> I copied this directly from libtheoraenc.c which has had this for more than 10
> years... is it wrong? Should it be changed too?

It's not wrong, that helper macro was added three years ago and it
expands to the same code, except promoting the intermediary result to
int64_t to prevent overflow.
And i think it should ideally be changed in libtheora/libvpx as well, yes.

> 
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

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

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

[FFmpeg-devel] [PATCH] avcodec: list the allocation requirements for intra_matrix and inter_matrix fields

2019-07-15 Thread James Almer
Signed-off-by: James Almer 
---
See 
https://git.videolan.org/?p=vlc.git;a=commitdiff;h=d86c4c87aa78130a4fd00294e25df865d0e2b327

 libavcodec/avcodec.h | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2528bd89ab..646b8f05fc 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2057,15 +2057,19 @@ typedef struct AVCodecContext {
 
 /**
  * custom intra quantization matrix
- * - encoding: Set by user, can be NULL.
- * - decoding: Set by libavcodec.
+ * Must be allocated with the av_malloc() family of functions, and will be 
freed in
+ * avcodec_free_context().
+ * - encoding: Set/allocated by user. Freed by libavcodec. Can be NULL.
+ * - decoding: Set/allocated/freed by libavcodec.
  */
 uint16_t *intra_matrix;
 
 /**
  * custom inter quantization matrix
- * - encoding: Set by user, can be NULL.
- * - decoding: Set by libavcodec.
+ * Must be allocated with the av_malloc() family of functions, and will be 
freed in
+ * avcodec_free_context().
+ * - encoding: Set/allocated by user. Freed by libavcodec. Can be NULL.
+ * - decoding: Set/allocated/freed by libavcodec.
  */
 uint16_t *inter_matrix;
 
-- 
2.22.0

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

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

Re: [FFmpeg-devel] [PATCHv4] avcodec: Add librav1e encoder

2019-07-15 Thread Derek Buitenhuis
On 13/07/2019 19:37, James Almer wrote:
> Just use av_reallocp(). Each call will make the buffer bigger, so you're
> not really making use the no-op benefits from av_fast_realloc(), which
> only trigger if newsize <= size.

I'll wait for your reply to Nicholas and do whichevr people agree on.

>> +ctx->pass_size = (strlen(avctx->stats_in) * 3) / 4;
> 
> AV_BASE64_DECODE_SIZE(strlen(avctx->stats_in));

I copied this directly from libtheoraenc.c which has had this for more than 10
years... is it wrong? Should it be changed too?

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

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

Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for autoscale/autorotate

2019-07-15 Thread Nicolas George
Linjie Fu (12019-07-15):
> Add docs for autoscale/noautoscale.

This belongs in the path that adds them.

> 
> Update information for autorotate according to ffplay.
> 
> Signed-off-by: Linjie Fu 
> ---
>  doc/ffmpeg.texi | 11 +++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index cd35eb49c8..040a2b53cf 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -735,9 +735,20 @@ Technical note -- attachments are implemented as codec 
> extradata, so this
>  option can actually be used to extract extradata from any stream, not just
>  attachments.
>  
> +@item -autorotate
> +Automatically rotate the video according to file metadata. Enabled by
> +default, use @option{-noautorotate} to disable it.
> +
> +@item -autoscale
> +Automatically scale the video according to the resolution of first frame.
> +Enabled by default, use @option{-noautoscale} to disable it.
> +
>  @item -noautorotate
>  Disable automatically rotating video based on file metadata.
>  

> +@item -noautoscale
> +Disable automatically scale video based on first frame resolution.

You neglected to explain the drawbacks.

> +
>  @end table
>  
>  @section Video Options

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v2] fate: add hls fmp4 segment type test case

2019-07-15 Thread Steven Liu


> 在 2019年7月15日,03:27,Michael Niedermayer  写道:
> 
> On Sun, Jul 14, 2019 at 06:41:28AM +0800, Steven Liu wrote:
>> Signed-off-by: Steven Liu 
>> ---
>> tests/fate/hlsenc.mak   |  12 +++
>> tests/ref/fate/hls-fmp4 | 198 
>> 
>> 2 files changed, 210 insertions(+)
>> create mode 100644 tests/ref/fate/hls-fmp4
>> 
>> diff --git a/tests/fate/hlsenc.mak b/tests/fate/hlsenc.mak
>> index 2a125cda3c..98d67f96df 100644
>> --- a/tests/fate/hlsenc.mak
>> +++ b/tests/fate/hlsenc.mak
>> @@ -74,3 +74,15 @@ FATE_AFILTER-$(call ALLYES, HLS_DEMUXER MPEGTS_MUXER 
>> MPEGTS_DEMUXER AEVALSRC_FIL
>> fate-hls-list-size: tests/data/hls_list_size.m3u8
>> fate-hls-list-size: CMD = framecrc -flags +bitexact -i 
>> $(TARGET_PATH)/tests/data/hls_list_size.m3u8 -vf setpts=N*23
>> 
>> +tests/data/hls_segment_type_fmp4.m3u8: TAG = GEN
>> +tests/data/hls_segment_type_fmp4.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | 
>> tests/data
>> +$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
>> +-f lavfi -re -i "aevalsrc=cos(2*PI*t)*sin(2*PI*(440+4*t)*t):d=5" -map 0 
>> -codec:a mp2fixed \
>> +-hls_segment_type mpegts -hls_fmp4_init_filename now.mp4 -hls_list_size 
>> 0 \
>> +-hls_time 1 -hls_segment_filename 
>> "$(TARGET_PATH)/tests/data/hls_fmp4_%d.m4s" \
>> +$(TARGET_PATH)/tests/data/hls_fmp4.m3u8 2>/dev/null
>> +
>> +FATE_AFILTER-$(call ALLYES, HLS_DEMUXER MPEGTS_MUXER MPEGTS_DEMUXER 
>> AEVALSRC_FILTER LAVFI_INDEV MP2FIXED_ENCODER) += fate-hls-fmp4
>> +fate-hls-fmp4: tests/data/hls_segment_type_fmp4.m3u8
> 
>> +fate-hls-fmp4: CMD = framecrc -flags +bitexact -i 
>> $(TARGET_PATH)/tests/data/hls_fmp4.m3u8 -vf setpts=N*23
> 
> tested on linux32/64 x86, mingw32/64 , linux arm and mips qemu
Applied

Thanks
Steven





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

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

Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for autoscale/autorotate

2019-07-15 Thread Fu, Linjie
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Moritz Barsnick
> Sent: Monday, July 15, 2019 20:02
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for
> autoscale/autorotate
> 
> On Mon, Jul 15, 2019 at 18:39:14 +0800, Linjie Fu wrote:
> 
> Nit:
> 
> > +@item -noautoscale
> > +Disable automatically scale video based on first frame resolution.
>  ^ scaling
> 

Yes, scaling :)
Thanks.

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

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

Re: [FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for autoscale/autorotate

2019-07-15 Thread Moritz Barsnick
On Mon, Jul 15, 2019 at 18:39:14 +0800, Linjie Fu wrote:

Nit:

> +@item -noautoscale
> +Disable automatically scale video based on first frame resolution.
 ^ scaling

Cheers,
Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 2/2] doc/vaapi_encode: add documentations for max_frame_size

2019-07-15 Thread Linjie Fu
Add docs for max_frame_size option.

Signed-off-by: Linjie Fu 
---
 doc/encoders.texi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index eefd124751..ea43900e91 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2899,6 +2899,12 @@ will refer only to P- or I-frames.  When set to greater 
values multiple layers
 of B-frames will be present, frames in each layer only referring to frames in
 higher layers.
 
+@item max_frame_size
+Set the allowed max size in bytes for each frame. If the frame size exceeds
+the limitation, encoder will adjust the QP value by adding delta_qp for each 
+pass to control the frame size. To simplify the usage, delta_qp is set to
+default.
+
 @item rc_mode
 Set the rate control mode to use.  A given driver may only support a subset of
 modes.
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH, v3 1/2] lavc/vaapi_encode: add support for maxframesize

2019-07-15 Thread Linjie Fu
Add support for max frame size:
- max_frame_size (bytes) to indicate the max allowed size for frame.

If the frame size exceeds the limitation, encoder will to control the frame
size by adjusting QP value.
- MFS_NUM_PASSES to indicate number of passes for QP adjust.
- MFS_DELTA_QP to indicate adjust qp value per pass.

To simplify the usage, default QP adjust is set to delta_qp[4] = {1, 1, 1, 1}.
Use new_qp for encoder if frame size exceeds the limitation:
new_qp = base_qp + delta_qp[0] + delta_qp[1] + ...

ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -f rawvideo \
-v verbose -s:v 352x288 -i ./input.yuv -vf format=nv12,hwupload \
-c:v h264_vaapi -profile:v main -g 30 -bf 3 -max_frame_size 4 \
-vframes 100 -y ./max_frame_size.h264

Max frame size was enabled since VA-API version (1, 3, 0), but query is 
available
since (1, 5, 0). It will be passed as a parameter in picParam and should be set
for each frame.

Signed-off-by: Linjie Fu 
---
Since the Attribute query for maxframesize is merged in media driver,
it's more robust now for vaapi to make use of this feature.
https://github.com/intel/media-driver/pull/656

 libavcodec/vaapi_encode.c | 68 ++-
 libavcodec/vaapi_encode.h | 19 +--
 2 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index dd2a24de04..fdc1cec178 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -258,7 +258,16 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 if (err < 0)
 goto fail;
 }
-
+#if VA_CHECK_VERSION(1, 5, 0)
+if (ctx->max_frame_size) {
+err = vaapi_encode_make_misc_param_buffer(avctx, pic,
+
VAEncMiscParameterTypeMultiPassFrameSize,
+&ctx->mfs_params,
+sizeof(ctx->mfs_params));
+if (err < 0)
+goto fail;
+}
+#endif
 if (pic->type == PICTURE_TYPE_IDR) {
 if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE &&
 ctx->codec->write_sequence_header) {
@@ -1671,6 +1680,54 @@ rc_mode_found:
 return 0;
 }
 
+static av_cold int vaapi_encode_init_max_frame_size(AVCodecContext *avctx)
+{
+#if VA_CHECK_VERSION(1, 5, 0)
+VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAConfigAttrib  attr = { VAConfigAttribMaxFrameSize };
+VAStatus vas;
+int i;
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile,
+ctx->va_entrypoint,
+&attr, 1);
+if (vas != VA_STATUS_SUCCESS) {
+ctx->max_frame_size = 0;
+av_log(avctx, AV_LOG_ERROR, "Failed to query max frame size "
+   "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
+
+if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+ctx->max_frame_size = 0;
+av_log(avctx, AV_LOG_WARNING, "Max frame size attribute "
+"is not supported.\n");
+} else {
+ctx->delta_qp = av_mallocz_array(MFS_NUM_PASSES, sizeof(uint8_t));
+if (!ctx->delta_qp) {
+return AVERROR(ENOMEM);
+}
+for (i = 0; i delta_qp[i] = MFS_DELTA_QP;
+
+ctx->mfs_params = (VAEncMiscParameterBufferMultiPassFrameSize){
+.max_frame_size = ctx->max_frame_size,
+.num_passes = MFS_NUM_PASSES,
+.delta_qp   = ctx->delta_qp,
+};
+
+av_log(avctx, AV_LOG_VERBOSE, "Max Frame Size: %d bytes.\n ",
+ctx->max_frame_size);
+}
+#else
+av_log(avctx, AV_LOG_WARNING, "Max Frame Size is "
+"not supported with this VA version.\n");
+#endif
+
+return 0;
+}
+
 static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -2138,6 +2195,12 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 goto fail;
 }
 
+if (ctx->max_frame_size) {
+err = vaapi_encode_init_max_frame_size(avctx);
+if (err < 0)
+goto fail;
+}
+
 vas = vaCreateConfig(ctx->hwctx->display,
  ctx->va_profile, ctx->va_entrypoint,
  ctx->config_attributes, ctx->nb_config_attributes,
@@ -2262,6 +2325,9 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
 ctx->va_config = VA_INVALID_ID;
 }
 
+if (ctx->delta_qp)
+av_freep(&ctx->delta_qp);
+
 av_freep(&ctx->codec_sequence_params);
 av_freep(&ctx->codec_picture_params);
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index eeec06036b..05b35608c2 100644
--- a/libavcodec/vaapi_encode

[FFmpeg-devel] [PATCH 2/2] doc/ffmpeg.texi: update docs for autoscale/autorotate

2019-07-15 Thread Linjie Fu
Add docs for autoscale/noautoscale.

Update information for autorotate according to ffplay.

Signed-off-by: Linjie Fu 
---
 doc/ffmpeg.texi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index cd35eb49c8..040a2b53cf 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -735,9 +735,20 @@ Technical note -- attachments are implemented as codec 
extradata, so this
 option can actually be used to extract extradata from any stream, not just
 attachments.
 
+@item -autorotate
+Automatically rotate the video according to file metadata. Enabled by
+default, use @option{-noautorotate} to disable it.
+
+@item -autoscale
+Automatically scale the video according to the resolution of first frame.
+Enabled by default, use @option{-noautoscale} to disable it.
+
 @item -noautorotate
 Disable automatically rotating video based on file metadata.
 
+@item -noautoscale
+Disable automatically scale video based on first frame resolution.
+
 @end table
 
 @section Video Options
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 1/2] fftools/ffmpeg_filter: add -autoscale to disable/enable the default scale

2019-07-15 Thread Linjie Fu
Currently, ffmpeg inserts scale filter by default in the filter graph
to force the whole decoded stream to scale into the same size with the
first frame. It's not quite make sense in resolution changing cases if
user wants the rawvideo without any scale.

Using autoscale/noautoscale to indicate whether auto inserting the scale
filter in the filter graph:
-noautoscale or -autoscale 0:
disable the default auto scale filter inserting.

Signed-off-by: Linjie Fu 
---
 fftools/ffmpeg.c| 1 +
 fftools/ffmpeg.h| 4 
 fftools/ffmpeg_filter.c | 2 +-
 fftools/ffmpeg_opt.c| 5 +
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 01f04103cf..5d52430b1e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2133,6 +2133,7 @@ static int ifilter_send_frame(InputFilter *ifilter, 
AVFrame *frame)
 
 /* determine if the parameters for this input changed */
 need_reinit = ifilter->format != frame->format;
+fg->autoscale = ifilter->ist->autoscale;
 
 switch (ifilter->ist->st->codecpar->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7b6f802082..1602406581 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -133,6 +133,8 @@ typedef struct OptionsContext {
 intnb_hwaccel_output_formats;
 SpecifierOpt *autorotate;
 intnb_autorotate;
+SpecifierOpt *autoscale;
+intnb_autoscale;
 
 /* output options */
 StreamMap *stream_maps;
@@ -285,6 +287,7 @@ typedef struct FilterGraph {
 
 AVFilterGraph *graph;
 int reconfiguration;
+int autoscale;
 
 InputFilter   **inputs;
 int  nb_inputs;
@@ -335,6 +338,7 @@ typedef struct InputStream {
 int guess_layout_max;
 
 int autorotate;
+int autoscale;
 
 int fix_sub_duration;
 struct { /* previous decoded subtitle and related variables */
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 72838de1e2..2a2eb080eb 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -469,7 +469,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
OutputFilter *ofilter,
 if (ret < 0)
 return ret;
 
-if (ofilter->width || ofilter->height) {
+if ((ofilter->width || ofilter->height) && fg->autoscale) {
 char args[255];
 AVFilterContext *filter;
 AVDictionaryEntry *e = NULL;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index f5ca18aa64..47f90c22aa 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -742,7 +742,9 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
 
 ist->autorotate = 1;
+ist->autoscale  = 1;
 MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
+MATCH_PER_STREAM_OPT(autoscale, i, ist->autoscale, ic, st);
 
 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
 if (codec_tag) {
@@ -3640,6 +3642,9 @@ const OptionDef options[] = {
 { "autorotate",   HAS_ARG | OPT_BOOL | OPT_SPEC |
   OPT_EXPERT | OPT_INPUT,  
  { .off = OFFSET(autorotate) },
 "automatically insert correct rotate filters" },
+{ "autoscale",HAS_ARG | OPT_BOOL | OPT_SPEC |
+  OPT_EXPERT | OPT_INPUT,  
  { .off = OFFSET(autoscale) },
+"automatically insert correct scale filters" },
 
 /* audio options */
 { "aframes",OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,   
{ .func_arg = opt_audio_frames },
-- 
2.17.1

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

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

Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: use -reinit_filter to disable/enable auto scale

2019-07-15 Thread Fu, Linjie
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Eoff, Ullysses A
> Sent: Saturday, July 13, 2019 12:26
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: use -reinit_filter
> to disable/enable auto scale
> 
> > > > Add an option to disable/enable "auto insert" is Ok for me, but I
> > > > think if you reuse the -reinit_filter option, you need to update doc
> > > > part at the same time.
> > >
> > > I prefer to add a separate option, too.
> > > Depending on the comments, I'll either update doc for reinit_filter, or
> add a
> > > new option and related doc.
> >
> > Since there is an existed option named "autorotate", add an new option
> "autoscale" looks can keep tune.
> 
> I like the idea of having a new option, too.  The option name "reinit_filter"
> doesn't imply anything
> about "scaling"... it's just a side-effect.  That is, reinit_filter could 
> cause other
> filters to behave
> differently too, right?  So an explicit option to enable/disable auto scale
> would imply a more
> obvious expectation to the user.
> 

Thanks for the comments.
Will refine new patches with a separate option and doc.

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

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