系带割掉了有什么影响| hvi是什么病| 神经官能症挂什么科| 内风湿是什么原因引起的| 颢读什么| 向日葵代表什么象征意义| 指甲黑是什么原因| 来月经是黑色的是什么原因| 吃藕粉对身体有什么好处| 轻微骨裂了有什么表现| 四两拨千斤是什么意思| 什么情况下做冠脉ct| 经常嗓子疼是什么原因| 做宫腔镜检查需要提前做什么准备| ttm是什么意思| mn是什么单位| 6月20是什么星座| tid什么意思| 女生吃什么可以丰胸| 6月是什么生肖| 心脏彩超主要检查什么| 老鳖吃什么| 叫什么名字好听| 血栓有什么症状| 二甲双胍缓释片什么时候吃最好| 肚子胀气吃什么药| 什么油适合高温油炸| 左下腹痛挂什么科| 亚蒂息肉是什么意思| 鼻涕倒流吃什么药效果好| 书字五行属什么| 苹果6和苹果6S有什么区别| 婴儿大便隐血阳性是什么意思| 健康管理是做什么的| 拔火罐起水泡是什么原因| ais什么意思| 干事是什么意思| 洗衣机单漂洗是什么意思| 梦见雨伞是什么意思| 优五行属性是什么| 什么钓鱼愿者上钩| alan什么意思| 肾阴虚的症状吃什么药| 在编是什么意思| 女性尿酸高有什么症状表现| 什么情况| 淋巴结增大是什么原因严重吗| 频繁小便是什么原因| 自戕是什么意思| 情人的定义是什么| 足癣用什么药| 附件囊肿吃什么药可以消除| 吃饭是什么意思| 米非司酮片是什么药| 雄五行属什么| 闺房之乐是什么意思| 如获至宝是什么意思| 辰代表什么意思| 单核细胞百分比偏高说明什么| 三个土是什么字怎么读| 腹部左侧是什么器官| 怀孕初期需要注意些什么| pending是什么状态| 女为什么字| 海南属于什么气候| 莒姬是什么位分| 梦见吵架是什么预兆| 组织部长是什么级别| 11.11什么星座| 勾心斗角是什么生肖| 前列腺液是什么样子| 暗里着迷什么意思| 想吃辣的是什么原因| 中元节开什么生肖| 什么是翻墙软件| 肾结石都有什么症状| 为什么睡觉流口水很臭| 层次是什么意思| 胃疼吃什么食物最养胃| 沟壑什么意思| 亦金读什么| 皓什么意思| 发烧为什么会浑身酸疼| 吃什么能补头发| 小便白细胞高是什么原因| 刚产下的蚕卵是什么颜色| 紫苏长什么样子图片| 蟋蟀是靠什么发声的| 小孩耳朵痛什么原因| 鼻子流水是什么原因| 四月份是什么星座| 再创佳绩是什么意思| 点子是什么意思| 名什么什么实| 产后42天复查挂什么科| 梦见浇花是什么意思| 肩周炎吃什么药效果最好| 肝病看什么科室| o型血和b型血的孩子是什么血型| 什么时候大暑| 梦见一群羊是什么意思| vivian是什么意思| 欣慰的意思是什么| 受凉胃疼吃什么药| play是什么牌子| 于谦为什么加入国民党| 手掌横纹代表什么意思| 什么东西补气血效果最好| 头出汗是什么原因| 小孩血糖高是什么原因引起的| 入幕之宾是什么意思| 什么的香蕉| 湿疹用什么药好得最快最有效| 骨髓炎是什么病| 羊胡子疮用什么药膏| 什么是中产阶级| 双子座女和什么星座最配| 抽筋是缺什么| rca是什么意思| 腰酸胀是什么原因男性| 樱桃红是什么颜色| 国酒是什么酒| 头孢长什么样| 去医院看脚挂什么科| 铁扇公主是什么妖精| 脑梗会引起什么症状| 男人秒射是什么原因| 三位一体是什么意思| 肋骨骨折吃什么药| 伏案什么意思| 磨牙齿有什么方法可以治| 小人痣代表什么意思| 什么如既往| 为什么会得痔疮| 避孕套玻尿酸的作用是什么| 涟漪是什么意思| 鸡枞菌生长在什么地方| 教育基金是什么意思| 甘油是什么| 紫癜是一种什么病严重吗| 继发不孕什么意思| 神经痛吃什么药| mews评分是什么意思| 早搏吃什么药最管用| 莅临什么意思| 小腿肿是什么原因| 为什么十二生肖老鼠排第一| 杀马特什么意思| 银花指什么生肖| 一次不忠终身不用什么意思| 情何以堪是什么意思| 龙王庙是指什么生肖| 医院康复科是干什么的| 耵聍是什么意思| 摩羯男喜欢什么类型的女生| 猪蹄炖什么| 55岁属什么生肖| 女生生日送什么礼物好| 萎缩性胃炎用什么药最好| 许莫氏结节是什么意思| 五加一笔是什么字| 冲击波治疗有什么效果| rh血型阳性什么意思| 为什么左眼皮一直跳| 什么是滑脉| 红糖水什么时候喝最好| rbc红细胞偏高是什么意思| 灰棕色是什么颜色| 肚子大了是什么原因造成的| 尼龙是什么| 小孩补铁吃什么| 为什么一动就出汗| 支原体培养阳性是什么意思| 阴虚吃什么调理| 准备要孩子需要注意什么| 切忌什么意思| q12h医学上是什么意思| 开门是什么意思| 灌肠用什么| 纳豆什么味道| 甲硝唑治什么病| 什么是抹茶| 盆腔炎是什么病| 乐果是什么农药| 腹部b超能检查出什么| 手心发红是什么原因| 7.20是什么星座| 彩超挂什么科| 吃什么记忆力增强| 喜鹊进家有什么预兆| 兔死狐悲指什么生肖| 男人不尊重你说明什么| 生化全项包括什么| 打仗是什么意思| 鼻子突然流血是什么原因| 蝶变是什么意思| 吃燕窝有什么功效| 义举是什么意思| bpo是什么意思啊| 盛情难却是什么意思| 支原体吃什么药| 周围神经病是什么症状| 被蚂蚁咬了用什么药| 检查肺部最好做什么检查| 手上有红点是什么原因| golden是什么牌子| 喜大普奔什么意思| 卵巢早衰有什么症状| 土耳其浴是什么意思| 白玫瑰代表什么| 白砂糖和冰糖有什么区别| 砍是什么生肖| 什么欲滴| hdl是什么意思| 肌肉痛吃什么药| 胃食管反流吃什么中成药| 小孩手足口病吃什么食物好| 心悸是什么病| 铁锈是什么颜色的| 手指关节疼痛是什么原因| 霉菌性阴道炎有什么症状| 尿管型偏高是什么原因| 天花是什么病| 茴香豆是什么豆| 11月18号是什么星座| 射手女和什么星座最配| 身上长小红痣是什么原因| 哺乳期胃疼可以吃什么药| 饭后打嗝是什么原因| 霍金是什么病| 肺在什么位置图片| hl是什么意思| 鼻孔干燥是什么原因| 日晡是什么意思| 乳腺腺体是什么| 2月5号什么星座| 一什么椅子| 橄榄枝象征着什么| 神经内科主要看什么病| 圣罗兰为什么叫杨树林| 胃看什么科室| cancer是什么意思| cov是什么意思| pvr是什么意思| 为什么会被限制高消费| yxh是什么意思| 三七是什么意思| 头三个月保胎喝什么汤| 月出念什么| 冷冻是什么意思| 身上有白点是什么原因| 臆想症是什么| 扁的桃子叫什么名字| 激素是什么| 鸡是什么意思| 碳酸氢钠俗称什么| 午餐肉是什么肉| 5.19是什么星座| 脉濡是什么意思| 教师的职责是什么| 什么是化疗| 生长纹是什么原因| 不全纵隔子宫是什么意思| 来月经可以吃什么水果好| 百度

