* [FFmpeg-devel] [PATCH 2/3] avcodec/avs2_parser: split data into frames
[not found] <20220610135021.89892-1-quinkblack@foxmail.com>
@ 2022-06-10 13:50 ` Zhao Zhili
2022-06-10 13:50 ` [FFmpeg-devel] [PATCH 3/3] avcodec/avs2_parser: parse more info Zhao Zhili
1 sibling, 0 replies; 5+ messages in thread
From: Zhao Zhili @ 2022-06-10 13:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili, Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
Before the patch, the parser split data into units, not frames.
Signed-off-by: Zhao Zhili <quinkblack@foxmail.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] 5+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] avcodec/avs2_parser: parse more info
[not found] <20220610135021.89892-1-quinkblack@foxmail.com>
2022-06-10 13:50 ` [FFmpeg-devel] [PATCH 2/3] avcodec/avs2_parser: split data into frames Zhao Zhili
@ 2022-06-10 13:50 ` Zhao Zhili
2022-06-12 16:42 ` [FFmpeg-devel] [PATCH v2 " Zhao Zhili
1 sibling, 1 reply; 5+ messages in thread
From: Zhao Zhili @ 2022-06-10 13:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
Including video resolution, framerate and picture type, etc.
Signed-off-by: Zhao Zhili <quinkblack@foxmail.com>
---
libavcodec/avs2.h | 27 ++++++++++
libavcodec/avs2_parser.c | 103 +++++++++++++++++++++++++++++++++++++++
2 files changed, 130 insertions(+)
diff --git a/libavcodec/avs2.h b/libavcodec/avs2.h
index f342ba52a0..e961c7d517 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,29 @@ 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,
+};
+
+static 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
+};
+
#endif
diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c
index 71cf442903..0638a35030 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,105 @@ 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 uint8_t precision[8] = { 0, 8, 10 };
+ int aspect_ratio;
+ int frame_rate_code;
+ int low_delay;
+
+ if (buf_size < 15)
+ return;
+
+ init_get_bits8(&gb, buf, buf_size);
+
+ 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, "
+ "framerate %d/%d, low_delay %d\n",
+ profile, level,
+ width, height,
+ chroma, precision[sample_precision], precision[encoding_precision],
+ 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 +177,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] 5+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/3] avcodec/avs2_parser: parse more info
2022-06-10 13:50 ` [FFmpeg-devel] [PATCH 3/3] avcodec/avs2_parser: parse more info Zhao Zhili
@ 2022-06-12 16:42 ` Zhao Zhili
2022-06-12 17:07 ` Andreas Rheinhardt
0 siblings, 1 reply; 5+ messages in thread
From: Zhao Zhili @ 2022-06-12 16:42 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
Including video resolution, framerate and picture type, etc.
Signed-off-by: Zhao Zhili <quinkblack@foxmail.com>
---
v2: fix unused variable warning
libavcodec/avs2.h | 27 ++++++++++
libavcodec/avs2_parser.c | 103 +++++++++++++++++++++++++++++++++++++++
2 files changed, 130 insertions(+)
diff --git a/libavcodec/avs2.h b/libavcodec/avs2.h
index f342ba52a0..e961c7d517 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,29 @@ 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,
+};
+
+static 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
+};
+
#endif
diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c
index 71cf442903..18d7729768 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,105 @@ 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 uint8_t precision[8] = { 0, 8, 10 };
+ unsigned aspect_ratio;
+ unsigned frame_rate_code;
+ int low_delay;
+
+ if (buf_size < 15)
+ return;
+
+ init_get_bits8(&gb, buf, buf_size);
+
+ 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 +177,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] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 3/3] avcodec/avs2_parser: parse more info
2022-06-12 16:42 ` [FFmpeg-devel] [PATCH v2 " Zhao Zhili
@ 2022-06-12 17:07 ` Andreas Rheinhardt
2022-06-13 3:42 ` "zhilizhao(赵志立)"
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Rheinhardt @ 2022-06-12 17:07 UTC (permalink / raw)
To: ffmpeg-devel
Zhao Zhili:
> Including video resolution, framerate and picture type, etc.
>
> Signed-off-by: Zhao Zhili <quinkblack@foxmail.com>
> ---
> v2: fix unused variable warning
>
> libavcodec/avs2.h | 27 ++++++++++
> libavcodec/avs2_parser.c | 103 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 130 insertions(+)
>
> diff --git a/libavcodec/avs2.h b/libavcodec/avs2.h
> index f342ba52a0..e961c7d517 100644
> --- a/libavcodec/avs2.h
> +++ b/libavcodec/avs2.h
> @@ -23,6 +23,8 @@
> #ifndef AVCODEC_AVS2_H
> #define AVCODEC_AVS2_Hto
>
> +#include "libavutil/rational.h"
> +
> #define AVS2_SLICE_MAX_START_CODE 0x000001AF
>
> enum {
> @@ -38,4 +40,29 @@ 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,
> +};
> +
> +static const AVRational ff_avs2_frame_rate_tab[16] = {
If this is only used at one place (as it is), it should be moved to that
place; if it is to be used in several places, it should be moved to a
single file instead of a header.
> + { 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
> +};
> +
> #endif
> diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c
> index 71cf442903..18d7729768 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,105 @@ 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 uint8_t precision[8] = { 0, 8, 10 };
Missing const.
> + unsigned aspect_ratio;
> + unsigned frame_rate_code;
> + int low_delay;
> +
> + if (buf_size < 15)
> + return;
> +
> + init_get_bits8(&gb, buf, buf_size);
If buf_size is gigantic, init_get_bits8 can fail. Given that you only
ever read the first 15 bytes of the header, you can avoid this by
initializing the GetBitContext with a size of 15.
> +
> + 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 +177,8 @@ static int avs2_parse(AVCodecParserContext *s, AVCodecContext *avctx,
> }
> }
>
> + parse_avs2_units(s, buf, buf_size, avctx);
> +
> *poutbuf = buf;
> *poutbuf_size = buf_size;
>
_______________________________________________
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] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 3/3] avcodec/avs2_parser: parse more info
2022-06-12 17:07 ` Andreas Rheinhardt
@ 2022-06-13 3:42 ` "zhilizhao(赵志立)"
0 siblings, 0 replies; 5+ messages in thread
From: "zhilizhao(赵志立)" @ 2022-06-13 3:42 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> On Jun 13, 2022, at 1:07 AM, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
>
> Zhao Zhili:
>> Including video resolution, framerate and picture type, etc.
>>
>> Signed-off-by: Zhao Zhili <quinkblack@foxmail.com>
>> ---
>> v2: fix unused variable warning
>>
>> libavcodec/avs2.h | 27 ++++++++++
>> libavcodec/avs2_parser.c | 103 +++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 130 insertions(+)
>>
>> diff --git a/libavcodec/avs2.h b/libavcodec/avs2.h
>> index f342ba52a0..e961c7d517 100644
>> --- a/libavcodec/avs2.h
>> +++ b/libavcodec/avs2.h
>> @@ -23,6 +23,8 @@
>> #ifndef AVCODEC_AVS2_H
>> #define AVCODEC_AVS2_Hto
>>
>> +#include "libavutil/rational.h"
>> +
>> #define AVS2_SLICE_MAX_START_CODE 0x000001AF
>>
>> enum {
>> @@ -38,4 +40,29 @@ 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,
>> +};
>> +
>> +static const AVRational ff_avs2_frame_rate_tab[16] = {
>
> If this is only used at one place (as it is), it should be moved to that
> place; if it is to be used in several places, it should be moved to a
> single file instead of a header.
Thanks for the review, fixed by v3:
1. Move ff_avs2_frame_rate_tab from avs2.h to avs2.c
2. Consitify `precision` in patch 3/5
3. init_get_bits8() with size limites to buf_size_min
4. Select avs2_parser for libdavs2
5. Use ff_avs2_frame_rate_tab in libdavs2
http://ffmpeg.org/pipermail/ffmpeg-devel/2022-June/297476.html
>
>> + { 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
>> +};
>> +
>> #endif
>> diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c
>> index 71cf442903..18d7729768 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,105 @@ 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 uint8_t precision[8] = { 0, 8, 10 };
>
> Missing const.
>
>> + unsigned aspect_ratio;
>> + unsigned frame_rate_code;
>> + int low_delay;
>> +
>> + if (buf_size < 15)
>> + return;
>> +
>> + init_get_bits8(&gb, buf, buf_size);
>
> If buf_size is gigantic, init_get_bits8 can fail. Given that you only
> ever read the first 15 bytes of the header, you can avoid this by
> initializing the GetBitContext with a size of 15.
>
>> +
>> + 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 +177,8 @@ static int avs2_parse(AVCodecParserContext *s, AVCodecContext *avctx,
>> }
>> }
>>
>> + parse_avs2_units(s, buf, buf_size, avctx);
>> +
>> *poutbuf = buf;
>> *poutbuf_size = buf_size;
>>
>
> _______________________________________________
> 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] 5+ messages in thread
end of thread, other threads:[~2022-06-13 3:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20220610135021.89892-1-quinkblack@foxmail.com>
2022-06-10 13:50 ` [FFmpeg-devel] [PATCH 2/3] avcodec/avs2_parser: split data into frames Zhao Zhili
2022-06-10 13:50 ` [FFmpeg-devel] [PATCH 3/3] avcodec/avs2_parser: parse more info Zhao Zhili
2022-06-12 16:42 ` [FFmpeg-devel] [PATCH v2 " Zhao Zhili
2022-06-12 17:07 ` Andreas Rheinhardt
2022-06-13 3:42 ` "zhilizhao(赵志立)"
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