[FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos
Michael Niedermayer
michael at niedermayer.cc
Sat Aug 3 22:36:42 EEST 2019
On Mon, Jul 29, 2019 at 11:12:34AM -0700, Juan De León wrote:
> 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 <juandl at google.com>
> ---
> 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 0x00008000
> #define FF_DEBUG_THREADS 0x00010000
> +#define FF_DEBUG_EXTRACTQP 0x00020000
> #define FF_DEBUG_GREEN_MD 0x00800000
> #define FF_DEBUG_NOMC 0x01000000
>
> 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;
has this been tested with files which have dimensions not a multiple of 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);
buffer leaks here
[...]
thx
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Elect your leaders based on what they did after the last election, not
based on what they say before an election.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190803/22e1e1d8/attachment.sig>
More information about the ffmpeg-devel
mailing list