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

Michael Niedermayer michael at niedermayer.cc
Sat Aug 3 22:15:26 EEST 2019


On Thu, Aug 01, 2019 at 04:48:32PM -0700, Juan De León wrote:
> Fixed

That would end in the commit message which is probably unintended


> 
> design doc: https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing
> 
> Signed-off-by: Juan De León <juandl at google.com>
> ---
>  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 0000000000..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 <stddef.h>
> +
> +#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"};
> +

The meaning of the chars in the strings should maybe be described
So generic code could interpret a new codecs qp values
though for such generic interpretation more would be needed like which direction
quality improves, if its linear or log scale, ...
so maybe this is just out of scope of this initial implementation


> +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

[...]

thx

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- 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/ecf647c5/attachment.sig>


More information about the ffmpeg-devel mailing list