From patchwork Thu Jul 18 22:07:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?UTF-8?q?Juan=20De=20Le=C3=B3n?= X-Patchwork-Id: 13984 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 19A0644990C for ; Fri, 19 Jul 2019 01:08:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E611C68AEE8; Fri, 19 Jul 2019 01:08:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3434168ABDD for ; Fri, 19 Jul 2019 01:08:32 +0300 (EEST) Received: by mail-pg1-f202.google.com with SMTP id u1so17438260pgr.13 for ; Thu, 18 Jul 2019 15:08:32 -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; bh=iHMfz5mKAxU1cFrilZfcSmSkbnGyyMNI7v4AiEAiBWk=; b=mhbmSLnEBA10pFX7sq2GJuwmz4070mobpYTS2YzG2Ha+y8iIFGM+bfgLayGKCxlnXn PfN9MMYMgMSYBuEU8xt6kv45jpNKpE6oa0qQWVn5tO9VaPBb/+g7iaSzcK5aLhNHuIUK 4l2ELNWxmPrBWeN7jqzf4+8J5yh/m18lzvZlpJ6fylJamoUeqN9LfRNpqP3HYO9fP5HG Cvw2+hGIRdyrLfFMGNz4UCz7WF+KOnbOVUHV/lyflymwoaiF4IMKW/xsRthDxg4T7x2i IlXwjk1n+Bmm6TyToWeZdQv1UW76jfrppKU461f38Cw/gdfD4wxVOj0xNRr8phdYkZ+L fZVg== 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; bh=iHMfz5mKAxU1cFrilZfcSmSkbnGyyMNI7v4AiEAiBWk=; b=ah78YbCy2KFuoFI/vQoBlahO7sdUd9jPnwK/wS8Wq6n1FUC9vmxK5GojAylWYmx5SP gHYizBhUQ2z2ZPuvAQ/uYdLrC7EBJwFPGOsUG2UcP9+tvve2BiOz+Km/wgBjrnuYzrw/ /xAJudODojv+cCWHnal0DGdC/slokN6j4eoOtBZImqdsKTgEDQCyyUAHjSssw0w/4r8r ld9C0lxHYAVFKqyOCMst586XnVJ3NRPf+SaEBTI5AmNySSr9C8HgEELR8rSTnTzx3654 i6UZ4g8P9c/2hBCozpOa3A5+jm3SFapQXReKEI1Jb/RHdgOBKORobL3E43kcVOI67xtj wusQ== X-Gm-Message-State: APjAAAVW86XDWzALHbLURlE/sVO3SPMj3EN02Y1j6slkPU1Dlfw1uvhC rnv43hZ+Mm9EqySQOfybD1CWv+wz9Cf1FUcRbn5z+EYgVfN0wMSWPTlx/XLdnZ4XrNY8nplyvTn 2yuydg8yrwLCIEpZ2g1V1VsiZLJV6ivhxA0xzi1lCrZxrHhe7ZEZdoMoYKk1oiVE= X-Google-Smtp-Source: APXvYqxfq2N2dLFBT+AMjgX1bl4cyuWI1Z5PYMA/+WcMUyVkPXX7xANlGLcT2Q7ebrIKYXahZAVftUyiIYc= X-Received: by 2002:a63:6c02:: with SMTP id h2mr48154539pgc.61.1563487709746; Thu, 18 Jul 2019 15:08:29 -0700 (PDT) Date: Thu, 18 Jul 2019 15:07:31 -0700 In-Reply-To: <20190718150759.GD28541@sunshine.barsnick.net> Message-Id: <20190718220729.98719-1-juandl@google.com> Mime-Version: 1.0 References: <20190718150759.GD28541@sunshine.barsnick.net> X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog From: "=?UTF-8?q?Juan=20De=20Le=C3=B3n?=" To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Setup for extracting quantization parameters from encoded streams 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" 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 0000000000..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 0000000000..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, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_QUANTIZATION_PARAMS_H +#define AVUTIL_QUANTIZATION_PARAMS_H + +/** + * 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 + * size depends on codec + */ + int *type; +} AVQuantizationParams; + +/** + * For storing an array of AVQuantization parameters and its size + * To be used as AVFrameSideData + */ +typedef struct AVQuantizationParamsArray { + /** + * AVQuantizationParams block array + */ + AVQuantizationParams *qp_arr; + /** + * size of the array + */ + int nb_blocks; +} AVQuantizationParamsArray; + +/** + * Enums for different codecs to store qp in the type array + * Each enum must have an array of strings describing each field + * used for output + */ +extern const char* const QP_ENUM_NAMES_H264[]; +enum QP_ARR_INDEXES_FOR_H264 { + QP_H264 = 0, // qp value + QP_TYPE_ARR_SIZE_H264 // used for allocating memory +}; + +extern const char* const QP_NAMES_VP9[]; +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 +}; + +extern const char* const QP_NAMES_AV1[]; +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 */