经济开发区康辰公司首次获得 “国家知识产...


Directory: ../../../ffmpeg/
File: src/libavcodec/bsf/hevc_mp4toannexb.c
Date: 2025-08-04 00:43:16
Exec Total Coverage
Lines: 88 116 75.9%
Functions: 3 3 100.0%
Branches: 70 98 71.4%

Line Branch Exec Source
1 /*
2 * HEVC MP4 to Annex B byte stream format filter
3 * copyright (c) 2015 Anton Khirnov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <string.h>
23
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
26
27 #include "bsf.h"
28 #include "bsf_internal.h"
29 #include "bytestream.h"
30 #include "defs.h"
31
32 #include "hevc/hevc.h"
33
34 #define MIN_HEVCC_LENGTH 23
35
36 typedef struct HEVCBSFContext {
37 uint8_t length_size;
38 int extradata_parsed;
39 } HEVCBSFContext;
40
41 1 static int hevc_extradata_to_annexb(AVBSFContext *ctx)
42 {
43 GetByteContext gb;
44 int length_size, num_arrays, i, j;
45 1 int ret = 0;
46
47 1 uint8_t *new_extradata = NULL;
48 1 size_t new_extradata_size = 0;
49
50 1 bytestream2_init(&gb, ctx->par_in->extradata, ctx->par_in->extradata_size);
51
52 1 bytestream2_skip(&gb, 21);
53 1 length_size = (bytestream2_get_byte(&gb) & 3) + 1;
54 1 num_arrays = bytestream2_get_byte(&gb);
55
56
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (i = 0; i < num_arrays; i++) {
57 3 int type = bytestream2_get_byte(&gb) & 0x3f;
58 3 int cnt = bytestream2_get_be16(&gb);
59
60
5/10
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
3 if (!(type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS ||
61 type == HEVC_NAL_SEI_PREFIX || type == HEVC_NAL_SEI_SUFFIX)) {
62 av_log(ctx, AV_LOG_ERROR, "Invalid NAL unit type in extradata: %d\n",
63 type);
64 ret = AVERROR_INVALIDDATA;
65 goto fail;
66 }
67
68
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 for (j = 0; j < cnt; j++) {
69 3 const int nalu_len = bytestream2_get_be16(&gb);
70
71
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 if (!nalu_len ||
72 3 nalu_len > bytestream2_get_bytes_left(&gb) ||
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 4 + AV_INPUT_BUFFER_PADDING_SIZE + nalu_len > SIZE_MAX - new_extradata_size) {
74 ret = AVERROR_INVALIDDATA;
75 goto fail;
76 }
77 3 ret = av_reallocp(&new_extradata, new_extradata_size + nalu_len + 4 + AV_INPUT_BUFFER_PADDING_SIZE);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
79 goto fail;
80
81 3 AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode
82 3 bytestream2_get_buffer(&gb, new_extradata + new_extradata_size + 4, nalu_len);
83 3 new_extradata_size += 4 + nalu_len;
84 3 memset(new_extradata + new_extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
85 }
86 }
87
88 1 av_freep(&ctx->par_out->extradata);
89 1 ctx->par_out->extradata = new_extradata;
90 1 ctx->par_out->extradata_size = new_extradata_size;
91
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!new_extradata_size)
93 av_log(ctx, AV_LOG_WARNING, "No parameter sets in the extradata\n");
94
95 1 return length_size;
96 fail:
97 av_freep(&new_extradata);
98 return ret;
99 }
100
101 1 static int hevc_mp4toannexb_init(AVBSFContext *ctx)
102 {
103 1 HEVCBSFContext *s = ctx->priv_data;
104 int ret;
105
106
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (ctx->par_in->extradata_size < MIN_HEVCC_LENGTH ||
107
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 AV_RB24(ctx->par_in->extradata) == 1 ||
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 AV_RB32(ctx->par_in->extradata) == 1) {
109 av_log(ctx, AV_LOG_VERBOSE,
110 "The input looks like it is Annex B already\n");
111 } else {
112 1 ret = hevc_extradata_to_annexb(ctx);
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
114 return ret;
115 1 s->length_size = ret;
116 1 s->extradata_parsed = 1;
117 }
118
119 1 return 0;
120 }
121
122 97 static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
123 {
124 97 HEVCBSFContext *s = ctx->priv_data;
125 AVPacket *in;
126 GetByteContext gb;
127
128 97 int got_irap = 0;
129 97 int got_ps = 0, seen_irap_ps = 0;
130 97 int i, ret = 0;
131
132 97 ret = ff_bsf_get_packet(ctx, &in);
133
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 48 times.
97 if (ret < 0)
134 49 return ret;
135
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (!s->extradata_parsed) {
137 av_packet_move_ref(out, in);
138 av_packet_free(&in);
139 return 0;
140 }
141
142 48 bytestream2_init(&gb, in->data, in->size);
143
144
4/4
✓ Branch 0 taken 428 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 381 times.
✓ Branch 4 taken 47 times.
429 while (!got_irap && bytestream2_get_bytes_left(&gb)) {
145 381 uint32_t nalu_size = 0;
146 int nalu_type;
147
148
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 381 times.
381 if (bytestream2_get_bytes_left(&gb) < s->length_size) {
149 ret = AVERROR_INVALIDDATA;
150 goto fail;
151 }
152
2/2
✓ Branch 0 taken 1524 times.
✓ Branch 1 taken 381 times.
1905 for (i = 0; i < s->length_size; i++)
153 1524 nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb);
154
155
2/4
✓ Branch 0 taken 381 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 381 times.
381 if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left(&gb)) {
156 ret = AVERROR_INVALIDDATA;
157 goto fail;
158 }
159
160 381 nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f;
161 381 bytestream2_skip(&gb, nalu_size);
162
4/4
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 330 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 50 times.
381 got_irap |= nalu_type >= HEVC_NAL_BLA_W_LP &&
163 nalu_type <= HEVC_NAL_RSV_IRAP_VCL23;
164
4/4
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 331 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 47 times.
381 got_ps |= nalu_type >= HEVC_NAL_VPS && nalu_type <= HEVC_NAL_PPS;
165 }
166
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
48 seen_irap_ps = got_irap && got_ps;
167 48 got_irap = got_ps = 0;
168
169 48 bytestream2_init(&gb, in->data, in->size);
170
171
2/2
✓ Branch 1 taken 382 times.
✓ Branch 2 taken 48 times.
430 while (bytestream2_get_bytes_left(&gb)) {
172 382 uint32_t nalu_size = 0;
173 int nalu_type;
174 int is_irap, is_ps, add_extradata, extra_size, prev_size;
175
176
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 382 times.
382 if (bytestream2_get_bytes_left(&gb) < s->length_size) {
177 ret = AVERROR_INVALIDDATA;
178 goto fail;
179 }
180
2/2
✓ Branch 0 taken 1528 times.
✓ Branch 1 taken 382 times.
1910 for (i = 0; i < s->length_size; i++)
181 1528 nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb);
182
183
2/4
✓ Branch 0 taken 382 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 382 times.
382 if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left(&gb)) {
184 ret = AVERROR_INVALIDDATA;
185 goto fail;
186 }
187
188 382 nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f;
189
190 /* prepend extradata to IRAP frames */
191
4/4
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 330 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 51 times.
382 is_irap = nalu_type >= HEVC_NAL_BLA_W_LP &&
192 nalu_type <= HEVC_NAL_RSV_IRAP_VCL23;
193
5/6
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 331 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
382 is_ps = nalu_type >= HEVC_NAL_VPS && nalu_type <= HEVC_NAL_PPS && seen_irap_ps;
194
7/8
✓ Branch 0 taken 379 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 378 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
382 add_extradata = (is_ps || is_irap) && !got_ps && !got_irap;
195 382 extra_size = add_extradata * ctx->par_out->extradata_size;
196 382 got_irap |= is_irap;
197 382 got_ps |= is_ps;
198
199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382 times.
382 if (FFMIN(INT_MAX, SIZE_MAX) < 4ULL + nalu_size + extra_size) {
200 ret = AVERROR_INVALIDDATA;
201 goto fail;
202 }
203
204 382 prev_size = out->size;
205
206 382 ret = av_grow_packet(out, 4 + nalu_size + extra_size);
207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382 times.
382 if (ret < 0)
208 goto fail;
209
210
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 381 times.
382 if (extra_size)
211 1 memcpy(out->data + prev_size, ctx->par_out->extradata, extra_size);
212 382 AV_WB32(out->data + prev_size + extra_size, 1);
213 382 bytestream2_get_buffer(&gb, out->data + prev_size + 4 + extra_size, nalu_size);
214 }
215
216 48 ret = av_packet_copy_props(out, in);
217
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if (ret < 0)
218 goto fail;
219
220 48 fail:
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (ret < 0)
222 av_packet_unref(out);
223 48 av_packet_free(&in);
224
225 48 return ret;
226 }
227
228 static const enum AVCodecID codec_ids[] = {
229 AV_CODEC_ID_HEVC, AV_CODEC_ID_NONE,
230 };
231
232 const FFBitStreamFilter ff_hevc_mp4toannexb_bsf = {
233 .p.name = "hevc_mp4toannexb",
234 .p.codec_ids = codec_ids,
235 .priv_data_size = sizeof(HEVCBSFContext),
236 .init = hevc_mp4toannexb_init,
237 .filter = hevc_mp4toannexb_filter,
238 };
239

