33 #define MIN_VVCC_LENGTH 23
43 int length_size, num_arrays,
i, j;
48 uint8_t *new_extradata =
NULL;
49 size_t new_extradata_size = 0;
51 int max_picture_width = 0;
52 int max_picture_height = 0;
53 int avg_frame_rate = 0;
56 temp = bytestream2_get_byte(&gb);
57 length_size = ((
temp & 6) >> 1) + 1;
58 ptl_present =
temp & 1;
60 int num_bytes_constraint_info;
61 int general_profile_idc;
62 int general_tier_flag;
63 int general_level_idc;
64 int ptl_frame_only_constraint_flag;
65 int ptl_multi_layer_enabled_flag;
66 int ptl_num_sub_profiles;
67 int temp3, temp4, temp5;
68 int temp2 = bytestream2_get_be16(&gb);
69 int ols_idx = (temp2 >> 7) & 0x1ff;
70 int num_sublayers = (temp2 >> 4) & 0x7;
71 int constant_frame_rate = (temp2 >> 2) & 0x3;
72 int chroma_format_idc = temp2 & 0x3;
73 int bit_depth_minus8 = (bytestream2_get_byte(&gb) >> 5) & 0x7;
75 "bit_depth_minus8 %d chroma_format_idc %d\n", bit_depth_minus8,
78 constant_frame_rate, ols_idx);
80 temp3 = bytestream2_get_byte(&gb);
81 num_bytes_constraint_info = (temp3) & 0x3f;
82 temp4 = bytestream2_get_byte(&gb);
83 general_profile_idc = (temp4 >> 1) & 0x7f;
84 general_tier_flag = (temp4) & 1;
85 general_level_idc = bytestream2_get_byte(&gb);
87 "general_profile_idc %d, general_tier_flag %d, general_level_idc %d, num_sublayers %d num_bytes_constraint_info %d\n",
88 general_profile_idc, general_tier_flag, general_level_idc,
89 num_sublayers, num_bytes_constraint_info);
91 temp5 = bytestream2_get_byte(&gb);
92 ptl_frame_only_constraint_flag = (temp5 >> 7) & 0x1;
93 ptl_multi_layer_enabled_flag = (temp5 >> 6) & 0x1;
94 for (
i = 0;
i < num_bytes_constraint_info - 1;
i++) {
96 bytestream2_get_byte(&gb);
100 "ptl_multi_layer_enabled_flag %d, ptl_frame_only_constraint_flag %d\n",
101 ptl_multi_layer_enabled_flag, ptl_frame_only_constraint_flag);
103 if (num_sublayers > 1) {
104 int temp6 = bytestream2_get_byte(&gb);
105 uint8_t ptl_sublayer_level_present_flag[8] = { 0 };
107 for (
i = num_sublayers - 2;
i >= 0;
i--) {
108 ptl_sublayer_level_present_flag[
i] =
109 (temp6 >> (7 - (num_sublayers - 2 -
i))) & 0x01;
113 for (
i = num_sublayers - 2;
i >= 0;
i--) {
114 if (ptl_sublayer_level_present_flag[
i]) {
120 ptl_num_sub_profiles = bytestream2_get_byte(&gb);
121 for (j = 0; j < ptl_num_sub_profiles; j++) {
123 bytestream2_get_be16(&gb);
124 bytestream2_get_be16(&gb);
127 max_picture_width = bytestream2_get_be16(&gb);
128 max_picture_height = bytestream2_get_be16(&gb);
129 avg_frame_rate = bytestream2_get_be16(&gb);
131 "max_picture_width %d, max_picture_height %d, avg_frame_rate %d\n",
132 max_picture_width, max_picture_height, avg_frame_rate);
135 num_arrays = bytestream2_get_byte(&gb);
137 for (
i = 0;
i < num_arrays;
i++) {
139 int type = bytestream2_get_byte(&gb) & 0x1f;
144 cnt = bytestream2_get_be16(&gb);
152 "Invalid NAL unit type in extradata: %d\n",
type);
157 for (j = 0; j < cnt; j++) {
158 const int nalu_len = bytestream2_get_be16(&gb);
166 ret =
av_reallocp(&new_extradata, new_extradata_size + nalu_len + 4
171 AV_WB32(new_extradata + new_extradata_size, 1);
174 new_extradata_size += 4 + nalu_len;
175 memset(new_extradata + new_extradata_size, 0,
181 ctx->par_out->extradata = new_extradata;
182 ctx->par_out->extradata_size = new_extradata_size;
184 if (!new_extradata_size)
202 "The input looks like it is Annex B already\n");
207 s->length_size =
ret;
208 s->extradata_parsed = 1;
228 if (!
s->extradata_parsed) {
238 uint32_t nalu_size = 0;
246 for (
i = 0;
i <
s->length_size;
i++)
247 nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb);
254 nalu_type = (bytestream2_peek_be16(&gb) >> 3) & 0x1f;
264 uint32_t nalu_size = 0;
266 int add_extradata, extra_size, prev_size;
273 for (
i = 0;
i <
s->length_size;
i++)
274 nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb);
281 nalu_type = (bytestream2_peek_be16(&gb) >> 3) & 0x1f;
284 add_extradata = is_irap && nalu_type !=
VVC_AUD_NUT && !added_extra;
285 extra_size = add_extradata *
ctx->par_out->extradata_size;
286 added_extra |= add_extradata;
288 if (
FFMIN(INT_MAX, SIZE_MAX) < 4ULL + nalu_size + extra_size) {
293 prev_size =
out->size;
300 memcpy(
out->data + prev_size,
ctx->par_out->extradata, extra_size);
301 AV_WB32(
out->data + prev_size + extra_size, 1);
323 .
p.
name =
"vvc_mp4toannexb",