From patchwork Mon Jul 29 18:07:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Juan=20De=20Le=C3=B3n?= X-Patchwork-Id: 14127 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A72B6449ECC for ; Mon, 29 Jul 2019 21:15:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7DC22689A61; Mon, 29 Jul 2019 21:15:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.74]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7099A68071C for ; Mon, 29 Jul 2019 21:15:37 +0300 (EEST) Received: by mail-ot1-f74.google.com with SMTP id x18so34511603otp.9 for ; Mon, 29 Jul 2019 11:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=lCR/ncNstD1ijdSnoXMHAT4QkevekOFmM5NWuW/1Ed0=; b=GbFfVrnzRk2oUK6soQI/KNhLf6FfhrfD/UnWa77z7ZXoVIhNwhi/pLXbEezqGU0jUI jD8kUBAq/m9Ebdru4KgBQ4D3ha2uKH6KdVyCKO/BfrMDwUAKKV4oGQvXdtFns7X5jmcz KrGlAVwGorwNq1xgvCLKfX/7vGD08Dq/rU4NgoGQs9/FQTScOIaEyy/HnHZuCzlN3hqm y1461Fgz+UwBSoeSAcSNPFqQofjfG5BbN2fOFYrBIbeDDr0T4rUIG4nZQoZe95+AkD1D PoMf4OIup6IQx9UkIhFU2fzkOKKM9vIiaL3BW/RUWSFy/kekrZ5TJA2PHYknU0TZgqVq Twfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=lCR/ncNstD1ijdSnoXMHAT4QkevekOFmM5NWuW/1Ed0=; b=Bj7MXhonAE6v9p3aAVxIYMMg23oXfUS+2i13mrr3gwyFa0eX5VKLaUi5GDMgu/V4tl BkgrpKFm43rj3bN0+bp+iFFNq6fnLRAqVlx/2M4wnHvg9CpuSQkwA2asbAtxJL7oBDpC +wBmGkXOeJRa8NmoccBYJcx3k9o7VEs/w8AInuawT5eJRtC6Gh4iLj0JVdZAnRQ2s28O aMkjRGnNy95ra/R0ZKhES8g952H5YraVB3PCZOc5/HM53eFlt9pKvpLx7GvCuAug4/YD h9KomSSJFiLSywAvjnFj11eUFSpMA+31bkCyO0Zges2a8ILIzEM2qWSgS773rKTj3MTt ezeQ== X-Gm-Message-State: APjAAAUYsWqB+J5yZbmaz2UIRiVpzyQBDdPR0oSwqxrbPhs6bWIlWyy5 ahvY6PS45NtmnRsAnFdeGJmy6/AyX874op5Bu5bKW74IZ4yHrIGDkwGSPE29p3OM3TkNW4ukOV9 zevHV5ZOSVOMi0WN/B/PlAAAzCDv1CmSxnXAeU78TVwFHo2kGarNKzMT00uIvi7g= X-Google-Smtp-Source: APXvYqyXq0lHezJ09T4FGBJokbBBYswfkOMu3Rt0vqt3QJPWUvThNQdEzcdKL/ScwDXJN5L/1W5iCYE/B3s= X-Received: by 2002:a63:ea50:: with SMTP id l16mr107195418pgk.160.1564423662860; Mon, 29 Jul 2019 11:07:42 -0700 (PDT) Date: Mon, 29 Jul 2019 11:07:37 -0700 In-Reply-To: <20190725211133.GE3219@michaelspb> Message-Id: <20190729180737.217922-1-juandl@google.com> Mime-Version: 1.0 References: <20190725211133.GE3219@michaelspb> X-Mailer: git-send-email 2.22.0.709.g102302147b-goog From: "=?UTF-8?q?Juan=20De=20Le=C3=B3n?=" To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: =?UTF-8?q?Juan=20De=20Le=C3=B3n?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 0000000000..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 0000000000..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 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 + */ + +#ifndef AVUTIL_QUANTIZATION_PARAMS_H +#define AVUTIL_QUANTIZATION_PARAMS_H + +#include "libavcodec/avcodec.h" + +// Max size for the type array: QP_ARR_SIZE_AV1 = 12 +#define MAX_SIZE 12 + +/** + * Data structure for extracting Quantization Parameters, codec independent + */ +typedef struct AVQuantizationParams { + /** + * x and y coordinates of the block in pixels + */ + int x, y; + /** + * width and height of the block in pixels + */ + int w, h; + /** + * qp array, indexed by type according to + * the enum corresponding to the codec + */ + int type[MAX_SIZE]; +} AVQuantizationParams; + +/** + * For storing an array of AVQuantization parameters and its size + * Used as AVFrameSideData + */ +typedef struct AVQuantizationParamsArray { + /** + * AVQuantizationParams block array + */ + AVQuantizationParams *qp_arr; + /** + * size of the array + */ + int nb_blocks; + + enum AVCodecID codec_id; +} AVQuantizationParamsArray; + +/** + * Get the string describing the qp type for the given codec + */ +char* get_qp_str(enum AVCodecID codec_id, int index); + +/** + * Enums for different codecs to store qp in the type array + * Each enum must have an array of strings describing each field + * declared in quantization_params.c + */ +enum QP_ARR_INDEXES_FOR_H264 { + QP_H264 = 0, // qp value + QP_ARR_SIZE_H264 // used for allocating memory +}; + +enum QP_ARR_INDEXES_FOR_VP9 { + QP_YDC_VP9 = 0, + QP_YAC_VP9, + QP_UVDC_VP9, + QP_UVAC_VP9, + QP_INDEX_YDC_VP9, + QP_INDEX_YAC_VP9, + QP_INDEX_UVDC_VP9, + QP_INDEX_UVAC_VP9, + QP_ARR_SIZE_VP9 +}; + +enum QP_ARR_INDEXES_FOR_AV1 { + QP_YDC_AV1 = 0, + QP_YAC_AV1, + QP_UDC_AV1, + QP_UAC_AV1, + QP_VDC_AV1, + QP_VAC_AV1, + QP_INDEX_YDC_AV1, + QP_INDEX_YAC_AV1, + QP_INDEX_UDC_AV1, + QP_INDEX_UAC_AV1, + QP_INDEX_VDC_AV1, + QP_INDEX_VAC_AV1, + QP_ARR_SIZE_AV1 +}; + +#endif /* AVUTIL_QUANTIZATION_PARAMS_H */