雷字五行属什么 黄瓜与什么相克 身体有湿气有什么症状 百思不得其解是什么意思 伤官见官什么意思
宝批龙是什么意思 泥鳅喜欢吃什么 嗜睡是什么原因 红艳艳的什么 黄什么鱼
吃什么化痰 盐酸利多卡因注射作用是什么 头发粗硬是什么原因 16年属什么生肖 宝宝乳糖不耐受喝什么奶粉比较好
什么品种的鸡肉最好吃 门静脉高压是什么意思 胆固醇高是什么病 纸鸢是什么意思 舌头肥大是什么原因
牙周炎吃什么消炎药cj623037.com 男人遗精是什么原因hcv9jop5ns2r.cn 淋巴发炎吃什么药好hcv7jop9ns7r.cn 小叶增生吃什么药hcv8jop8ns5r.cn 妇科炎症用什么药好jasonfriends.com
abo溶血是什么意思wzqsfys.com 拉屎是绿色的是什么原因hcv7jop9ns2r.cn 神经内科看什么病的hcv8jop3ns4r.cn 脚气吃什么维生素hcv7jop5ns5r.cn 但爱鲈鱼美的但是什么意思hcv9jop5ns0r.cn
梅西踢什么位置hcv8jop0ns5r.cn 定向招生是什么意思hcv8jop7ns0r.cn 肤浅什么意思96micro.com 左胸隐隐作痛是什么原因hcv8jop6ns0r.cn 太平洋中间是什么hcv7jop4ns6r.cn
嘴唇周围长痘痘是什么原因hcv7jop4ns5r.cn b1是什么hcv8jop1ns4r.cn 什么什么相什么的成语jasonfriends.com 晚上口苦是什么原因引起的hcv9jop6ns4r.cn 66.66红包代表什么意思hcv9jop2ns9r.cn
百度