* [FFmpeg-devel] [PATCH v3 1/5] avcodec/avs2: add AVS2 related definitions [not found] <20220613033636.84271-1-quinkblack@foxmail.com> @ 2022-06-13 3:36 ` Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 2/5] avcodec/avs2_parser: split data into frames Zhao Zhili ` (3 subsequent siblings) 4 siblings, 0 replies; 9+ messages in thread From: Zhao Zhili @ 2022-06-13 3:36 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili, Zhao Zhili Replace magic numbers by enum values. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavcodec/avs2.h | 41 ++++++++++++++++++++++++++++++++++++++++ libavcodec/avs2_parser.c | 6 +----- 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 libavcodec/avs2.h diff --git a/libavcodec/avs2.h b/libavcodec/avs2.h new file mode 100644 index 0000000000..7b66f51998 --- /dev/null +++ b/libavcodec/avs2.h @@ -0,0 +1,41 @@ +/* + * AVS2 related definitions + * + * Copyright (C) 2022 Zhao Zhili, <zhilizhao@tencent.com> + * + * 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 AVCODEC_AVS2_H +#define AVCODEC_AVS2_H + +#define AVS2_SLICE_MAX_START_CODE 0x000001AF + +enum { + AVS2_SEQ_START_CODE = 0xB0, + AVS2_SEQ_END_CODE = 0xB1, + AVS2_USER_DATA_START_CODE = 0xB2, + AVS2_INTRA_PIC_START_CODE = 0xB3, + // reserved = 0xB4, + AVS2_EXTENSION_START_CODE = 0xB5, + AVS2_INTER_PIC_START_CODE = 0xB6, +}; + +#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 || (x) == AVS2_SEQ_END_CODE || (x) == AVS2_USER_DATA_START_CODE || AVS2_ISPIC(x)) + +#endif diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c index b7d5d7774e..3755dbd78c 100644 --- a/libavcodec/avs2_parser.c +++ b/libavcodec/avs2_parser.c @@ -19,13 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "avs2.h" #include "parser.h" -#define AVS2_SLICE_MAX_START_CODE 0x000001AF - -#define AVS2_ISPIC(x) ((x) == 0xB3 || (x) == 0xB6) -#define AVS2_ISUNIT(x) ((x) == 0xB0 || (x) == 0xB1 || (x) == 0xB2 || AVS2_ISPIC(x)) - static int avs2_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) { int pic_found = pc->frame_start_found; -- 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH v3 2/5] avcodec/avs2_parser: split data into frames [not found] <20220613033636.84271-1-quinkblack@foxmail.com> 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 1/5] avcodec/avs2: add AVS2 related definitions Zhao Zhili @ 2022-06-13 3:36 ` Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info Zhao Zhili ` (2 subsequent siblings) 4 siblings, 0 replies; 9+ messages in thread From: Zhao Zhili @ 2022-06-13 3:36 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili, Zhao Zhili Before the patch, the parser split data into units, not frames. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavcodec/avs2.h | 2 +- libavcodec/avs2_parser.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/avs2.h b/libavcodec/avs2.h index 7b66f51998..f342ba52a0 100644 --- a/libavcodec/avs2.h +++ b/libavcodec/avs2.h @@ -36,6 +36,6 @@ 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 || (x) == AVS2_SEQ_END_CODE || (x) == AVS2_USER_DATA_START_CODE || AVS2_ISPIC(x)) +#define AVS2_ISUNIT(x) ((x) == AVS2_SEQ_START_CODE || AVS2_ISPIC(x)) #endif diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c index 3755dbd78c..71cf442903 100644 --- a/libavcodec/avs2_parser.c +++ b/libavcodec/avs2_parser.c @@ -31,7 +31,7 @@ static int avs2_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_siz if (!pic_found) { for (; cur < buf_size; ++cur) { state = (state << 8) | buf[cur]; - if (AVS2_ISUNIT(buf[cur])){ + if ((state & 0xFFFFFF00) == 0x100 && AVS2_ISPIC(buf[cur])) { cur++; pic_found = 1; break; @@ -44,7 +44,7 @@ static int avs2_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_siz return END_NOT_FOUND; for (; cur < buf_size; cur++) { state = (state << 8) | buf[cur]; - if ((state & 0xFFFFFF00) == 0x100 && state > AVS2_SLICE_MAX_START_CODE) { + if ((state & 0xFFFFFF00) == 0x100 && AVS2_ISUNIT(buf[cur])) { pc->frame_start_found = 0; pc->state = -1; return cur - 3; -- 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info [not found] <20220613033636.84271-1-quinkblack@foxmail.com> 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 1/5] avcodec/avs2: add AVS2 related definitions Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 2/5] avcodec/avs2_parser: split data into frames Zhao Zhili @ 2022-06-13 3:36 ` Zhao Zhili 2022-06-21 2:45 ` hwren 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 4/5] configure: select avs2 parser for libdavs2 decoder Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 5/5] avcodec/libdavs2: use frame rate code table Zhao Zhili 4 siblings, 1 reply; 9+ messages in thread From: Zhao Zhili @ 2022-06-13 3:36 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili, Zhao Zhili Including video resolution, framerate and picture type, etc. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- 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, <zhilizhao@tencent.com> + * + * 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info Zhao Zhili @ 2022-06-21 2:45 ` hwren 2022-06-21 8:25 ` "zhilizhao(赵志立)" 0 siblings, 1 reply; 9+ messages in thread From: hwren @ 2022-06-21 2:45 UTC (permalink / raw) To: FFmpeg development discussions and patches At 2022-06-13 11:36:34, "Zhao Zhili" <quinkblack@foxmail.com> wrote: >Including video resolution, framerate and picture type, etc. > >Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> >--- > 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, <zhilizhao@tencent.com> >+ * >+ * 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 >+}; That table seems to appear only in avs2 decoder. If so, they are supposed to be declared in libdavs2.c. If not, please point out the usage of this separate source file. Persionally, the frame_rate table can be used in both encoder and decoder. So it is what should be defined in the avs2.h (with related enc/dec changes). >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)) > Same as above. Mentioned definitions now are only used in avs2_parser.c. If so, they are supposed to be kept in avs2_parser.c. >+enum AVS2Profile { >+ AVS2_PROFILE_MAIN_PIC = 0x12, >+ AVS2_PROFILE_MAIN = 0x20, >+ AVS2_PROFILE_MAIN10 = 0x22, >+}; Not mentioned elsewhere. If they are to work in the encoder/decoder, please package them with related changes. >+ >+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 Best Regards, Huiwen Ren > >_______________________________________________ >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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info 2022-06-21 2:45 ` hwren @ 2022-06-21 8:25 ` "zhilizhao(赵志立)" 2022-06-21 8:28 ` "zhilizhao(赵志立)" 0 siblings, 1 reply; 9+ messages in thread From: "zhilizhao(赵志立)" @ 2022-06-21 8:25 UTC (permalink / raw) To: FFmpeg development discussions and patches > On Jun 21, 2022, at 10:45 AM, hwren <hwrenx@126.com> wrote: > > At 2022-06-13 11:36:34, "Zhao Zhili" <quinkblack@foxmail.com> wrote: >> Including video resolution, framerate and picture type, etc. >> >> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> >> --- >> 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, <zhilizhao@tencent.com> >> + * >> + * 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 >> +}; > > That table seems to appear only in avs2 decoder. If so, they are supposed to be declared in libdavs2.c. > If not, please point out the usage of this separate source file. It’s used in this patch, parse_avs2_seq_header(). > > Persionally, the frame_rate table can be used in both encoder and decoder. So it is what should be > defined in the avs2.h (with related enc/dec changes). It’s declared in avs2.h, so it can be used by enc/dec. It’s defined in .c to reduce binary size. > >> 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)) >> > > Same as above. Mentioned definitions now are only used in avs2_parser.c. If so, they are supposed to be > kept in avs2_parser.c. It’s not the same as ff_avs2_frame_rate_tab. Firstly, define enum and macros doesn’t generate binary. Secondly, they are be used by avs2 parser/decoder/encoder and so on, the same as avs3.h. They are only used by avs2 parser now, but they are handy when debug decoder, for example, and future proof. > > >> +enum AVS2Profile { >> + AVS2_PROFILE_MAIN_PIC = 0x12, >> + AVS2_PROFILE_MAIN = 0x20, >> + AVS2_PROFILE_MAIN10 = 0x22, >> +}; > > Not mentioned elsewhere. If they are to work in the encoder/decoder, please package them with related changes. AVS2_PROFILE_MAIN10 is used in this patch. > >> + >> +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 > > > Best Regards, > Huiwen Ren > >> >> _______________________________________________ >> 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". > > > _______________________________________________ > 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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info 2022-06-21 8:25 ` "zhilizhao(赵志立)" @ 2022-06-21 8:28 ` "zhilizhao(赵志立)" 2022-06-21 8:57 ` hwren 0 siblings, 1 reply; 9+ messages in thread From: "zhilizhao(赵志立)" @ 2022-06-21 8:28 UTC (permalink / raw) To: FFmpeg development discussions and patches > On Jun 21, 2022, at 4:25 PM, zhilizhao(赵志立) <quinkblack@foxmail.com> wrote: > >> On Jun 21, 2022, at 10:45 AM, hwren <hwrenx@126.com> wrote: >> >> At 2022-06-13 11:36:34, "Zhao Zhili" <quinkblack@foxmail.com> wrote: >>> Including video resolution, framerate and picture type, etc. >>> >>> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> >>> --- >>> 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, <zhilizhao@tencent.com> >>> + * >>> + * 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 >>> +}; >> >> That table seems to appear only in avs2 decoder. If so, they are supposed to be declared in libdavs2.c. >> If not, please point out the usage of this separate source file. > > It’s used in this patch, parse_avs2_seq_header(). > >> >> Persionally, the frame_rate table can be used in both encoder and decoder. So it is what should be >> defined in the avs2.h (with related enc/dec changes). > > It’s declared in avs2.h, so it can be used by enc/dec. > It’s defined in .c to reduce binary size. > >> >>> 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)) >>> >> >> Same as above. Mentioned definitions now are only used in avs2_parser.c. If so, they are supposed to be >> kept in avs2_parser.c. > > It’s not the same as ff_avs2_frame_rate_tab. Firstly, define enum > and macros doesn’t generate binary. Secondly, they are be used > by avs2 parser/decoder/encoder and so on, the same as avs3.h. I mean they ‘can’ be used by avs2 parser/decoder/encoder. > > They are only used by avs2 parser now, but they are handy when debug > decoder, for example, and future proof. > >> >> >>> +enum AVS2Profile { >>> + AVS2_PROFILE_MAIN_PIC = 0x12, >>> + AVS2_PROFILE_MAIN = 0x20, >>> + AVS2_PROFILE_MAIN10 = 0x22, >>> +}; >> >> Not mentioned elsewhere. If they are to work in the encoder/decoder, please package them with related changes. > > AVS2_PROFILE_MAIN10 is used in this patch. > >> >>> + >>> +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 >> >> >> Best Regards, >> Huiwen Ren >> >>> >>> _______________________________________________ >>> 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". >> >> >> _______________________________________________ >> 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". > >> On Jun 21, 2022, at 10:45 AM, hwren <hwrenx@126.com> wrote: >> >> At 2022-06-13 11:36:34, "Zhao Zhili" <quinkblack@foxmail.com> wrote: >>> Including video resolution, framerate and picture type, etc. >>> >>> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> >>> --- >>> 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, <zhilizhao@tencent.com> >>> + * >>> + * 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 >>> +}; >> >> That table seems to appear only in avs2 decoder. If so, they are supposed to be declared in libdavs2.c. >> If not, please point out the usage of this separate source file. > > It’s used in this patch, parse_avs2_seq_header(). > >> >> Persionally, the frame_rate table can be used in both encoder and decoder. So it is what should be >> defined in the avs2.h (with related enc/dec changes). > > It’s declared in avs2.h, so it can be used by enc/dec. > It’s defined in .c to reduce binary size. > >> >>> 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)) >>> >> >> Same as above. Mentioned definitions now are only used in avs2_parser.c. If so, they are supposed to be >> kept in avs2_parser.c. > > It’s not the same as ff_avs2_frame_rate_tab. Firstly, define enum > and macros doesn’t generate binary. Secondly, they are be used > by avs2 parser/decoder/encoder and so on, the same as avs3.h. > > They are only used by avs2 parser now, but they are handy when debug > decoder, for example, and future proof. > >> >> >>> +enum AVS2Profile { >>> + AVS2_PROFILE_MAIN_PIC = 0x12, >>> + AVS2_PROFILE_MAIN = 0x20, >>> + AVS2_PROFILE_MAIN10 = 0x22, >>> +}; >> >> Not mentioned elsewhere. If they are to work in the encoder/decoder, please package them with related changes. > > AVS2_PROFILE_MAIN10 is used in this patch. > >> >>> + >>> +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 >> >> >> Best Regards, >> Huiwen Ren >> >>> >>> _______________________________________________ >>> 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". >> >> >> _______________________________________________ >> 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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info 2022-06-21 8:28 ` "zhilizhao(赵志立)" @ 2022-06-21 8:57 ` hwren 0 siblings, 0 replies; 9+ messages in thread From: hwren @ 2022-06-21 8:57 UTC (permalink / raw) To: FFmpeg development discussions and patches 在 2022-06-21 16:28:37,"\"zhilizhao(赵志立)\"" <quinkblack@foxmail.com> 写道: > > >> On Jun 21, 2022, at 4:25 PM, zhilizhao(赵志立) <quinkblack@foxmail.com> wrote: >> >>> On Jun 21, 2022, at 10:45 AM, hwren <hwrenx@126.com> wrote: >>> >>> At 2022-06-13 11:36:34, "Zhao Zhili" <quinkblack@foxmail.com> wrote: >>>> Including video resolution, framerate and picture type, etc. >>>> >>>> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> >>>> --- >>>> 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, <zhilizhao@tencent.com> >>>> + * >>>> + * 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 >>>> +}; >>> >>> That table seems to appear only in avs2 decoder. If so, they are supposed to be declared in libdavs2.c. >>> If not, please point out the usage of this separate source file. >> >> It’s used in this patch, parse_avs2_seq_header(). LGTM if it is used in multiple files and need to be optimized to reduce binary size. >> >>> >>> Persionally, the frame_rate table can be used in both encoder and decoder. So it is what should be >>> defined in the avs2.h (with related enc/dec changes). >> >> It’s declared in avs2.h, so it can be used by enc/dec. >> It’s defined in .c to reduce binary size. >> >>> >>>> 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)) >>>> >>> >>> Same as above. Mentioned definitions now are only used in avs2_parser.c. If so, they are supposed to be >>> kept in avs2_parser.c. >> >> It’s not the same as ff_avs2_frame_rate_tab. Firstly, define enum >> and macros doesn’t generate binary. Secondly, they are be used >> by avs2 parser/decoder/encoder and so on, the same as avs3.h. > >I mean they ‘can’ be used by avs2 parser/decoder/encoder. LGTM > >> >> They are only used by avs2 parser now, but they are handy when debug >> decoder, for example, and future proof. >> >>> >>> >>>> +enum AVS2Profile { >>>> + AVS2_PROFILE_MAIN_PIC = 0x12, >>>> + AVS2_PROFILE_MAIN = 0x20, >>>> + AVS2_PROFILE_MAIN10 = 0x22, >>>> +}; >>> >>> Not mentioned elsewhere. If they are to work in the encoder/decoder, please package them with related changes. >> >> AVS2_PROFILE_MAIN10 is used in this patch. Got it. No more questions. >> >>> >>>> + >>>> +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 >>> >>> >>> Best Regards, >>> Huiwen Ren >>> >>>> >>>> _______________________________________________ >>>> 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". >>> >>> >>> _______________________________________________ >>> 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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH v3 4/5] configure: select avs2 parser for libdavs2 decoder [not found] <20220613033636.84271-1-quinkblack@foxmail.com> ` (2 preceding siblings ...) 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info Zhao Zhili @ 2022-06-13 3:36 ` Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 5/5] avcodec/libdavs2: use frame rate code table Zhao Zhili 4 siblings, 0 replies; 9+ messages in thread From: Zhao Zhili @ 2022-06-13 3:36 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili, Zhao Zhili Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- configure | 1 + 1 file changed, 1 insertion(+) diff --git a/configure b/configure index 3dca1c4bd3..3b60fde733 100755 --- a/configure +++ b/configure @@ -3324,6 +3324,7 @@ libcodec2_encoder_deps="libcodec2" libdav1d_decoder_deps="libdav1d" libdav1d_decoder_select="atsc_a53" libdavs2_decoder_deps="libdavs2" +libdavs2_decoder_select="avs2_parser" libfdk_aac_decoder_deps="libfdk_aac" libfdk_aac_encoder_deps="libfdk_aac" libfdk_aac_encoder_select="audio_frame_queue" -- 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH v3 5/5] avcodec/libdavs2: use frame rate code table [not found] <20220613033636.84271-1-quinkblack@foxmail.com> ` (3 preceding siblings ...) 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 4/5] configure: select avs2 parser for libdavs2 decoder Zhao Zhili @ 2022-06-13 3:36 ` Zhao Zhili 4 siblings, 0 replies; 9+ messages in thread From: Zhao Zhili @ 2022-06-13 3:36 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili, Zhao Zhili It's more natural than the floating to fraction conversion. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavcodec/libdavs2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c index bc31745a4f..d7625718a2 100644 --- a/libavcodec/libdavs2.c +++ b/libavcodec/libdavs2.c @@ -25,6 +25,7 @@ #include "libavutil/cpu.h" #include "avcodec.h" #include "codec_internal.h" +#include "avs2.h" #include "davs2.h" typedef struct DAVS2Context { @@ -85,7 +86,8 @@ static int davs2_dump_frames(AVCodecContext *avctx, davs2_picture_t *pic, int *g */ avctx->has_b_frames = FFMAX(avctx->has_b_frames, !headerset->low_delay); - avctx->framerate = av_d2q(headerset->frame_rate,4096); + if (headerset->frame_rate_id < 16) + avctx->framerate = ff_avs2_frame_rate_tab[headerset->frame_rate_id]; *got_frame = 0; return 0; } -- 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-06-21 8:57 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20220613033636.84271-1-quinkblack@foxmail.com> 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 1/5] avcodec/avs2: add AVS2 related definitions Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 2/5] avcodec/avs2_parser: split data into frames Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 3/5] avcodec/avs2_parser: parse more info Zhao Zhili 2022-06-21 2:45 ` hwren 2022-06-21 8:25 ` "zhilizhao(赵志立)" 2022-06-21 8:28 ` "zhilizhao(赵志立)" 2022-06-21 8:57 ` hwren 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 4/5] configure: select avs2 parser for libdavs2 decoder Zhao Zhili 2022-06-13 3:36 ` [FFmpeg-devel] [PATCH v3 5/5] avcodec/libdavs2: use frame rate code table Zhao Zhili
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git