Re: [FFmpeg-devel] [PATCH 1/3] libavutil: AVEncodeInfo data structures

2019-08-23 Thread Juan De León
On Fri, Aug 23, 2019 at 12:28 PM Nicolas George  wrote:

> Juan De León (12019-08-23):
> > I changed it to an inline function, returns SIZE_MAX if it fails to make
> > av_malloc() fail and return NULL.
>
> You neglected to check for SIZE_MAX afterwards. I suspect there are
> architectures where such a malloc could succeed.
>
I doubt it since av_malloc() checks for size > INT_MAX - 32.
Maybe in a 16 bit system.

But in this case, a macro would probably be the simplest.
>
I'm sending a new patch with a macro.
___
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] libavutil: AVEncodeInfo data structures

2019-08-23 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  72 ++
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 192 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..1048173e7f
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,72 @@
+/*
+ * 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/encode_info.h"
+#include "libavutil/mem.h"
+
+/**
+ * Get the size to allocate of AVEncodeInfoFrame and the array of 
AVEncodeInfoBlock.
+ * AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock.
+ */
+#define AV_ENCODE_INFO_GET_SIZE(SIZE, N) \
+if (N > (SIZE_MAX - sizeof(AVEncodeInfoFrame)) / sizeof(AVEncodeInfoBlock) 
+ 1) \
+return NULL; \
+SIZE = sizeof(AVEncodeInfoFrame) - sizeof(AVEncodeInfoBlock) \
++ FFMAX(1, N) * sizeof(AVEncodeInfoBlock)
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, unsigned nb_blocks)
+{
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(unsigned nb_blocks)
+{
+size_t size;
+AV_ENCODE_INFO_GET_SIZE(size, nb_blocks);
+AVEncodeInfoFrame *ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned 
nb_blocks)
+{
+size_t size;
+AV_ENCODE_INFO_GET_SIZE(size, nb_blocks);
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..8afe0c9c9e
--- /dev/null
+++ b/libavutil/encode_inf

Re: [FFmpeg-devel] [PATCH 1/3] libavutil: AVEncodeInfo data structures

2019-08-23 Thread Juan De León
On Fri, Aug 23, 2019 at 8:07 AM Nicolas George  wrote:

> > +if (nb_blocks - 1 > (SIZE_MAX - sizeof(AVEncodeInfoFrame)) /
> sizeof(AVEncodeInfoBlock))
> > +return NULL;
>
> nb_blocks - 1 overflows for 0. Move the -1 right of the = as +1.
>
> > +//AVEncodeInfoFrame already allocates size for one element of
> AVEncodeInfoBlock
>
> > +size_t size = sizeof(AVEncodeInfoFrame) - sizeof(AVEncodeInfoBlock)
> +
> > +  FFMAX(1, nb_blocks) * sizeof(AVEncodeInfoBlock);
>
> This code would be better shared in an inline function or macro instead
> of duplicated. With a macro, you can include the check.
>

I changed it to an inline function, returns SIZE_MAX if it fails to make
av_malloc() fail and return NULL.
Thanks for the feedback.
___
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] libavutil: AVEncodeInfo data structures

2019-08-23 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  74 +++
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 194 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..0614745948
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,74 @@
+/*
+ * 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/encode_info.h"
+#include "libavutil/mem.h"
+
+
+/**
+ * Get the size to allocate of  AVEncodeInfoFrame and the array of 
AVEncodeInfoBlock.
+ * Return SIZE_MAX insted of 0 to make av_malloc() return NULL.
+ */
+static inline get_encode_info_size (unsigned nb_blocks)
+{
+if (nb_blocks > (SIZE_MAX - sizeof(AVEncodeInfoFrame)) / 
sizeof(AVEncodeInfoBlock) + 1)
+return SIZE_MAX;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+return sizeof(AVEncodeInfoFrame) - sizeof(AVEncodeInfoBlock)
++ FFMAX(1, nb_blocks) * sizeof(AVEncodeInfoBlock);
+}
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, unsigned nb_blocks)
+{
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(unsigned nb_blocks)
+{
+size_t size = get_encode_info_size(nb_blocks);
+AVEncodeInfoFrame *ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned 
nb_blocks)
+{
+size_t size = get_encode_info_size(nb_blocks);
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 10

[FFmpeg-devel] [PATCH 1/3] libavutil: AVEncodeInfo data structures

2019-08-21 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  71 ++
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 191 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..91e43fce63
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,71 @@
+/*
+ * 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/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, unsigned nb_blocks) {
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(unsigned nb_blocks)
+{
+// Check for possible size_t overflow
+if (nb_blocks - 1 > (SIZE_MAX - sizeof(AVEncodeInfoFrame)) / 
sizeof(AVEncodeInfoBlock))
+return NULL;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) - sizeof(AVEncodeInfoBlock) +
+  FFMAX(1, nb_blocks) * sizeof(AVEncodeInfoBlock);
+
+AVEncodeInfoFrame *ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned 
nb_blocks)
+{
+// Check for size_t overflow
+if (nb_blocks - 1 > (SIZE_MAX - sizeof(AVEncodeInfoFrame)) / 
sizeof(AVEncodeInfoBlock))
+return NULL;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) - sizeof(AVEncodeInfoBlock) +
+  FFMAX(1, nb_blocks) * sizeof(AVEncodeInfoBlock);
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncod

Re: [FFmpeg-devel] [PATCH 0/3] AVEncodeInfo and extractqp changes

2019-08-20 Thread Juan De León
On Mon, Aug 19, 2019 at 4:37 PM Juan De León  wrote:

> Proposed changes to use AVEncodeInfoFrame and AVencodeInfoBlock
> data types as AVFrameSideData, including the changes tothe h264
> decoder as well as a filter to output the data extracted.
>
> Filter can be called using:
> ffmpeg -debug extractqp -i  -lavfi extractqp=extractqp.log -f
> null -
>
> More options in filters.texi, libx264 has to be enabled.
>
> doc/filters.texi   |  40 ++
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vf_extractqp.c | 243
> +
>  4 files changed, 285 insertions(+)
>
> libavcodec/avcodec.h   |  1 +
>  libavcodec/h264dec.c   | 40 
>  libavcodec/options_table.h |  1 +
>  3 files changed, 42 insertions(+)
>
> libavutil/Makefile  |   2 ++
>  libavutil/encode_info.c |  70
> +
>  libavutil/encode_info.h | 110
> 
>  libavutil/frame.c   |   1 +
>  libavutil/frame.h   |   7 +++
>  5 files changed, 190 insertions(+)
>
>
A very gentle ping.
___
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] libavfilter: extractqp filter

2019-08-19 Thread Juan De León
Extracts quantization parameters data from AVEncodeInfoFrame side data,
if available, then calculates min/max/avg and outputs the results in a log file.

Signed-off-by: Juan De León 
---
 doc/filters.texi   |  40 ++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_extractqp.c | 243 +
 4 files changed, 285 insertions(+)
 create mode 100644 libavfilter/vf_extractqp.c

diff --git a/doc/filters.texi b/doc/filters.texi
index e081cdc7bc..46a82b147a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9607,6 +9607,46 @@ ffmpeg -i video.avi -filter_complex 
'extractplanes=y+u+v[y][u][v]' -map '[y]' y.
 @end example
 @end itemize
 
+@section extractqp
+
+Extracts Quantization Parameters from @code{AVFrameSideData} and calculates 
min/max/avg QP.
+
+QP extraction must be enabled with the option @code{-debug extractqp} before 
decoding the stream and calling the filter.
+
+The filter accepts the following options:
+@table @option
+@item stats_file, f
+If specified, the filter will use the named file to output the QP data. If set 
to '-' the data is sent to standard output.
+@item log
+If specificed, sets the log level for the output out of three options 
(defaults to frame):
+@table @samp
+@item frame
+Default log level. Outputs min/max/avg per frame.
+@item block
+Outputs qp data for every block in each frame.
+@item all
+Outputs min/max/avg and block data per frame.
+@end table
+@end table
+
+Supported decoders:
+@itemize
+@item x264
+@end itemize
+
+@subsection Examples
+
+@itemize
+@item Get QP min/max/avg and store it in QP.log
+@example
+ffmpeg -debug extractqp -i  -lavfi  extractqp="stats_file=QP.log" -f 
null -
+@end example
+@item Output only block data
+@example
+ffmpeg -debug extractqp -i  -lavfi  
extractqp="stats_file=QP.log:log=block" -f null -
+@end example
+@end itemize
+
 @section elbg
 
 Apply a posterize effect using the ELBG (Enhanced LBG) algorithm.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index efc7bbb153..5944558c14 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -231,6 +231,7 @@ OBJS-$(CONFIG_EROSION_FILTER)+= 
vf_neighbor.o
 OBJS-$(CONFIG_EROSION_OPENCL_FILTER) += vf_neighbor_opencl.o opencl.o \
 opencl/neighbor.o
 OBJS-$(CONFIG_EXTRACTPLANES_FILTER)  += vf_extractplanes.o
+OBJS-$(CONFIG_EXTRACTQP_FILTER)  += vf_extractqp.o
 OBJS-$(CONFIG_FADE_FILTER)   += vf_fade.o
 OBJS-$(CONFIG_FFTDNOIZ_FILTER)   += vf_fftdnoiz.o
 OBJS-$(CONFIG_FFTFILT_FILTER)+= vf_fftfilt.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index abd726d616..93ea25401a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -217,6 +217,7 @@ extern AVFilter ff_vf_eq;
 extern AVFilter ff_vf_erosion;
 extern AVFilter ff_vf_erosion_opencl;
 extern AVFilter ff_vf_extractplanes;
+extern AVFilter ff_vf_extractqp;
 extern AVFilter ff_vf_fade;
 extern AVFilter ff_vf_fftdnoiz;
 extern AVFilter ff_vf_fftfilt;
diff --git a/libavfilter/vf_extractqp.c b/libavfilter/vf_extractqp.c
new file mode 100644
index 00..67a1770849
--- /dev/null
+++ b/libavfilter/vf_extractqp.c
@@ -0,0 +1,243 @@
+/*
+ * 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 "libavutil/frame.h"
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+#include "libavutil/encode_info.h"
+#include "libavfilter/avfilter.h"
+#include "libavfilter/internal.h"
+#include "libavfilter/video.h"
+#include "libavformat/avio.h"
+
+// Output flags
+#define EXTRACTQP_LOG_FRAME (1<<0)
+#define EXTRACTQP_LOG_BLOCK (1<<1)
+
+typedef struct ExtractQPContext {
+const AVClass *class;
+int log_level, nb_frames;
+int frame_w, frame_h;
+AVEncodeInfoFrame *frame_info;
+int min_q, max_q;
+double avg_q;
+FILE *stats_file;
+char *stats_file_str;
+AVIOContext *avio_context;
+} ExtractQPContext;
+
+#define OFFSET(x) offsetof(ExtractQPContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+

[FFmpeg-devel] [PATCH 0/3] AVEncodeInfo and extractqp changes

2019-08-19 Thread Juan De León
Proposed changes to use AVEncodeInfoFrame and AVencodeInfoBlock
data types as AVFrameSideData, including the changes tothe h264
decoder as well as a filter to output the data extracted.

Filter can be called using:
ffmpeg -debug extractqp -i  -lavfi extractqp=extractqp.log -f null -

More options in filters.texi, libx264 has to be enabled.

doc/filters.texi   |  40 ++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_extractqp.c | 243 
+
 4 files changed, 285 insertions(+)

libavcodec/avcodec.h   |  1 +
 libavcodec/h264dec.c   | 40 
 libavcodec/options_table.h |  1 +
 3 files changed, 42 insertions(+)

libavutil/Makefile  |   2 ++
 libavutil/encode_info.c |  70 
+
 libavutil/encode_info.h | 110 

 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 190 insertions(+)



___
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] libavutil: AVEncodeInfo data structures

2019-08-19 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  70 +
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 190 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..348f7cda29
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,70 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+// To prevent overflow, assumes max number = 1px blocks for 8k video.
+#define AV_ENCODE_INFO_MAX_BLOCKS 33177600
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, unsigned int 
nb_blocks) {
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(unsigned int nb_blocks)
+{
+if (nb_blocks > AV_ENCODE_INFO_MAX_BLOCKS)
+return NULL;
+
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) +
+  sizeof(AVEncodeInfoBlock)*(!nb_blocks ? 0 : nb_blocks - 1);
+AVEncodeInfoFrame *ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned 
int nb_blocks)
+{
+if (nb_blocks > AV_ENCODE_INFO_MAX_BLOCKS)
+return NULL;
+
+size_t size = sizeof(AVEncodeInfoFrame) +
+  sizeof(AVEncodeInfoBlock)*(!nb_blocks ? 0 : nb_blocks - 1);
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..354411b9e1
--- /dev/null
+++ b/libavutil/encode_

[FFmpeg-devel] [PATCH 2/3] libavcodec: extractqp changes for h264 decoder

2019-08-19 Thread Juan De León
Added extractqp flag as an argument to the -debug flag to enable qp extraction
for the h264 decoder using AVEncodeInfo as AVFrameSideData.

Signed-off-by: Juan De León 
---
 libavcodec/avcodec.h   |  1 +
 libavcodec/h264dec.c   | 40 ++
 libavcodec/options_table.h |  1 +
 3 files changed, 42 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d234271c5b..9e3185720a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2671,6 +2671,7 @@ typedef struct AVCodecContext {
 #endif
 #define FF_DEBUG_BUFFERS 0x8000
 #define FF_DEBUG_THREADS 0x0001
+#define FF_DEBUG_EXTRACTQP   0x0002
 #define FF_DEBUG_GREEN_MD0x0080
 #define FF_DEBUG_NOMC0x0100
 
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8d1bd16a8e..1edbfde65e 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -28,6 +28,7 @@
 #define UNCHECKED_BITSTREAM_READER 1
 
 #include "libavutil/avassert.h"
+#include "libavutil/encode_info.h"
 #include "libavutil/display.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
@@ -906,6 +907,45 @@ static int finalize_frame(H264Context *h, AVFrame *dst, 
H264Picture *out, int *g
   f->format, f->width, f->height>>1);
 }
 
+if (h->avctx->debug & FF_DEBUG_EXTRACTQP) {
+int mb_height = h->height / 16;
+int mb_width = h->width / 16;
+int mb_xy = mb_width * mb_height;
+const PPS *pps = (const PPS*)h->ps.pps;
+
+AVEncodeInfoFrame *encode_info = 
av_encode_info_create_side_data(out->f, mb_xy);
+if (!encode_info) {
+av_log(h->avctx, AV_LOG_ERROR, "Failed to allocate encode info 
in side data\n");
+return AVERROR(ENOMEM);
+}
+
+encode_info->plane_q[0] = pps->init_qp; //base Y qp
+if (pps->chroma_qp_index_offset[0] != 0) {
+encode_info->plane_q[1] = pps->init_qp + 
pps->chroma_qp_index_offset[0];
+}
+if (pps->chroma_qp_diff != 0) {
+encode_info->plane_q[2] = pps->init_qp + 
pps->chroma_qp_index_offset[1];
+}
+
+// loop allocate qp
+int qs_index, mb_y, mb_x;
+int idx = 0;
+AVEncodeInfoBlock *block;
+for (mb_y = 0; mb_y < mb_height; mb_y++) {
+for (mb_x = 0; mb_x < mb_width; mb_x++) {
+qs_index = mb_x + mb_y * h->mb_stride; //qscale table index
+
+block = av_encode_info_get_block(encode_info, idx);
+block->src_x = mb_x * 16 - h->crop_left;
+block->src_y = mb_y * 16 - h->crop_top;
+block->w = block->h = 16;
+
+block->delta_q = out->qscale_table[qs_index] - 
pps->init_qp;
+idx++;
+}
+}
+}
+
 ret = output_frame(h, dst, out);
 if (ret < 0)
 return ret;
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 4a266eca16..e0e78a69c5 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -219,6 +219,7 @@ static const AVOption avcodec_options[] = {
 {"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"},
 {"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|A|D, "debug"},
 {"nomc", "skip motion compensation", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_NOMC }, INT_MIN, INT_MAX, V|A|D, "debug"},
+{"extractqp", "enable QP extraction per frame", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_EXTRACTQP }, INT_MIN, INT_MAX, V|D, "debug"},
 {"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), 
AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
 {"last_pred", "amount of motion predictors from the previous frame", 
OFFSET(last_predictor_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, 
INT_MAX, V|E},
 #if FF_API_PRIVATE_OPT
-- 
2.23.0.rc1.153.gdeed80330f-goog

___
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] libavutil: AVEncodeInfo data structures

2019-08-19 Thread Juan De León
On Sat, Aug 17, 2019 at 7:00 AM Nicolas George  wrote:

> > +#define AV_ENCODE_INFO_MAX_BLOCKS 33177600
> > +
> > +static int init_encode_info_data(AVEncodeInfoFrame *info, unsigned int
> nb_blocks) {
> > +info->nb_blocks = nb_blocks;
> > +info->block_size = sizeof(AVEncodeInfoBlock);
> > +info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
> > +
> > +for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
> > +info->plane_q[i] = -1;
> > +
> > +return 0;
> > +}
> > +
> > +AVEncodeInfoFrame *av_encode_info_alloc(unsigned int nb_blocks)
> > +{
> > +if (nb_blocks > AV_ENCODE_INFO_MAX_BLOCKS)
> > +return NULL;
> > +
> > +//AVEncodeInfoFrame already allocates size for one element of
> AVEncodeInfoBlock
>
> > +size_t size = sizeof(AVEncodeInfoFrame) +
> sizeof(AVEncodeInfoBlock)*FFMAX((int)(nb_blocks - 1), 0);
>
> (Commenting from my phone because urgent.)
> This line do not make sense to me. Can you explain the reason for the
> cast and how you avoid overflows?
>
In AVFrameEncodeInfo the block array is initialized as blocks[1], so when
allocating memory for the array we must consider 1 block is already
allocated.
nb_blocks can be 0, if it is unsigned the subtraction wraps it around to
UINT_MAX, the cast to int is to prevent that.
If this is confusing, I think it's better to change it to check for
nb_blocks > 0 and subtract 1.

Thanks

On Sat, Aug 17, 2019 at 7:00 AM Nicolas George  wrote:

> Juan De León (12019-08-16):
> > AVEncodeInfoFrame data structure to store as AVFrameSideData of type
> > AV_FRAME_DATA_ENCODE_INFO.
> > The structure stores quantization index for each plane, DC/AC deltas
> > for luma and chroma planes, and an array of AVEncodeInfoBlock type
> > denoting position, size, and delta quantizer for each block in the
> > frame.
> > Can be extended to support extraction of other block information.
> >
> > Signed-off-by: Juan De León 
> > ---
> >  libavutil/Makefile  |   2 +
> >  libavutil/encode_info.c |  68 +
> >  libavutil/encode_info.h | 110 
> >  libavutil/frame.c   |   1 +
> >  libavutil/frame.h   |   7 +++
> >  5 files changed, 188 insertions(+)
> >  create mode 100644 libavutil/encode_info.c
> >  create mode 100644 libavutil/encode_info.h
> >
> > diff --git a/libavutil/Makefile b/libavutil/Makefile
> > index 57e6e3d7e8..37cfb099e9 100644
> > --- a/libavutil/Makefile
> > +++ b/libavutil/Makefile
> > @@ -24,6 +24,7 @@ HEADERS = adler32.h
>  \
> >dict.h
> \
> >display.h
>  \
> >downmix_info.h
> \
> > +  encode_info.h
>  \
> >encryption_info.h
>  \
> >error.h
>  \
> >eval.h
> \
> > @@ -111,6 +112,7 @@ OBJS = adler32.o
> \
> > dict.o
>  \
> > display.o
> \
> > downmix_info.o
>  \
> > +   encode_info.o
> \
> > encryption_info.o
> \
> > error.o
> \
> > eval.o
>  \
> > diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
> > new file mode 100644
> > index 00..ec352a403b
> > --- /dev/null
> > +++ b/libavutil/encode_info.c
> > @@ -0,0 +1,68 @@
> > +/*
> > + * 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 "libavutil/encode_info.h"
> > +#include "libavutil/mem.h"
> > +
> > +// To prevent overflow, assumes max number = 1px blocks for 8k video.
> > +#define AV_ENCODE_INFO_MAX_BLOCKS 33177600
> > +
> > +static int init_encode_info_data(AVEncodeInfoFrame *info,

[FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures

2019-08-16 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  68 +
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 188 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..ec352a403b
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,68 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+// To prevent overflow, assumes max number = 1px blocks for 8k video.
+#define AV_ENCODE_INFO_MAX_BLOCKS 33177600
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, unsigned int 
nb_blocks) {
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(unsigned int nb_blocks)
+{
+if (nb_blocks > AV_ENCODE_INFO_MAX_BLOCKS)
+return NULL;
+
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMAX((int)(nb_blocks - 1), 0);
+AVEncodeInfoFrame *ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned 
int nb_blocks)
+{
+if (nb_blocks > AV_ENCODE_INFO_MAX_BLOCKS)
+return NULL;
+
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMAX((int)(nb_blocks - 1), 0);
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..354411b9e1
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,110 @@
+/*
+ * T

[FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures

2019-08-15 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  68 +
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 188 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..351333cf43
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,68 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, int nb_blocks) {
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(int nb_blocks)
+{
+AVEncodeInfoFrame *ptr;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMAX(nb_blocks - 1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, int 
nb_blocks)
+{
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMAX(nb_blocks - 1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..93d0e3fb56
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,110 @@
+/*
+ * 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

Re: [FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures

2019-08-15 Thread Juan De León
On Wed, Aug 14, 2019 at 12:11 PM Juan De León  wrote:

> AVEncodeInfoFrame data structure to store as AVFrameSideData of type
> AV_FRAME_DATA_ENCODE_INFO.
> The structure stores quantization index for each plane, DC/AC deltas
> for luma and chroma planes, and an array of AVEncodeInfoBlock type
> denoting position, size, and delta quantizer for each block in the
> frame.
> Can be extended to support extraction of other block information.
>
> Signed-off-by: Juan De León 
> ---
>  libavutil/Makefile  |   2 +
>  libavutil/encode_info.c |  68 
>  libavutil/encode_info.h | 112 
>  libavutil/frame.c   |   1 +
>  libavutil/frame.h   |   7 +++
>  5 files changed, 190 insertions(+)
>  create mode 100644 libavutil/encode_info.c
>  create mode 100644 libavutil/encode_info.h
>
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index 57e6e3d7e8..37cfb099e9 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -24,6 +24,7 @@ HEADERS = adler32.h
>\
>dict.h\
>display.h \
>downmix_info.h\
> +  encode_info.h \
>encryption_info.h \
>error.h   \
>eval.h\
> @@ -111,6 +112,7 @@ OBJS = adler32.o
>   \
> dict.o   \
> display.o\
> downmix_info.o   \
> +   encode_info.o\
> encryption_info.o\
> error.o  \
> eval.o   \
> diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
> new file mode 100644
> index 00..351333cf43
> --- /dev/null
> +++ b/libavutil/encode_info.c
> @@ -0,0 +1,68 @@
> +/*
> + * 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 "libavutil/encode_info.h"
> +#include "libavutil/mem.h"
> +
> +static int init_encode_info_data(AVEncodeInfoFrame *info, int nb_blocks) {
> +info->nb_blocks = nb_blocks;
> +info->block_size = sizeof(AVEncodeInfoBlock);
> +info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
> +
> +for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
> +info->plane_q[i] = -1;
> +
> +return 0;
> +}
> +
> +AVEncodeInfoFrame *av_encode_info_alloc(int nb_blocks)
> +{
> +AVEncodeInfoFrame *ptr;
> +//AVEncodeInfoFrame already allocates size for one element of
> AVEncodeInfoBlock
> +size_t size = sizeof(AVEncodeInfoFrame) +
> sizeof(AVEncodeInfoBlock)*FFMAX(nb_blocks - 1, 0);
> +
> +if (nb_blocks < 0 || size >= INT_MAX)
> +return NULL;
> +
> +ptr = av_mallocz(size);
> +if (!ptr)
> +return NULL;
> +
> +init_encode_info_data(ptr, nb_blocks);
> +
> +return ptr;
> +}
> +
> +AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, int
> nb_blocks)
> +{
> +size_t size = sizeof(AVEncodeInfoFrame) +
> sizeof(AVEncodeInfoBlock)*FFMAX(nb_blocks - 1, 0);
> +
> +if (nb_blocks < 0 || size >= INT_MAX)
> +return NULL;
> +
> +AVFrameSideData *sd = av_frame_new_side_data(frame,
> +
>  AV_FRAME_DATA_ENCODE_INFO,
> + size);
> +if (!sd)
> +return NU

[FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures

2019-08-14 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  68 
 libavutil/encode_info.h | 112 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 190 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..351333cf43
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,68 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, int nb_blocks) {
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(int nb_blocks)
+{
+AVEncodeInfoFrame *ptr;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMAX(nb_blocks - 1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, int 
nb_blocks)
+{
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMAX(nb_blocks - 1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..ae0a6563dc
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,112 @@
+/*
+ * 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

Re: [FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures

2019-08-14 Thread Juan De León
On Wed, Aug 14, 2019 at 12:10 AM Nicolas George  wrote:

> James Almer (12019-08-13):
> > I'm fairly sure this was discussed before, but invalid arguments
> > shouldn't crash an user's application. They even have their own
> > standardized errno value for this purpose.
> > asserts() are to catch bugs in our code, not in theirs. Returning a NULL
> > pointer is the preferred behavior.
>
> I do not agree. Asserts are to catch all bugs that can be catched
> statically. There is no sense in making some bugs harder to catch just
> because they involve separate developers.
>
> Nobody can predict whether a disk will make a I/O error, whether there
> will be enough memory, etc., that kind of error MUST be handled
> gracefully.
>
> On the other hand, it is easy to make sure that a buffer given to read()
> is not NULL, and therefore it is very acceptable to just crash when that
> happens.
>
> EINVAL is for cases where the acceptable value cannot be easily
> predicted by the caller. For example, setting an unsupported sample rate
> for the sound device: the caller could check in advance, but that would
> be cumbersome.
>
> Now, please tell me, according to you, "idx is not smaller than
> nb_blocks", is it more akin to a disk I/O error, a NULL buffer or an
> invalid sample rate?
>
> Another argument:
>
> Instead of providing utility code, we could just document the
> arithmetic. In that case, the application would have code that says, in
> essence: "block = info + offset + idx * block_size". No check. What
> would happen if idx was too big? Not a graceful error: a crash, or
> worse.
>
> The assert mimics that, in a more convenient way since it gives the
> reason and line number, and does not allow the bug to devolve into
> something more serious than a crash.
>
> Regards,
>
> --
>   Nicolas George
> ___
> 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".


In that case, I believe documenting the size of the array and behaviour of
undefined indexes should be enough. Have the pointers return NULL,
and let the user handle the result, instead of stopping the execution.

I would prefer to discuss the actual data structure for now.
___
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] libavutil: AVEncodeInfo data structures

2019-08-13 Thread Juan De León
On Tue, Aug 13, 2019 at 4:49 PM James Almer  wrote:

> I'm fairly sure this was discussed before, but invalid arguments
> shouldn't crash an user's application. They even have their own
> standardized errno value for this purpose.
> asserts() are to catch bugs in our code, not in theirs. Returning a NULL
> pointer is the preferred behavior.
>

Thank you for the feedback, I will update the patch accordingly.
Also I noticed I was using FFMIN instead of FFMAX here:
size_t size = sizeof(AVEncodeInfoFrame) +
sizeof(AVEncodeInfoBlock)*FFMIN(nb_blocks
- 1, 0);

If anyone has any more feedback or wants to discuss the patch I'll also be
available in the IRC channel.
___
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] libavutil: AVEncodeInfo data structures

2019-08-13 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  68 +
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 188 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..631934efc2
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,68 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, int nb_blocks) {
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(unsigned nb_blocks)
+{
+AVEncodeInfoFrame *ptr;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMIN(nb_blocks - 1, 0);
+
+if (size >= INT_MAX)
+return NULL;
+
+ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, unsigned 
nb_blocks)
+{
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMIN(nb_blocks - 1, 0);
+
+if (size >= INT_MAX)
+return NULL;
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..8408deb382
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,110 @@
+/*
+ * 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 th

Re: [FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures

2019-08-13 Thread Juan De León
On Tue, Aug 13, 2019 at 2:49 PM Nicolas George  wrote:

> > +info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
>
> You can use sizeof(AVEncodeInfoFrame) and dispense with the blocks final
> array entirely.
>
The array is there so that the structure isn't opaque, it should be
accessed with the function.


> > +if (!info || idx >= info->nb_blocks || idx < 0)
> > +return NULL;
>
> How valid is it for applications to call with idx outside the range?

They shouldn't but I figure it's better to return NULL than to get
undefined behaviour.
___
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] libavutil: AVEncodeInfo data structures

2019-08-13 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/encode_info.c |  68 +
 libavutil/encode_info.h | 110 
 libavutil/frame.c   |   1 +
 libavutil/frame.h   |   7 +++
 5 files changed, 188 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..ffc43f2c19
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,68 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *info, int nb_blocks) {
+info->nb_blocks = nb_blocks;
+info->block_size = sizeof(AVEncodeInfoBlock);
+info->blocks_offset = offsetof(AVEncodeInfoFrame, blocks);
+
+for(int i = 0; i < AV_NUM_DATA_POINTERS; i++)
+info->plane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(int nb_blocks)
+{
+AVEncodeInfoFrame *ptr;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMIN(nb_blocks - 1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, int 
nb_blocks)
+{
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMIN(nb_blocks - 1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..864e42bdcf
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,110 @@
+/*
+ * 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

Re: [FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures

2019-08-12 Thread Juan De León
Pinging,
Any other opinions?

On Sat, Aug 10, 2019 at 2:22 AM Nicolas George  wrote:

> Lynne (12019-08-10):
> > >> +typedef struct AVEncodeInfoBlock{
> > >> +/**
> > >> + * Distance in luma pixels from the top-left corner of the
> visible frame
> > >> + * to the top-left corner of the block.
> > >> + * Can be negative if top/right padding is present on the coded
> frame.
> > >> + */
> > >> +int src_x, src_y;
> > >> +/**
> > >> + * Width and height of the block in luma pixels
> > >> + */
> > >> +int w, h;
> > >> +/**
> > >> + * Delta quantization index for the block
> > >> + */
> > >> +int delta_q;
> > >> +
> > >>
> > >> +uint8_t reserved[128];
> > >>
> > > What are these (this one and the one below) reserved fields for?
> >
> > For future extensions without breaking the API. Things like block type,
> prediction type, motion vectors, references, etc.
>
> I suspected as much. But remember that setting the size of reserved
> after fields are added will be very tricky: it requires taking into
> account alignment and padding in the structure.
>
> I think something like that might be easier to manage (and also use less
> memory right now):
>
> typedef struct AVEncodeInfoFrame {
> ...
> size_t blocks_offset;
> size_t block_size;
> }
>
> static inline AVEncodeInfoBlock *
> av_encode_info_block(AVEncodeInfoFrame *info, unsigned idx)
> {
> return (AVEncodeInfoBlock *)
>((char *)info + info->blocks_offset +
> idx * info->block_size);
> }
>
> static inline AVEncodeInfoBlock *
> av_encode_info_block_next(AVEncodeInfoFrame *info, AVEncodeInfoBlock
> *block)
> {
> return (AVEncodeInfoBlock *)
>((char *)block + info->block_size);
> }
>
> Regards,
>
> --
>   Nicolas George
> ___
> 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] libavutil: AVEncodeInfo data structures

2019-08-09 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas
for luma and chroma planes, and an array of AVEncodeInfoBlock type
denoting position, size, and delta quantizer for each block in the
frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |  2 +
 libavutil/encode_info.c | 68 +++
 libavutil/encode_info.h | 90 +
 libavutil/frame.c   |  1 +
 libavutil/frame.h   |  7 
 5 files changed, 168 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..6d832b2e36
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,68 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *ptr, int nb_blocks) {
+ptr->nb_blocks = nb_blocks;
+ptr->dc_q = ptr->ac_q = -1;
+ptr->dc_chroma_q = ptr->ac_chroma_q = -1;
+
+for(int i=0;iplane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(int nb_blocks)
+{
+AVEncodeInfoFrame *ptr;
+//AVEncodeInfoFrame already allocates size for one element of 
AVEncodeInfoBlock
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMIN(nb_blocks-1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, int 
nb_blocks)
+{
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*FFMIN(nb_blocks-1, 0);
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..f4175b43c9
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,90 @@
+/*
+ * 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

[FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures and AV_FRAME_DATA_ENCODE_INFO AVFrameSideDataType

2019-08-09 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type 
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas for luma 
and chroma planes, and an array of AVEncodeInfoBlock struct denoting position, 
size, and delta quantizer for each block in the frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |  2 +
 libavutil/encode_info.c | 67 +++
 libavutil/encode_info.h | 87 +
 libavutil/frame.c   |  1 +
 libavutil/frame.h   |  7 
 5 files changed, 164 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..68c30af4d7
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,67 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *ptr, int nb_blocks) {
+ptr->nb_blocks = nb_blocks;
+ptr->dc_q = ptr->ac_q = -1;
+ptr->dc_chroma_q = ptr->ac_chroma_q = -1;
+
+for(int i=0;iplane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(int nb_blocks)
+{
+AVEncodeInfoFrame *ptr;
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*nb_blocks;
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, int 
nb_blocks)
+{
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*nb_blocks;
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..cbe8be2891
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,87 @@
+/*
+ * 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 wi

[FFmpeg-devel] [PATCH] libavutil: AVEncodeInfo data structures and AV_FRAME_DATA_ENCODE_INFO AVFrameSideDataType

2019-08-09 Thread Juan De León
AVEncodeInfoFrame data structure to store as AVFrameSideData of type 
AV_FRAME_DATA_ENCODE_INFO.
The structure stores quantization index for each plane, DC/AC deltas for luma 
and chroma planes, and an array of AVEncodeInfoBlock struct denoting position, 
size, and delta quantizer for each block in the frame.
Can be extended to support extraction of other block information.

Signed-off-by: Juan De León 
---
fixed a typo in frame.h comment
 libavutil/Makefile  |  2 +
 libavutil/encode_info.c | 67 +++
 libavutil/encode_info.h | 87 +
 libavutil/frame.c   |  1 +
 libavutil/frame.h   |  7 
 5 files changed, 164 insertions(+)
 create mode 100644 libavutil/encode_info.c
 create mode 100644 libavutil/encode_info.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 57e6e3d7e8..37cfb099e9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -24,6 +24,7 @@ HEADERS = adler32.h   
  \
   dict.h\
   display.h \
   downmix_info.h\
+  encode_info.h \
   encryption_info.h \
   error.h   \
   eval.h\
@@ -111,6 +112,7 @@ OBJS = adler32.o
\
dict.o   \
display.o\
downmix_info.o   \
+   encode_info.o\
encryption_info.o\
error.o  \
eval.o   \
diff --git a/libavutil/encode_info.c b/libavutil/encode_info.c
new file mode 100644
index 00..68c30af4d7
--- /dev/null
+++ b/libavutil/encode_info.c
@@ -0,0 +1,67 @@
+/*
+ * 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 "libavutil/encode_info.h"
+#include "libavutil/mem.h"
+
+static int init_encode_info_data(AVEncodeInfoFrame *ptr, int nb_blocks) {
+ptr->nb_blocks = nb_blocks;
+ptr->dc_q = ptr->ac_q = -1;
+ptr->dc_chroma_q = ptr->ac_chroma_q = -1;
+
+for(int i=0;iplane_q[i] = -1;
+
+return 0;
+}
+
+AVEncodeInfoFrame *av_encode_info_alloc(int nb_blocks)
+{
+AVEncodeInfoFrame *ptr;
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*nb_blocks;
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+ptr = av_mallocz(size);
+if (!ptr)
+return NULL;
+
+init_encode_info_data(ptr, nb_blocks);
+
+return ptr;
+}
+
+AVEncodeInfoFrame *av_encode_info_create_side_data(AVFrame *frame, int 
nb_blocks)
+{
+size_t size = sizeof(AVEncodeInfoFrame) + 
sizeof(AVEncodeInfoBlock)*nb_blocks;
+
+if (nb_blocks < 0 || size >= INT_MAX)
+return NULL;
+
+AVFrameSideData *sd = av_frame_new_side_data(frame,
+ AV_FRAME_DATA_ENCODE_INFO,
+ size);
+if (!sd)
+return NULL;
+
+memset(sd->data, 0, size);
+init_encode_info_data((AVEncodeInfoFrame*)sd->data, nb_blocks);
+
+return (AVEncodeInfoFrame*)sd->data;
+}
diff --git a/libavutil/encode_info.h b/libavutil/encode_info.h
new file mode 100644
index 00..cbe8be2891
--- /dev/null
+++ b/libavutil/encode_info.h
@@ -0,0 +1,87 @@
+/*
+ * 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 distrib

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-08-07 Thread Juan De León
On Tue, Aug 6, 2019 at 5:07 PM Mark Thompson  wrote:

> This should be in libavcodec, not libavutil - it relates directly to
> codecs.  (Indeed, you've ended up having to define a special non-libavcodec
> enum of codecs below to make it work in libavutil at all.)
>
If this belongs in avcodec I can move it there, but I don't see a similar
data structure in that library.
I believe declaring different IDs for supported codecs here is a better
approach.


> > +enum AVQPArrIndexesH264 {  // varaible names in spec document
>
> I don't think giving these enums a tag has any value?
>
They are not used in the code, but keeping them makes the purpose of each
enum clearer.


> > +AV_QP_ARR_SIZE_H264
> > +};
> > +
> > +enum AVQPArrIndexesVP9 {   // variable names in spec document
> > +AV_QP_YAC_VP9 = 0, // get_dc_quant[][base_q_idx]
>
> This isn't right - get_dc_quant() is a function of one variable, not a
> two-dimensional array (confused with dc_qlookup[][] somehow?).
>
Thank you, I think I meant: ac_q(get_qindex()).

Why are you including higher-level frame values for VP9 and AV1, but not
> including similar ones for H.264?
>
Again, I meant get_qindex(), it is supposed to represent the quant index
for the specified segment, not frame quant index.

What is the motivation for AV1 returning the exponential coefficient
> scaling values (range 4..29247) rather than the linear parameter (range
> 0..255) as you do for H.264?

Exposing both the values was a requirement by my team.

> +#define AV_QP_ARR_MAX_SIZE AV_QP_ARR_SIZE_AV1
>
> Fixing this for all time for a particular codec which happens to need the
> most space when it is defined doesn't seem like a good idea.  E.g. you
> can't support JPEG with only this number (it would need all entries in up
> to four tables).

It might be better if the structure size wasn't fixed forever by the first
> version of the API/ABI.  Perhaps an approach something like that used for
> AVRegionOfInterest would work?
>
Each instance of AVQuantizationParams has an array of qp values/indexes
(qp_type[]) for which I need a constant to allocate memory.
The approach AVRegionOfInterest uses does not solve that problem.

> +/**
> > + * x and y coordinates of the block in pixels
> > + */
> > +int x, y;
>
> Don't call these x/y coordinates because it not clear exactly what that
> means (what is the scale, where is the origin, which direction is positive,
> where in the block is being referred to, etc.).

Instead follow the same convention as other structures in FFmpeg and define
> them as the distance in pixels from the left or the top edge of the picture
> to the top-left corner of the block.
>
That's exactly their purpose, the distance in pixels from the top-left
corner of the frame, to the top-left corner of the block. I will make the
description clearer, thank you.


> On 30/07/2019 03:19, Juan De León wrote:
> > On Mon, Jul 29, 2019 at 12:48 PM Mark Thompson  wrote:
> >>
> >> How do these values interact with cropping?
> >
> > I'm not sure I understand, could you elaborate?
>
> For codecs which include cropping such as H.26[45], the decoder may
> directly apply cropping from the stream (controlled by
> AVCodecContext.apply_cropping), possibly modified by alignment (with
> AV_CODEC_FLAG_UNALIGNED), and then sets the AVFrame cropping fields to
> reflect the remainder.

For example, in H.264 try setting the
> frame_crop_left_offset/frame_crop_top_offset fields in a stream to large
> values (h264_metadata can do this for an existing stream).  What do your
> x/y values then refer to in the result?  They could be negative to indicate
> macroblocks which are off the edges of the cropped picture, or they might
> be relative to the uncropped picture in which case you would need
> additional information to reconstruct which blocks they refer to in the
> frame you actually have.
>
The coordinates of the blocks should correspond to the coded picture,
quantization is still applied to cropped MBs outside of the frame so that
should be considered for the logging and avg calculation, similar to an
analyzer.


> > +/**
> > + * Stores an id corresponding to one of the supported codecs
> > + */
> > +enum AVExtractQPSupportedCodecs codec_id;
>
> enum AVCodecID, with this in libavcodec.
>
Like Michael said, this could cause conflict when extracting QP. It might
be better to leave it as a separate ID.

> +/**
> > + * Get the string describing the qp type for the given codec
> > + */
> > +const char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs
> codec_id, int index);
>
> I'm not sure there is a good reason to embed this in the public API - what
> user is ever goin

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-08-06 Thread Juan De León
On Mon, Aug 5, 2019 at 1:07 PM Michael Niedermayer 
wrote

> a macro would still require a major version bump as its a ABI change, if
> it changes.
> To fix this would probably require a deeper change, we could also
> of course just leave it and accept that as the maximum till the next
> ABI major bump
>

I added the macro to at least make it clearer, I don't see any other
cleaner solution at the moment.
Please review my latest patch and if there are any more concerns please let
me know.
___
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] Extract QP from h264 encoded videos

2019-08-05 Thread Juan De León
AVQuantizationParams data structure for extracting qp and storing as 
AV_FRAME_DATA_QUANTIZATION_PARAMS AVFrameSideDataType
design doc: 
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  83 
 libavutil/quantization_params.h | 110 
 4 files changed, 201 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..b64fd9c02c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data is stored as AVQuantizationParamsArray type, described in
+ * libavuitl/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..d0aff7b35a
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,83 @@
+/*
+ * 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/quantization_params.h"
+
+/**
+ * Strings describing the corresponding qp_type for each of the enums
+ * listed in libavutil/quantization_params.h
+ * Used for logging.
+ */
+
+static const char* const QP_NAMES_H264[] = {  // enum 
AVQPArrIndexesH264:
+"qp", // AV_QP_Y_H264
+"qpcb",   // AV_QP_U_H264
+"qpcr"// AV_QP_V_H264
+};
+
+static const char* const QP_NAMES_VP9[] = {   // enum 
AVQPArrIndexesVP9:
+   "qyac",// AV_QP_YAC_VP9
+   "qydc",// AV_QP_YDC_VP9
+   "quvdc",   // AV_QP_UVDC_VP9
+   "quvac",   // AV_QP_UVAC_VP9
+   "qiyac",   // AV_QP_INDEX_YAC_VP9
+   "qiydc",   // AV_QP_INDEX_YDC_VP9
+   "qiuvdc",  // AV_QP_INDEX_UVDC_VP9
+   "qiuvac"   // AV_QP_INDEX_UVAC_VP9
+   

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-08-05 Thread Juan De León
On Sat, Aug 3, 2019 at 12:15 PM Michael Niedermayer 
wrote:

> > +const char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs
> codec_id, int index)
> > +{
> > +switch (codec_id) {
> > +case AV_EXTRACT_QP_CODEC_ID_H264:
> > +return index < AV_QP_ARR_SIZE_H264 ? QP_NAMES_H264[index]
> :NULL;
> > +case AV_EXTRACT_QP_CODEC_ID_VP9:
> > +return index < AV_QP_ARR_SIZE_VP9  ? QP_NAMES_VP9[index]
> :NULL;
> > +case AV_EXTRACT_QP_CODEC_ID_AV1:
> > +return index < AV_QP_ARR_SIZE_AV1  ? QP_NAMES_AV1[index]
> :NULL;
> > +default:
> > +return NULL;
> > +}
> > +}
>
> index is checked for being too large but not for too small ( < 0 )
> not sure that is intended
>
Added a check for (index < 0) to return NULL before the switch, will submit
in new patch.


On Sat, Aug 3, 2019 at 12:36 PM Michael Niedermayer 
wrote:

> > +if (h->avctx->debug & FF_DEBUG_EXTRACTQP) {
> > +int mb_height = h->height / 16;
> > +int mb_width = h->width / 16;
>
> has this been tested with files which have dimensions not a multiple of 16
> ?
>
Yes, tested with a 640x360 video, width and height here correspond to the
coded dimension, which are always multiples of 16 so I believe this should
not be a problem.
typedef struct H264Context

{
...

/* coded dimensions -- 16 * mb w/h */int width
,
height 
;
   ...

> +if (!sd) {
> > +return AVERROR(ENOMEM);
>
> buffer leaks here
>
I updated it to allocate an array of AVQuantizationParams in the side data
so that it can all be freed with a single call. I will submit the new patch
when the patch for libavutil is approved.


On Sat, Aug 3, 2019 at 12:45 PM Michael Niedermayer 
wrote:

>  +int qp_type[AV_QP_ARR_SIZE_AV1];

What happens if a future codec needs more than AV1 ?
> i think this would not be extendible without breaking ABI

Would a macro for largest size be better in this case? I will make that
change in a new patch also.
___
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] Extract QP from h264 encoded videos

2019-08-01 Thread Juan De León
Fixed

design doc: 
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  42 +
 libavutil/quantization_params.h | 101 
 4 files changed, 151 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..b64fd9c02c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data is stored as AVQuantizationParamsArray type, described in
+ * libavuitl/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..152be71ba7
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,42 @@
+/*
+ * 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/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp", "qpcb", "qpcr"};
+
+static const char* const QP_NAMES_VP9[] = {"qyac", "qydc", "quvdc", "quvac",
+   "qiyac", "qiydc", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qyac", "qydc", "qudc", "quac", 
"qvdc", "qvac",
+  "qiyac", "qiydc", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+const char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs codec_id, 
int index)
+{
+switch (codec_id) {
+case AV_EXTRACT_QP_CODEC_ID_H264:
+return index < AV_QP_ARR_SIZE_H264 ? QP_NAMES_H264[index] :NULL;
+case AV_EXTRACT_QP_CODEC_ID_VP9:
+return index < AV_QP_ARR_SIZE_VP9  ? QP_NAMES_VP9[index]  :NULL;
+case AV_EXTRACT_QP_CODEC_ID_AV1:
+return index < AV_QP_ARR_SIZE_AV1  ? QP_NAMES_AV1[index]  :NULL;
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..23f4311293
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,101 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free softw

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-08-01 Thread Juan De León
On Tue, Jul 30, 2019 at 6:50 PM Juan De León  wrote:

> Removed AVQuantizationParamsArray to prevent ambiguous memory allocation.
> For simplicity, the side data will be allocated as an array of
> AVQuantizationParams and the last element of the array will have w and h
> set to 0.
>
> Better explained in the doc.
> design doc:
> https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing
>
> Signed-off-by: Juan De León 
> ---
>  libavutil/Makefile  |   2 +
>  libavutil/frame.h   |   6 ++
>  libavutil/quantization_params.c |  41 +
>  libavutil/quantization_params.h | 101 
>  4 files changed, 150 insertions(+)
>  create mode 100644 libavutil/quantization_params.c
>  create mode 100644 libavutil/quantization_params.h
>
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index 8a7a44e4b5..be1a9c3a9c 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -60,6 +60,7 @@ HEADERS = adler32.h
>\
>pixdesc.h \
>pixelutils.h  \
>pixfmt.h  \
> +  quantization_params.h \
>random_seed.h \
>rc4.h \
>rational.h\
> @@ -140,6 +141,7 @@ OBJS = adler32.o
>   \
> parseutils.o \
> pixdesc.o\
> pixelutils.o \
> +   quantization_params.o\
> random_seed.o\
> rational.o   \
> reverse.o\
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 5d3231e7bb..b64fd9c02c 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -179,6 +179,12 @@ enum AVFrameSideDataType {
>   * array element is implied by AVFrameSideData.size /
> AVRegionOfInterest.self_size.
>   */
>  AV_FRAME_DATA_REGIONS_OF_INTEREST,
> +/**
> + * To extract quantization parameters from supported decoders.
> + * The data is stored as AVQuantizationParamsArray type, described in
> + * libavuitl/quantization_params.h
> + */
> +AV_FRAME_DATA_QUANTIZATION_PARAMS,
>  };
>
>  enum AVActiveFormatDescription {
> diff --git a/libavutil/quantization_params.c
> b/libavutil/quantization_params.c
> new file mode 100644
> index 00..7d8b0a4526
> --- /dev/null
> +++ b/libavutil/quantization_params.c
> @@ -0,0 +1,41 @@
> +/*
> + * 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 "libavutil/quantization_params.h"
> +
> +static const char* const QP_NAMES_H264[] = {"qp", "qpcb", "qpcr"};
> +
> +static const char* const QP_NAMES_VP9[] = {"qyac", "qydc", "quvdc",
> "quvac",
> +   "qiyac", "qiydc", "qiuvdc",
> "qiuvac"};
> +
> +static const char* const QP_NAMES_AV1[] = {"qyac", "qydc", "qudc",
> "quac", "qvdc", "qvac",
> +  "qiyac", "qiydc", "qiudc", "qiuac",
> "qivdc", "qivac"};
> +
> +const char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs
> codec_id, int index)
> +{
> +swi

[FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-30 Thread Juan De León
Removed AVQuantizationParamsArray to prevent ambiguous memory allocation.
For simplicity, the side data will be allocated as an array of 
AVQuantizationParams and the last element of the array will have w and h set to 
0.

Better explained in the doc.
design doc: 
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  41 +
 libavutil/quantization_params.h | 101 
 4 files changed, 150 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..b64fd9c02c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data is stored as AVQuantizationParamsArray type, described in
+ * libavuitl/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..7d8b0a4526
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,41 @@
+/*
+ * 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 "libavutil/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp", "qpcb", "qpcr"};
+
+static const char* const QP_NAMES_VP9[] = {"qyac", "qydc", "quvdc", "quvac",
+   "qiyac", "qiydc", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qyac", "qydc", "qudc", "quac", 
"qvdc", "qvac",
+  "qiyac", "qiydc", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+const char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs codec_id, 
int index)
+{
+switch (codec_id) {
+case AV_EXTRACT_QP_CODEC_ID_H264:
+return index < AV_QP_ARR_SIZE_H264 ? QP_NAMES_H264[index] :NULL;
+case AV_EXTRACT_QP_CODEC_ID_VP9:
+return index < AV_QP_ARR_SIZE_VP9  ? QP_NAMES_VP9[index]  :NULL;
+case AV_EXTRACT_QP_CODEC_ID_AV1:
+return index < AV_QP_ARR_SIZE_AV1  ? QP_NAMES_AV1[index]  :NULL;
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_para

[FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-30 Thread Juan De León
av_get_qp_type_string now returns const char
added descriptions to QP in enum
Tell me what you think.

design doc: 
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  41 
 libavutil/quantization_params.h | 115 
 4 files changed, 164 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..b64fd9c02c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data is stored as AVQuantizationParamsArray type, described in
+ * libavuitl/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..7d8b0a4526
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,41 @@
+/*
+ * 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 "libavutil/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp", "qpcb", "qpcr"};
+
+static const char* const QP_NAMES_VP9[] = {"qyac", "qydc", "quvdc", "quvac",
+   "qiyac", "qiydc", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qyac", "qydc", "qudc", "quac", 
"qvdc", "qvac",
+  "qiyac", "qiydc", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+const char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs codec_id, 
int index)
+{
+switch (codec_id) {
+case AV_EXTRACT_QP_CODEC_ID_H264:
+return index < AV_QP_ARR_SIZE_H264 ? QP_NAMES_H264[index] :NULL;
+case AV_EXTRACT_QP_CODEC_ID_VP9:
+return index < AV_QP_ARR_SIZE_VP9  ? QP_NAMES_VP9[index]  :NULL;
+case AV_EXTRACT_QP_CODEC_ID_AV1:
+return index < AV_QP_ARR_SIZE_AV1  ? QP_NAMES_AV1[index]  :NULL;
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..561216ccbd
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-30 Thread Juan De León
On Tue, Jul 30, 2019 at 2:20 AM Andrey Semashev 
wrote:

> Just a thought. If you need codec ids and implement codec-specific
> functionality, then this whole thing probably belongs to libavcodec, not
> libavutil.
>

My understanding is that only encoders and decoders are supposed to be in
libavcodec.
I believe this fits better in libavutil for consistency.
___
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] Extract QP from h264 encoded videos

2019-07-30 Thread Juan De León
On Mon, Jul 29, 2019 at 7:59 PM James Almer  wrote:

> Side data, or more specifically, any AVBufferRef, must be a flat array.
> You can't have pointers to some other allocated buffer within them since
> you can't really control their lifetime.
>
Here's a snippet of how I'm doing it right now:
// mb_xy = number of blocks in the frame
size_t buf_size = sizeof(AVQuantizationParamsArray) + mb_xy *
sizeof(AVQuantizationParams);
AVBufferRef *buffer = av_buffer_alloc(buf_size);
AVQuantizationParamsArray *params = (AVQuantizationParamsArray
*)buffer->data;

// offset memory for qp_block_array in same buffer
params->qp_block_array = (AVQuantizationParams*) (params + 1);

AVFrameSideData *sd;
sd = av_frame_new_side_data_from_buf(dst,
AV_FRAME_DATA_QUANTIZATION_PARAMS, buffer);

The idea is to keep everything in the same buffer so that it can all be
freed when AVFrameSideData is freed.
Let me know if this doesn't look right to you.
___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
I tried to fix all you suggested, please have a look and let me know what you 
think.

design doc: 
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  42 
 libavutil/quantization_params.h | 114 
 4 files changed, 164 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..b64fd9c02c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data is stored as AVQuantizationParamsArray type, described in
+ * libavuitl/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..fc51b55eee
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,42 @@
+/*
+ * 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 "libavutil/quantization_params.h"
+#include "libavutil/mem.h"
+
+static const char* const QP_NAMES_H264[] = {"qpy", "qpuv"};
+
+static const char* const QP_NAMES_VP9[] = {"qyac", "qydc", "quvdc", "quvac",
+   "qiyac", "qiydc", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", 
"qvdc", "qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs codec_id, int 
index)
+{
+switch (codec_id) {
+case AV_EXTRACT_QP_CODEC_ID_H264:
+return index < AV_QP_ARR_SIZE_H264 ? 
av_strdup(QP_NAMES_H264[index]) :NULL;
+case AV_EXTRACT_QP_CODEC_ID_VP9:
+return index < AV_QP_ARR_SIZE_VP9  ? 
av_strdup(QP_NAMES_VP9[index])  :NULL;
+case AV_EXTRACT_QP_CODEC_ID_AV1:
+return index < AV_QP_ARR_SIZE_AV1  ? 
av_strdup(QP_NAMES_AV1[index])  :NULL;
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..d123aade3b
--- /dev/null
+++ b/l

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
On Mon, Jul 29, 2019 at 12:48 PM Mark Thompson  wrote:

> This doesn't belong in the commit message.
>
> What does belong here would be some commentary on why you want this
> feature.
>
Here is the, somewhat outdated, design document, this should explain it.
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

In short the purpose is to implement an API to extract QP and calculate min
max and average.

> +int x, y;
>
> How do these values interact with cropping?

I'm not sure I understand, could you elaborate?

> +AVQuantizationParams *qp_arr;
>
> Side-data is reference counted, so how is this pointer managed?  More
> genrally, it would probably help to explain exactly how this is allocated
> and who will be responsible for freeing it.
>
The idea is to allocate the memory, for AVQuantizationParamsArray and the
necessary number of AVQuantizationParams, in a single buffer that can be
freed when the side data is freed.


> > +enum QP_ARR_INDEXES_FOR_H264 {
> > +QP_H264 = 0,// qp value
>
> What value specifically does this refer to?  QP_Y or QP'_Y for the given
> block?
>
It refers to the final QP of the block, not the delta.
Also Added a field for chroma QP, thanks!


> What is the proposed consumer of this?  It might help if you provided that
> as well (a filter?).
>
The filter is incomplete but I can submit what I have so far if needed to
give more context.
The document explains it better.
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing
___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Thank you for the feedback Andrey, I will fix it ASAP.

On Mon, Jul 29, 2019 at 12:11 PM Andreas Håkon 
wrote:

> Interesting patch. But I have a question:
> Could you implement the same thing when using the hardware decoders?

I believe this might be in the scope of my project.
I'm not too familiar with hardware decoders but when I complete the rest of
the implementation I will take a look at this.


> And also, could you make a similar patch for MPEG-2 as well?

The scope was limited to H264, VP9 and AV1 but I will talk about it with my
team.
Again, thanks for the feedback.
___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  41 
 libavutil/quantization_params.h | 106 
 4 files changed, 155 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be5e5d831f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.o
\
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..d48ccf342f 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data stored is AVQuantizationParamsArray type, described in
+ * libavuitls/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..28b08ebe19
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,41 @@
+/*
+ * 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 "libavutil/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp"};
+
+static const char* const QP_NAMES_VP9[] = {"qydc", "qyac", "quvdc", "quvac",
+   "qiydc", "qiyac", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", 
"qvdc", "qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+char* get_qp_str(enum AVCodecID codec_id, int index)
+{
+switch (codec_id) {
+case AV_CODEC_ID_H264:
+return QP_NAMES_H264[index];
+case AV_CODEC_ID_VP9:
+return QP_NAMES_VP9[index];
+case AV_CODEC_ID_AV1:
+return QP_NAMES_AV1[index];
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..7a3daeaae5
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,106 @@
+/*
+ * 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 WARRAN

[FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Here is the second patch, I sent the first one twice accidentaly. 
First patch is libavutil, this patch is libavcodec.

Signed-off-by: Juan De León 
---
 libavcodec/avcodec.h   |  1 +
 libavcodec/h264dec.c   | 44 ++
 libavcodec/options_table.h |  1 +
 3 files changed, 46 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d234271c5b..9e3185720a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2671,6 +2671,7 @@ typedef struct AVCodecContext {
 #endif
 #define FF_DEBUG_BUFFERS 0x8000
 #define FF_DEBUG_THREADS 0x0001
+#define FF_DEBUG_EXTRACTQP   0x0002
 #define FF_DEBUG_GREEN_MD0x0080
 #define FF_DEBUG_NOMC0x0100
 
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8d1bd16a8e..52ad12e55d 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -33,6 +33,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timer.h"
+#include "libavutil/quantization_params.h"
 #include "internal.h"
 #include "bytestream.h"
 #include "cabac.h"
@@ -922,6 +923,49 @@ static int finalize_frame(H264Context *h, AVFrame *dst, 
H264Picture *out, int *g
 }
 }
 
+if (h->avctx->debug & FF_DEBUG_EXTRACTQP) {
+int mb_height = h->height / 16;
+int mb_width = h->width / 16;
+int mb_xy = mb_width * mb_height;
+
+int buf_size = sizeof(AVQuantizationParamsArray) +
+   mb_xy * sizeof(AVQuantizationParams);
+AVBufferRef *buffer = av_buffer_alloc(buf_size);
+if (!buffer) {
+return AVERROR(ENOMEM);
+}
+
+AVQuantizationParamsArray *params = (AVQuantizationParamsArray 
*)buffer->data;
+params->nb_blocks = mb_xy;
+params->codec_id = h->avctx->codec_id;
+// offset memory for qp_arr in same buffer
+params->qp_arr = (AVQuantizationParams*) (params + 1);
+
+// loop allocate qp
+int qp_index = 0;
+for (int mb_y = 0; mb_y < mb_height; mb_y++) {
+for (int mb_x = 0; mb_x < mb_width; mb_x++) {
+int qs_index = mb_x + mb_y * h->mb_stride;
+AVQuantizationParams *qp_block = &(params->qp_arr[qp_index]);
+
+qp_block->x = mb_x * 16;
+qp_block->y = mb_y * 16;
+qp_block->w = qp_block->h = 16;
+qp_block->type[QP_H264] = out->qscale_table[qs_index];
+
+qp_index++;
+}
+}
+
+AVFrameSideData *sd;
+sd = av_frame_new_side_data_from_buf(dst,
+ AV_FRAME_DATA_QUANTIZATION_PARAMS,
+ buffer);
+if (!sd) {
+return AVERROR(ENOMEM);
+}
+}
+
 return 0;
 }
 
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 4a266eca16..e0e78a69c5 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -219,6 +219,7 @@ static const AVOption avcodec_options[] = {
 {"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"},
 {"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|A|D, "debug"},
 {"nomc", "skip motion compensation", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_NOMC }, INT_MIN, INT_MAX, V|A|D, "debug"},
+{"extractqp", "enable QP extraction per frame", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_EXTRACTQP }, INT_MIN, INT_MAX, V|D, "debug"},
 {"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), 
AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
 {"last_pred", "amount of motion predictors from the previous frame", 
OFFSET(last_predictor_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, 
INT_MAX, V|E},
 #if FF_API_PRIVATE_OPT
-- 
2.22.0.709.g102302147b-goog

___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Changes to libavcodec, hope this addresses all your comments.
Cheers.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  41 
 libavutil/quantization_params.h | 106 
 4 files changed, 155 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be5e5d831f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.o
\
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..d48ccf342f 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data stored is AVQuantizationParamsArray type, described in
+ * libavuitls/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..28b08ebe19
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,41 @@
+/*
+ * 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 "libavutil/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp"};
+
+static const char* const QP_NAMES_VP9[] = {"qydc", "qyac", "quvdc", "quvac",
+   "qiydc", "qiyac", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", 
"qvdc", "qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+char* get_qp_str(enum AVCodecID codec_id, int index)
+{
+switch (codec_id) {
+case AV_CODEC_ID_H264:
+return QP_NAMES_H264[index];
+case AV_CODEC_ID_VP9:
+return QP_NAMES_VP9[index];
+case AV_CODEC_ID_AV1:
+return QP_NAMES_AV1[index];
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..7a3daeaae5
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,106 @@
+/*
+ * 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 i

Re: [FFmpeg-devel] [PATCH] Setup for extracting quantization parameters from encoded streams

2019-07-25 Thread Juan De León
I submitted another patch in a new email thread addressing your concerns,
apologies for the confusion.
The subject is "[PATCH] Extract QP from h264 encoded videos".
Here is the link to the archive
http://ffmpeg.org/pipermail/ffmpeg-devel/2019-July/247037.html
___
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] Extract QP from h264 encoded videos

2019-07-24 Thread Juan De León
Previous thread:
http://ffmpeg.org/pipermail/ffmpeg-devel/2019-July/246951.html
I added the modifications to the decoder, I ran some tests for performance
and run times are only affected if my flag is enabled.
Decoded 3 different encoded videos 20 times each with and without my debug
flag, here are the results:

*ExtractQP disabled:*
===> multitime results
1: ffmpeg -hide_banner -loglevel panic -debug 0 -i tveryfast.mp4 -f null -
MeanStd.Dev.Min Median  Max
real0.747   0.007   0.735   0.749   0.756
user5.582   0.025   5.547   5.574   5.627
sys 0.166   0.028   0.120   0.167   0.224
===> multitime results
1: ffmpeg -hide_banner -loglevel panic -debug 0 -i tmedium.mp4 -f null -
MeanStd.Dev.Min Median  Max
real0.865   0.009   0.845   0.864   0.887
user6.296   0.036   6.198   6.299   6.365
sys 0.195   0.026   0.142   0.199   0.247
===> multitime results
1: ffmpeg -hide_banner -loglevel panic -debug 0 -i tveryslow.mp4 -f null -
MeanStd.Dev.Min Median  Max
real0.919   0.011   0.892   0.920   0.943
user6.398   0.042   6.311   6.381   6.476
sys 0.229   0.032   0.169   0.238   0.287

*ExtractQP enabled: *
===> multitime results
1: ffmpeg -hide_banner -loglevel panic -debug extractqp -i tveryfast.mp4 -f
null -
MeanStd.Dev.Min Median  Max
real1.126   0.032   1.076   1.132   1.216
user6.433   0.054   6.347   6.430   6.561
sys 1.069   0.047   0.989   1.063   1.161
===> multitime results
1: ffmpeg -hide_banner -loglevel panic -debug extractqp -i tmedium.mp4 -f
null -
MeanStd.Dev.Min Median  Max
real1.178   0.020   1.143   1.176   1.217
user7.091   0.055   7.020   7.081   7.196
sys 1.031   0.057   0.898   1.043   1.131
===> multitime results
1: ffmpeg -hide_banner -loglevel panic -debug extractqp -i tveryslow.mp4 -f
null -
MeanStd.Dev.Min Median  Max
real1.234   0.028   1.196   1.230   1.322
user7.212   0.077   6.996   7.230   7.345
sys 1.067   0.076   0.938   1.062   1.283
___
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] Extract QP from h264 encoded videos

2019-07-24 Thread Juan De León
---
 libavcodec/avcodec.h|   1 +
 libavcodec/h264dec.c|  37 
 libavcodec/options_table.h  |   1 +
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  40 +
 libavutil/quantization_params.h | 102 
 7 files changed, 189 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d234271c5b..9e3185720a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2671,6 +2671,7 @@ typedef struct AVCodecContext {
 #endif
 #define FF_DEBUG_BUFFERS 0x8000
 #define FF_DEBUG_THREADS 0x0001
+#define FF_DEBUG_EXTRACTQP   0x0002
 #define FF_DEBUG_GREEN_MD0x0080
 #define FF_DEBUG_NOMC0x0100
 
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8d1bd16a8e..07b85f4e0a 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -33,6 +33,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timer.h"
+#include "libavutil/quantization_params.h"
 #include "internal.h"
 #include "bytestream.h"
 #include "cabac.h"
@@ -922,6 +923,42 @@ static int finalize_frame(H264Context *h, AVFrame *dst, 
H264Picture *out, int *g
 }
 }
 
+if (h->avctx->debug & FF_DEBUG_EXTRACTQP) {
+int mb_height = h->height / 16;
+int mb_width = h->width / 16;
+int mb_xy = mb_width * mb_height;
+
+AVFrameSideData *sd;
+sd = av_frame_new_side_data(dst, AV_FRAME_DATA_QUANTIZATION_PARAMS,
+  sizeof(AVQuantizationParamsArray));
+
+AVQuantizationParamsArray *params;
+params = (AVQuantizationParamsArray *)sd->data;
+params->nb_blocks = mb_xy;
+params->qp_arr = av_malloc_array(mb_xy, sizeof(AVQuantizationParams));
+
+params->codec_id = h->avctx->codec_id;
+
+// loop allocate QP
+int qp_index = 0;
+for (int mb_y = 0; mb_y < mb_height; mb_y++) {
+for (int mb_x = 0; mb_x < mb_width; mb_x++) {
+int qs_index = mb_x + mb_y * h->mb_stride;
+AVQuantizationParams *qp_block = &(params->qp_arr[qp_index]);
+
+qp_block->x = mb_x * 16;
+qp_block->y = mb_y * 16;
+qp_block->w = qp_block->h = 16;
+
+// ALLOCATE MEMORY TO THE QP ARRAY
+qp_block->type = av_malloc(QP_TYPE_ARR_SIZE_H264 * 
sizeof(int));
+qp_block->type[QP_H264] = out->qscale_table[qs_index];
+
+qp_index++;
+}
+}
+}
+
 return 0;
 }
 
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 4a266eca16..e0e78a69c5 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -219,6 +219,7 @@ static const AVOption avcodec_options[] = {
 {"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"},
 {"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|A|D, "debug"},
 {"nomc", "skip motion compensation", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_NOMC }, INT_MIN, INT_MAX, V|A|D, "debug"},
+{"extractqp", "enable QP extraction per frame", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_EXTRACTQP }, INT_MIN, INT_MAX, V|D, "debug"},
 {"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), 
AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
 {"last_pred", "amount of motion predictors from the previous frame", 
OFFSET(last_predictor_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, 
INT_MAX, V|E},
 #if FF_API_PRIVATE_OPT
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\

Re: [FFmpeg-devel] [PATCH] Setup for extracting quantization parameters from encoded streams

2019-07-22 Thread Juan De León
> On Mon, Jul 22, 2019 at 12:17 PM Lynne  wrote:
> You can't hack a decoder in any nice and performant way for it to output
data to an analyzer.
Hi, Lynne
I hear your concern about the decoder performance.
I believe that the way we would like to modify the decoder should not
affect its performance, since
AV_FRAME_QUANTIZATION_PARAMS will be disabled by default; the extraction is
done optionally with a flag.
I would be glad to verify that by running tests and measuring performance
with and without my changes.
If you have in mind any tests I should run, please let me know.

> I've explained why this is a bad idea and why you should maintain
it internally.
FFmpeg already has a lot of analyzing tools, I disagree that this change
does not belong to ffmpeg.
___
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] Setup for extracting quantization parameters from encoded streams

2019-07-22 Thread Juan De León
On Fri, Jul 19, 2019 at 12:47 PM Moritz Barsnick  wrote:

> On Fri, Jul 19, 2019 at 10:00:52 +0200, Nicolas George wrote:
> > I do not judge whether this filter would be useful and should be
> > included, but if so, then I would appreciate that the output be done
> > using AVIO, so that it can go to any supported protocol.
>
> The metadata filter has a nice example of how to use avio, incl.
> mapping to stdout:
>
>
> https://github.com/FFmpeg/FFmpeg/blob/f102a4efcef33014d414f9bf4492a04feab20c82/libavfilter/f_metadata.c#L250
>
> I suppose this can been used as a reference.
>
> 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".


Thanks, I will update the filter to use avio.
Pinging the thread.
___
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] Setup for extracting quantization parameters from encoded streams

2019-07-18 Thread Juan De León
Thanks for the feedback, appreciate it.
I added the AV_FRAME_DATA_QUANTIZATION_PARAMS type to AVFrameSideData and I 
removed the filter since it is not complete yet. 
I will send the filter and the modification to the encoders when those are done.

---
 libavutil/Makefile  |  2 +
 libavutil/frame.h   |  6 ++
 libavutil/quantization_params.c | 28 ++
 libavutil/quantization_params.h | 98 +
 4 files changed, 134 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..c0afca325c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported encoded streams.
+ * The data stored is AVQuantizationParamsArray type, described in
+ * libavuitls/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..96ffd78dbb
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,28 @@
+/*
+ * 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 "libavutil/quantization_params.h"
+
+/**
+ * Strings for names of enums, used by Filter
+ */
+const char* const QP_NAMES_H264[] = {"qp"};
+const char* const QP_NAMES_VP9[] = {"qydc", "qyac", "quvdc", "quvac", "qiydc", 
"qiyac",
+  "qiuvdc", "qiuvac"};
+const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", "qvdc", 
"qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", "qivdc", 
"qivac"};
\ No newline at end of file
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..e986abe842
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,98 @@
+/*
+ * 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, 

Re: [FFmpeg-devel] [PATCH] Setup for extracting quantization parameters from encoded streams

2019-07-17 Thread Juan De León
For context
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing
Feel free to comment the doc.

On Wed, Jul 17, 2019 at 4:18 PM Juan De León  wrote:

> ---
>  libavfilter/vf_extractqp.c  | 116 
>  libavutil/Makefile  |   2 +
>  libavutil/quantization_params.c |  28 
>  libavutil/quantization_params.h |  98 +++
>  4 files changed, 244 insertions(+)
>  create mode 100644 libavfilter/vf_extractqp.c
>  create mode 100644 libavutil/quantization_params.c
>  create mode 100644 libavutil/quantization_params.h
>
> diff --git a/libavfilter/vf_extractqp.c b/libavfilter/vf_extractqp.c
> new file mode 100644
> index 00..4332012cc4
> --- /dev/null
> +++ b/libavfilter/vf_extractqp.c
> @@ -0,0 +1,116 @@
> +/*
> + * 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 "libavutil/frame.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/quantization_params.h"
> +#include "libavfilter/avfilter.h"
> +#include "libavfilter/internal.h"
> +
> +typedef struct QPExtractContext {
> +const AVClass *class;
> +FILE *stats_file;
> +char *stats_file_str;
> +} QPExtractContext;
> +
> +#define OFFSET(x) offsetof(QPExtractContext, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> +
> +static const AVOption qpextract_options[] = {
> +{"stats_file", "Set file to store QP information",
> OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
> +{"f",  "Set file to store QP information",
> OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
> +{ NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(qpextract);
> +
> +static av_cold int init(AVFilterContext *ctx)
> +{
> +QPExtractContext *s = ctx->priv;
> +
> +if (s->stats_file_str) {
> +if (!strcmp(s->stats_file_str, "-")) {
> +s->stats_file = stdout;
> +} else {
> +s->stats_file = fopen(s->stats_file_str, "w");
> +if (!s->stats_file) {
> +int err = AVERROR(errno);
> +char buf[128];
> +av_strerror(err, buf, sizeof(buf));
> +av_log(ctx, AV_LOG_ERROR, "Could not open log file %s:
> %s\n",
> +   s->stats_file_str, buf);
> +return err;
> +}
> +}
> +}
> +return 0;
> +}
> +
> +static av_cold int uninit(AVFilterContext *ctx) {
> +return 0;
> +}
> +
> +static int filter_frame(AVFilterLink *inlink, AVFrame *in) {
> +AVFilterContext *ctx = inlink->dst;
> +AVFilterLink *outlink = ctx->outputs[0];
> +QPExtractContext *s = ctx->priv;
> +AVFrame *out = NULL;
> +
> +if (ctx->is_disabled) {
> +return ff_filter_frame(outlink, in);
> +}
> +
> +AVFrameSideData *sd = av_frame_get_side_data(in,
> AV_FRAME_DATA_QUANTIZATION_PARAMS);
> +
> +if (!sd) {
> +fprintf(s->stats_file, "no side data");
> +}
> +else {
> +fprintf(s->stats_file, "yes side data");
> +}
> +
> +return ff_filter_frame(outlink, in);
> +}
> +
> +static const AVFilterPad qpextract_inputs[] = {
> +{
> +.name = "default",
> +.type = AVMEDIA_TYPE_VIDEO,
> +.filter_frame = filter_frame,
> +},
> +{ NULL }
> +};
> +
> +static const AVFilterPad qpextract_outputs[] = {
> +{
> +.name  = "default",
> +.type  = AVMEDIA_TYPE_VIDEO,
> +},
> +{ NULL }
> +};
> +
> +AVFilter ff_vf_qpextract = {
> +.name  = "extractqp",
> +.description   = N

[FFmpeg-devel] [PATCH] Setup for extracting quantization parameters from encoded streams

2019-07-17 Thread Juan De León
---
 libavfilter/vf_extractqp.c  | 116 
 libavutil/Makefile  |   2 +
 libavutil/quantization_params.c |  28 
 libavutil/quantization_params.h |  98 +++
 4 files changed, 244 insertions(+)
 create mode 100644 libavfilter/vf_extractqp.c
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavfilter/vf_extractqp.c b/libavfilter/vf_extractqp.c
new file mode 100644
index 00..4332012cc4
--- /dev/null
+++ b/libavfilter/vf_extractqp.c
@@ -0,0 +1,116 @@
+/*
+ * 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 "libavutil/frame.h"
+#include "libavutil/opt.h"
+#include "libavutil/quantization_params.h"
+#include "libavfilter/avfilter.h"
+#include "libavfilter/internal.h"
+
+typedef struct QPExtractContext {
+const AVClass *class;
+FILE *stats_file;
+char *stats_file_str;
+} QPExtractContext;
+
+#define OFFSET(x) offsetof(QPExtractContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption qpextract_options[] = {
+{"stats_file", "Set file to store QP information", OFFSET(stats_file_str), 
AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
+{"f",  "Set file to store QP information", OFFSET(stats_file_str), 
AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(qpextract);
+
+static av_cold int init(AVFilterContext *ctx)
+{
+QPExtractContext *s = ctx->priv;
+
+if (s->stats_file_str) {
+if (!strcmp(s->stats_file_str, "-")) {
+s->stats_file = stdout;
+} else {
+s->stats_file = fopen(s->stats_file_str, "w");
+if (!s->stats_file) {
+int err = AVERROR(errno);
+char buf[128];
+av_strerror(err, buf, sizeof(buf));
+av_log(ctx, AV_LOG_ERROR, "Could not open log file %s: %s\n",
+   s->stats_file_str, buf);
+return err;
+}
+}
+}
+return 0;
+}
+
+static av_cold int uninit(AVFilterContext *ctx) {
+return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in) {
+AVFilterContext *ctx = inlink->dst;
+AVFilterLink *outlink = ctx->outputs[0];
+QPExtractContext *s = ctx->priv;
+AVFrame *out = NULL;
+
+if (ctx->is_disabled) {
+return ff_filter_frame(outlink, in);
+}
+
+AVFrameSideData *sd = av_frame_get_side_data(in, 
AV_FRAME_DATA_QUANTIZATION_PARAMS);
+
+if (!sd) {
+fprintf(s->stats_file, "no side data");
+}
+else {
+fprintf(s->stats_file, "yes side data");
+}
+
+return ff_filter_frame(outlink, in);
+}
+
+static const AVFilterPad qpextract_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_VIDEO,
+.filter_frame = filter_frame,
+},
+{ NULL }
+};
+
+static const AVFilterPad qpextract_outputs[] = {
+{
+.name  = "default",
+.type  = AVMEDIA_TYPE_VIDEO,
+},
+{ NULL }
+};
+
+AVFilter ff_vf_qpextract = {
+.name  = "extractqp",
+.description   = NULL_IF_CONFIG_SMALL("Extract quantization parameters."),
+.init  = init,
+.uninit= uninit,
+.priv_size = sizeof(QPExtractContext),
+.priv_class= _class,
+.inputs= qpextract_inputs,
+.outputs   = qpextract_outputs,
+};
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@