From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 33D5C42F0F for ; Mon, 13 Jun 2022 03:37:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 736BA68B4B8; Mon, 13 Jun 2022 06:36:56 +0300 (EEST) Received: from out203-205-251-80.mail.qq.com (out203-205-251-80.mail.qq.com [203.205.251.80]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1BF3868B579 for ; Mon, 13 Jun 2022 06:36:48 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1655091402; bh=F8PjvcI0QOLu6X/SWF3aGMdRwQ6oWvEigaKftrDeB0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TqRaenWGAmyXmokbO5gN5TOKh9mP6DoMDYp+iP2e49w8wcdnQh1RMtV5SoXV8FdWb 6oWCSQyObiM1+pwhACpBC2PxAAyC5zD0YhEr5fez5vccUaLUqUuAm1riCujtg6b1Ms UBZ+xUP6fCsCSQMEpQ+KinmrsvsfmWphUTJde1hs= Received: from ZHILIZHAO-MB2.tencent.com ([59.37.125.124]) by newxmesmtplogicsvrszb6.qq.com (NewEsmtp) with SMTP id 926352F6; Mon, 13 Jun 2022 11:36:38 +0800 X-QQ-mid: xmsmtpt1655091401tu752p7ke Message-ID: X-QQ-XMAILINFO: NMGzQWUSIfvTb/ByxnjqNlgP/LyKaOr/uRIwqXg/KJQ8wd5aF0SHOw7ctuB0g3 I0WklmmaFKjYfmu8B98NkRqtqh5XD8Xa1Sm09dGc8OHN3nsKuZw1oKS4xRE1WU3QEn2HyMARetdP PiOib3krJAd/gVHCyYThEPP8fgW1Lct7cnSsGfGvRXNCnUp8rbIZnnZTOL5a86mgNG/6hGsk0/GF /Lxdr5lPzsxhyLHH5wxmn42znExdQj2gfk90ye6Z/sleoxcJza8McFtzkcnCtk/hw5AcaQ6EWJy1 PSlAmPCPAi5iMyzzgYExyj2AEzpZx5m4Mrm1cPXyvavhCXoyXvyJKcpZhGZ/J/BASUDaqahEK7yK R/ncMuGGmyv9dRGmN7NnvH9JLhZ6ENdm6zI8JLpiWjDYDi1cgwC+CLVzyKCpSv5GRh8iR2d1qYGs JFjsrZkHQk8E7pZiqQf+syD4tCx5FmmlVQekVxGHaZIM+oveQCWMfMbL6SGzyndeaPf/doKfwVCX o3Jbq7hyY6qQBZXTx9U0Q98lguvn4RiBq/hrdNwzkZB3Ix8gHQ2nIGmjwFnKd4iwsrhkpwpcWw6s Gz0Hj9ox5v5zEWtnulTsUD5SHavzN42U+z/pdlsRxxnzPIyswGN1h3P5kNLOVvT4qqG7GNqEvtZ6 ZDETpLXuGfDAE1XM8SbpHjPkN1VPYOoYAXywKfz0ocL/ofsFgPd36uEDK/Wqu/08GQrsNv5MLk6U c7B06srbnzmo8Z2wmEUHA1W1+YdagHKiYBZGjjbzXoTBA7upRTcVBV1WZkRnJRUJK6ZBzZsofxb5 cofJRQzg6/xyvAGMDY8Mn0/CHNTsHgFzs2w7xGZF0Wzzj4dUG1e0K58yEugvs9n2GPBEvup/fnP7 /HGH2WJu13flZouhkIuEQ2YuZjjB9hefC3CcWOqV2Twu+mLOkgwj+3k2QKAfvpzOaQT5r/9HaFDG ZQ8yfIatI= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Jun 2022 11:36:34 +0800 X-OQ-MSGID: <20220613033636.84271-4-quinkblack@foxmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220613033636.84271-1-quinkblack@foxmail.com> References: <20220613033636.84271-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Zhao Zhili , Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Including video resolution, framerate and picture type, etc. Signed-off-by: Zhao Zhili --- libavcodec/Makefile | 2 +- libavcodec/avs2.c | 42 ++++++++++++++++ libavcodec/avs2.h | 10 ++++ libavcodec/avs2_parser.c | 105 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 libavcodec/avs2.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3b8f7b5e01..6cc6f8437c 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1114,7 +1114,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \ OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o -OBJS-$(CONFIG_AVS2_PARSER) += avs2_parser.o +OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs_parser.o diff --git a/libavcodec/avs2.c b/libavcodec/avs2.c new file mode 100644 index 0000000000..ead8687d0a --- /dev/null +++ b/libavcodec/avs2.c @@ -0,0 +1,42 @@ +/* + * AVS2 related definitions + * + * Copyright (C) 2022 Zhao Zhili, + * + * 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 "avs2.h" + +const AVRational ff_avs2_frame_rate_tab[16] = { + { 0 , 0 }, // forbid + { 24000, 1001}, + { 24 , 1 }, + { 25 , 1 }, + { 30000, 1001}, + { 30 , 1 }, + { 50 , 1 }, + { 60000, 1001}, + { 60 , 1 }, + { 100 , 1 }, + { 120 , 1 }, + { 200 , 1 }, + { 240 , 1 }, + { 300 , 1 }, + { 0 , 0 }, // reserved + { 0 , 0 } // reserved +}; diff --git a/libavcodec/avs2.h b/libavcodec/avs2.h index f342ba52a0..544cf502d7 100644 --- a/libavcodec/avs2.h +++ b/libavcodec/avs2.h @@ -23,6 +23,8 @@ #ifndef AVCODEC_AVS2_H #define AVCODEC_AVS2_H +#include "libavutil/rational.h" + #define AVS2_SLICE_MAX_START_CODE 0x000001AF enum { @@ -38,4 +40,12 @@ enum { #define AVS2_ISPIC(x) ((x) == AVS2_INTRA_PIC_START_CODE || (x) == AVS2_INTER_PIC_START_CODE) #define AVS2_ISUNIT(x) ((x) == AVS2_SEQ_START_CODE || AVS2_ISPIC(x)) +enum AVS2Profile { + AVS2_PROFILE_MAIN_PIC = 0x12, + AVS2_PROFILE_MAIN = 0x20, + AVS2_PROFILE_MAIN10 = 0x22, +}; + +extern const AVRational ff_avs2_frame_rate_tab[16]; + #endif diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c index 71cf442903..0350517493 100644 --- a/libavcodec/avs2_parser.c +++ b/libavcodec/avs2_parser.c @@ -19,7 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avutil.h" #include "avs2.h" +#include "get_bits.h" #include "parser.h" static int avs2_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) @@ -58,6 +60,107 @@ static int avs2_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_siz return END_NOT_FOUND; } +static void parse_avs2_seq_header(AVCodecParserContext *s, const uint8_t *buf, + int buf_size, AVCodecContext *avctx) +{ + GetBitContext gb; + int profile, level; + int width, height; + int chroma, sample_precision, encoding_precision = 1; + // sample_precision and encoding_precision is 3 bits + static const uint8_t precision[8] = { 0, 8, 10 }; + unsigned aspect_ratio; + unsigned frame_rate_code; + int low_delay; + // update buf_size_min if parse more deeper + const int buf_size_min = 15; + + if (buf_size < buf_size_min) + return; + + init_get_bits8(&gb, buf, buf_size_min); + + s->key_frame = 1; + s->pict_type = AV_PICTURE_TYPE_I; + + profile = get_bits(&gb, 8); + level = get_bits(&gb, 8); + + // progressive_sequence u(1) + // field_coded_sequence u(1) + skip_bits(&gb, 2); + + width = get_bits(&gb, 14); + height = get_bits(&gb, 14); + + chroma = get_bits(&gb, 2); + sample_precision = get_bits(&gb, 3); + if (profile == AVS2_PROFILE_MAIN10) + encoding_precision = get_bits(&gb, 3); + + aspect_ratio = get_bits(&gb, 4); + frame_rate_code = get_bits(&gb, 4); + + // bit_rate_lower u(18) + // marker_bit f(1) + // bit_rate_upper u(12) + skip_bits(&gb, 31); + + low_delay = get_bits(&gb, 1); + + s->width = width; + s->height = height; + s->coded_width = FFALIGN(width, 8); + s->coded_height = FFALIGN(height, 8); + avctx->framerate.num = avctx->time_base.den = + ff_avs2_frame_rate_tab[frame_rate_code].num; + avctx->framerate.den = avctx->time_base.num = + ff_avs2_frame_rate_tab[frame_rate_code].den; + avctx->has_b_frames = FFMAX(avctx->has_b_frames, !low_delay); + + av_log(avctx, AV_LOG_DEBUG, + "AVS2 parse seq HDR: profile %x, level %x, " + "width %d, height %d, " + "chroma %d, sample_precision %d bits, encoding_precision %d bits, " + "aspect_ratio 0x%x, framerate %d/%d, low_delay %d\n", + profile, level, + width, height, + chroma, precision[sample_precision], precision[encoding_precision], + aspect_ratio, avctx->framerate.num, avctx->framerate.den, low_delay); +} + +static void parse_avs2_units(AVCodecParserContext *s, const uint8_t *buf, + int buf_size, AVCodecContext *avctx) +{ + if (buf_size < 5) + return; + + if (!(buf[0] == 0x0 && buf[1] == 0x0 && buf[2] == 0x1)) + return; + + switch (buf[3]) { + case AVS2_SEQ_START_CODE: + parse_avs2_seq_header(s, buf + 4, buf_size - 4, avctx); + return; + case AVS2_INTRA_PIC_START_CODE: + s->key_frame = 1; + s->pict_type = AV_PICTURE_TYPE_I; + return; + case AVS2_INTER_PIC_START_CODE: + s->key_frame = 0; + if (buf_size > 9) { + int pic_code_type = buf[8] & 0x3; + if (pic_code_type == 1) + s->pict_type = AV_PICTURE_TYPE_P; + else if (pic_code_type == 3) + s->pict_type = AV_PICTURE_TYPE_S; + else + s->pict_type = AV_PICTURE_TYPE_B; + } + return; + } +} + static int avs2_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) @@ -76,6 +179,8 @@ static int avs2_parse(AVCodecParserContext *s, AVCodecContext *avctx, } } + parse_avs2_units(s, buf, buf_size, avctx); + *poutbuf = buf; *poutbuf_size = buf_size; -- 2.35.3 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".