省长什么级别| 例假少吃什么能让量多| 肛肠科属于什么科| 宝宝吃什么奶粉好| 嗡阿吽是什么意思| 桑黄长在什么树上| 卖是什么意思| 瑜伽是什么意思| 束带是什么| 鸡屁股叫什么| 手掌发红是什么原因| 感冒了吃什么药| 异禀是什么意思| 身主天相是什么意思| 西米是什么做的| 白介素2是治疗什么病的| 利血平是什么药| 肝硬化是什么| 50公斤发什么物流便宜| cta是什么检查| 蛞蝓是什么| dha是什么意思| 缺钾是什么症状| 拉肚子吃什么菜| 可可是什么饮料| 世风日下什么意思| 俄罗斯的国花是什么花| 相伴是什么意思| 宫腔积液吃什么药效果最好| 生肖龙和什么生肖最配| 心慌手抖是什么原因| 得了阴虱用什么药能除根| gap是什么牌子的衣服| 金灿灿的什么| 空调外机为什么会滴水| 什么原因引起血糖高| 癌症病人吃什么| 貂是什么动物| 感冒嗓子痒咳嗽吃什么药| 脑电图异常是什么病| 1991年属羊是什么命| pr间期延长是什么意思| 鼻子出血挂什么科| 1941属什么生肖| pd950是什么金| 孕妇的尿液有什么用途| 自限性疾病是什么意思| 牙垢是什么| 蛇吃什么| 毛新宇什么级别| 输血前八项指什么| der是什么意思| 回族为什么不能吃猪肉| 田字出头是什么字| 垂涎什么意思| 12320是什么电话| 静心是什么意思| 二甲双胍什么时候吃最好| 香蕉像什么比喻句| 送男生什么生日礼物| 拎不清是什么意思| 乌龟属于什么动物| 牙龈紫色是什么原因| 什么是无机盐| 韬字五行属什么| 大蒜味是什么中毒| 男性早泄吃什么药| 衣锦还乡是什么意思| 相宜的意思是什么| 梦见大风大雨预示什么| 专台号是什么意思| 吃丝瓜有什么功效和作用| 体质指数是什么意思| 炎症用什么药最好| 电表走的快是什么原因| c反应蛋白是什么意思| 什么叫做| 骨折后吃什么好的快| 1981年属什么生肖| 82年属什么的| 右胳膊发麻是什么原因| 吃二甲双胍为什么会瘦| 2009年属什么生肖| 手指脱皮是缺什么维生素| 鬼火是什么意思| 代发什么意思| 痛经吃什么| 待字闺中是什么意思| 梦见自己骑马是什么意思| 唇上有痣代表什么| 血尿是什么原因| 澜字五行属什么| 维生素b12片治什么病| 乙肝有什么明显的症状| 流黄鼻涕是什么原因| 手串断了寓意什么| 护腕有什么用| 1893年属什么| 解大便时有鲜血流出是什么原因| 吃什么能缓解孕吐| 束缚什么意思| 荒芜是什么意思| 两个日是什么字| 舌头短是什么原因| 喉咙长溃疡是什么原因| 寻找什么| 牙龈为什么会肿痛| 骶椎腰化什么意思| 送日子是什么意思| 继发性高血压是什么意思| 女性感染hpv有什么症状| 甲状腺在什么位置图片| 蚕蛾吃什么| 炎性增殖灶是什么意思| 教师节送什么礼物呢| 驴血为什么是白色的| 人老是放屁是什么原因| 血小板降低是什么病| 喝什么泡水降血压最好| 公丁香和母丁香有什么区别| 无疾而终什么意思| 澳大利亚有什么动物| 九十岁老人称什么| 什么是精神出轨| 口腔发苦是什么原因| 月经推迟什么原因| 98年属什么| 切脉切的是什么脉| 内化是什么意思| 望周知是什么意思| 待客是什么意思| 局气是什么意思| 凉皮用什么粉做的| 口臭口干口苦是什么原因| 韶字五行属什么| 左耳朵嗡嗡响是什么原因引起的| 血小板低吃什么好补| 原味是什么意思| 什么是电离辐射| 右眼皮跳是什么意思| 易主是什么意思| 黑加京念什么| 孩子咬手指甲是什么原因| 解脲脲原体阳性是什么| 下焦湿热阴囊潮湿吃什么药| 嘴巴里面起泡是什么原因引起的| 肉碱是什么| 中性粒细胞是指什么| 物以类聚人以群分什么意思| 你为什么不说话歌词| 头孢有什么用| 绒毛浆是什么| 碳水化合物指的是什么| 5月4日什么星座| 九月十七是什么星座| 全身检查要挂什么科| 一生辛苦不得财是什么生肖| 咖啡不能和什么一起吃| 燚是什么意思| 阿胶不能和什么一起吃| 淼怎么读什么意思| 舌苔厚白吃什么药最好| 天灾人祸什么意思| 家五行属什么| 五月十六日是什么星座| 靖五行属性是什么| 月经不调去医院挂什么科| 肩周炎吃什么药好| 肺炎支原体抗体阴性是什么意思| 为什么老长口腔溃疡| 为什么人会做梦| 2月什么星座| 鱿鱼炒什么好吃| 右手小指戴戒指什么意思| 四肢麻木是什么病| 耳朵里面痒是什么原因| 合拍是什么意思| 阑尾炎检查什么项目| 医学五行属什么| 非萎缩性胃炎什么意思| 黑暗料理是什么意思| 为什么眼睛老是流泪| 眼睛发炎用什么眼药水| 胃出血恢复期吃什么好| 一叶一菩提一花一世界什么意思| 农村一般喂金毛吃什么| 儿童早餐吃什么有营养还能长高| 只吐不拉是什么原因| 真菌感染用什么药最好| 百合和拉拉有什么区别| 什么马不能骑| 天天打喷嚏是什么原因| 29度穿什么衣服合适| 肝内低密度影是什么意思| 麦芯粉是什么面粉| 手抖吃什么药| 化疗是什么样的过程| 梦见大便是什么预兆| 狂鸟读什么| 右侧肋骨下方是什么器官| 左手无名指戴戒指什么意思| 儿童回春颗粒主要治什么| 内分泌失调吃什么药效果最好| 五什么六什么| 蛋白是什么东西| 牛油果树长什么样| 山见念什么| 伤口消毒用什么| 底妆是什么意思| 公因数是什么意思| 美容师都要学什么| 高贵的什么| 34属什么| 备是什么意思| 血脂是指什么| 为什么会长扁平疣| 结核有什么症状| 腔梗吃什么药| 经期可以喝什么| sob是什么意思| 邮政编码有什么用| 尿频看什么科| 手抖是什么症状| 狗狗有什么品种| 自由奔放是什么生肖| 什么暗什么明| 无穷大是什么意思| 268是什么意思| 贴图是什么意思| 出汗太多是什么原因| 总胆固醇高有什么危害| 抿嘴是什么意思| 蚂蚱长什么样| 拾到什么意思| 正团级是什么军衔| 天津为什么叫天津卫| 中药什么时候喝| 咆哮是什么意思| 梦到狗什么意思| 蜱虫咬人后有什么症状图片| 智齿长什么样子| 女人梦见桃子预示什么| 十三香是什么| 腿有淤青是什么原因| 脸上痒是什么原因| 送礼送什么比较好| 诸侯国是什么意思| 喝老陈皮水有什么好处| 男人要的归属感是什么| 1999年发生了什么事| 1966年属什么今年多大| 肝纤维化是什么意思| 尼特族是什么意思| 梦见钓鱼是什么意思周公解梦| 什么是鸡奸| 眼珠子发黄是什么原因| 糖吃多了有什么危害| bebe是什么牌子| 什么是溶血性疾病| 两个c是什么牌子| 头发斑秃是什么原因引起的| 重力是什么| 为什么拉的屎是墨绿色| 湿热会引起什么症状| 百度


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_fsync.c
Date: 2025-08-04 00:43:16
Exec Total Coverage
Lines: 100 117 85.5%
Functions: 9 9 100.0%
Branches: 43 60 71.7%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2023 Thilo Borgmann <thilo.borgmann _at_ mail.de>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * Filter for syncing video frames from external source
24 *
25 * @author Thilo Borgmann <thilo.borgmann _at_ mail.de>
26 */
27
28 #include "libavutil/avstring.h"
29 #include "libavutil/error.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/opt.h"
32 #include "libavformat/avio.h"
33 #include "video.h"
34 #include "filters.h"
35
36 #define BUF_SIZE 256
37
38 typedef struct FsyncContext {
39 const AVClass *class;
40 AVIOContext *avio_ctx; // reading the map file
41 AVFrame *last_frame; // buffering the last frame for duplicating eventually
42 char *filename; // user-specified map file
43 char *buf; // line buffer for the map file
44 char *cur; // current position in the line buffer
45 char *end; // end pointer of the line buffer
46 int64_t ptsi; // input pts to map to [0-N] output pts
47 int64_t pts; // output pts
48 int tb_num; // output timebase num
49 int tb_den; // output timebase den
50 } FsyncContext;
51
52 #define OFFSET(x) offsetof(FsyncContext, x)
53
54 static const AVOption fsync_options[] = {
55 { "file", "set the file name to use for frame sync", OFFSET(filename), AV_OPT_TYPE_STRING, { .str = "" }, .flags= AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
56 { "f", "set the file name to use for frame sync", OFFSET(filename), AV_OPT_TYPE_STRING, { .str = "" }, .flags= AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
57 { NULL }
58 };
59
60 /**
61 * Fills the buffer from cur to end, add \0 at EOF
62 */
63 6 static int buf_fill(FsyncContext *ctx)
64 {
65 int ret;
66 6 int num = ctx->end - ctx->cur;
67
68 6 ret = avio_read(ctx->avio_ctx, ctx->cur, num);
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret < 0)
70 return ret;
71
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (ret < num) {
72 3 *(ctx->cur + ret) = '\0';
73 }
74
75 6 return ret;
76 }
77
78 /**
79 * Copies cur to end to the beginning and fills the rest
80 */
81 2 static int buf_reload(FsyncContext *ctx)
82 {
83 int i, ret;
84 2 int num = ctx->end - ctx->cur;
85
86
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (i = 0; i < num; i++) {
87 6 ctx->buf[i] = *ctx->cur++;
88 }
89
90 2 ctx->cur = ctx->buf + i;
91 2 ret = buf_fill(ctx);
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0)
93 return ret;
94 2 ctx->cur = ctx->buf;
95
96 2 return ret;
97 }
98
99 /**
100 * Skip from cur over eol
101 */
102 165 static void buf_skip_eol(FsyncContext *ctx)
103 {
104 char *i;
105
1/2
✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
229 for (i = ctx->cur; i < ctx->end; i++) {
106
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 64 times.
229 if (*i != '\n')// && *i != '\r')
107 165 break;
108 }
109 165 ctx->cur = i;
110 165 }
111
112 /**
113 * Get number of bytes from cur until eol
114 *
115 * @return >= 0 in case of success,
116 * -1 in case there is no line ending before end of buffer
117 */
118 167 static int buf_get_line_count(FsyncContext *ctx)
119 {
120 167 int ret = 0;
121 char *i;
122
2/2
✓ Branch 0 taken 1597 times.
✓ Branch 1 taken 2 times.
1599 for (i = ctx->cur; i < ctx->end; i++, ret++) {
123
4/4
✓ Branch 0 taken 1594 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 162 times.
✓ Branch 3 taken 1432 times.
1597 if (*i == '\0' || *i == '\n')
124 165 return ret;
125 }
126
127 2 return -1;
128 }
129
130 /**
131 * Get number of bytes from cur to '\0'
132 */
133 75 static int buf_get_zero(FsyncContext *ctx)
134 {
135 75 return av_strnlen(ctx->cur, ctx->end - ctx->cur);
136 }
137
138 165 static int activate(AVFilterContext *ctx)
139 {
140 165 FsyncContext *s = ctx->priv;
141 165 AVFilterLink *inlink = ctx->inputs[0];
142 165 AVFilterLink *outlink = ctx->outputs[0];
143
144 int ret, line_count;
145 AVFrame *frame;
146
147
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 165 times.
165 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
148
149 165 buf_skip_eol(s);
150 165 line_count = buf_get_line_count(s);
151
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 163 times.
165 if (line_count < 0) {
152 2 line_count = buf_reload(s);
153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (line_count < 0)
154 return line_count;
155 2 line_count = buf_get_line_count(s);
156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (line_count < 0)
157 return line_count;
158 }
159
160
4/4
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 93 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 69 times.
165 if (avio_feof(s->avio_ctx) && buf_get_zero(s) < 3) {
161 3 av_log(ctx, AV_LOG_DEBUG, "End of file. To zero = %i\n", buf_get_zero(s));
162 3 goto end;
163 }
164
165
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 51 times.
162 if (s->last_frame) {
166 111 ret = av_sscanf(s->cur, "%"PRId64" %"PRId64" %d/%d", &s->ptsi, &s->pts, &s->tb_num, &s->tb_den);
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if (ret != 4) {
168 av_log(ctx, AV_LOG_ERROR, "Unexpected format found (%i / 4).\n", ret);
169 ff_outlink_set_status(outlink, AVERROR_INVALIDDATA, AV_NOPTS_VALUE);
170 return AVERROR_INVALIDDATA;
171 }
172
173 111 av_log(ctx, AV_LOG_DEBUG, "frame %"PRId64" ", s->last_frame->pts);
174
175
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 47 times.
111 if (s->last_frame->pts >= s->ptsi) {
176 64 av_log(ctx, AV_LOG_DEBUG, ">= %"PRId64": DUP LAST with pts = %"PRId64"\n", s->ptsi, s->pts);
177
178 // clone frame
179 64 frame = av_frame_clone(s->last_frame);
180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (!frame) {
181 ff_outlink_set_status(outlink, AVERROR(ENOMEM), AV_NOPTS_VALUE);
182 return AVERROR(ENOMEM);
183 }
184
185 // set output pts and timebase
186 64 frame->pts = s->pts;
187 64 frame->time_base = av_make_q((int)s->tb_num, (int)s->tb_den);
188
189 // advance cur to eol, skip over eol in the next call
190 64 s->cur += line_count;
191
192 // call again
193
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 if (ff_inoutlink_check_flow(inlink, outlink))
194 64 ff_filter_set_ready(ctx, 100);
195
196 // filter frame
197 64 return ff_filter_frame(outlink, frame);
198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 } else if (s->last_frame->pts < s->ptsi) {
199 47 av_log(ctx, AV_LOG_DEBUG, "< %"PRId64": DROP\n", s->ptsi);
200 47 av_frame_free(&s->last_frame);
201
202 // call again
203
1/2
✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
47 if (ff_inoutlink_check_flow(inlink, outlink))
204 47 ff_filter_set_ready(ctx, 100);
205
206 47 return 0;
207 }
208 }
209
210 51 end:
211
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 51 times.
54 if (s->last_frame)
212 3 av_frame_free(&s->last_frame);
213
214 54 ret = ff_inlink_consume_frame(inlink, &s->last_frame);
215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (ret < 0)
216 return ret;
217
218
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 52 times.
54 FF_FILTER_FORWARD_STATUS(inlink, outlink);
219
1/2
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
52 FF_FILTER_FORWARD_WANTED(outlink, inlink);
220
221 return FFERROR_NOT_READY;
222 }
223
224 2 static int fsync_config_props(AVFilterLink* outlink)
225 {
226 2 AVFilterContext *ctx = outlink->src;
227 2 FilterLink *l = ff_filter_link(outlink);
228 2 FsyncContext *s = ctx->priv;
229 int ret;
230
231 // read first line to get output timebase
232 2 ret = av_sscanf(s->cur, "%"PRId64" %"PRId64" %d/%d", &s->ptsi, &s->pts, &s->tb_num, &s->tb_den);
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret != 4) {
234 av_log(ctx, AV_LOG_ERROR, "Unexpected format found (%i of 4).\n", ret);
235 ff_outlink_set_status(outlink, AVERROR_INVALIDDATA, AV_NOPTS_VALUE);
236 return AVERROR_INVALIDDATA;
237 }
238
239 2 l->frame_rate = av_make_q(1, 0); // unknown or dynamic
240 2 outlink->time_base = av_make_q(s->tb_num, s->tb_den);
241
242 2 return 0;
243 }
244
245 4 static av_cold int fsync_init(AVFilterContext *ctx)
246 {
247 4 FsyncContext *s = ctx->priv;
248 int ret;
249
250 4 av_log(ctx, AV_LOG_DEBUG, "filename: %s\n", s->filename);
251
252 4 s->buf = av_malloc(BUF_SIZE + 1);
253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!s->buf)
254 return AVERROR(ENOMEM);
255
256 4 ret = avio_open(&s->avio_ctx, s->filename, AVIO_FLAG_READ);
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
258 return ret;
259
260 4 s->cur = s->buf;
261 4 s->end = s->buf + BUF_SIZE;
262 4 s->buf[BUF_SIZE] = '\0';
263
264 4 ret = buf_fill(s);
265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
266 return ret;
267
268
269 4 return 0;
270 }
271
272 4 static av_cold void fsync_uninit(AVFilterContext *ctx)
273 {
274 4 FsyncContext *s = ctx->priv;
275
276 4 avio_closep(&s->avio_ctx);
277 4 av_freep(&s->buf);
278 4 av_frame_free(&s->last_frame);
279 4 }
280
281 AVFILTER_DEFINE_CLASS(fsync);
282
283 static const AVFilterPad fsync_outputs[] = {
284 {
285 .name = "default",
286 .type = AVMEDIA_TYPE_VIDEO,
287 .config_props = fsync_config_props,
288 },
289 };
290
291 const FFFilter ff_vf_fsync = {
292 .p.name = "fsync",
293 .p.description = NULL_IF_CONFIG_SMALL("Synchronize video frames from external source."),
294 .p.priv_class = &fsync_class,
295 .p.flags = AVFILTER_FLAG_METADATA_ONLY,
296 .init = fsync_init,
297 .uninit = fsync_uninit,
298 .priv_size = sizeof(FsyncContext),
299 .activate = activate,
300 .formats_state = FF_FILTER_FORMATS_PASSTHROUGH,
301 FILTER_INPUTS(ff_video_default_filterpad),
302 FILTER_OUTPUTS(fsync_outputs),
303 };
304

粉蒸肉用什么肉好吃 经常腰酸是什么原因女性 萝莉控是什么意思 豆面是什么 脊膜瘤是什么样的病
王八看绿豆是什么意思 殖民地是什么意思 妊娠是什么 盛世美颜是什么意思 胃酸反流是什么原因
预科班什么意思 早搏是什么原因引起的 吃什么补气血最快最好 喝温开水有什么好处 最大的罩杯是什么杯
http是什么 10.19什么星座 三教九流什么意思 吃什么补肾精 64岁属什么
亲什么意思hcv9jop6ns5r.cn 梦见牙齿掉光了是什么征兆hcv7jop5ns1r.cn 对食什么意思hcv8jop4ns3r.cn 烂好人是什么意思hcv9jop5ns0r.cn 神经性皮炎用什么药膏hcv9jop4ns7r.cn
梦见性生活是什么意思hcv8jop6ns6r.cn 蓝莓泡酒有什么功效ff14chat.com 洋地黄中毒首选什么药hcv8jop8ns7r.cn 打狂犬疫苗不能吃什么helloaicloud.com 什么情什么意hcv8jop0ns1r.cn
甲状腺肿大挂什么科hcv7jop4ns8r.cn 什么就是什么造句xianpinbao.com 美尼尔症是什么病hcv8jop3ns4r.cn facebook是什么意思hcv9jop1ns1r.cn 色盲色弱是什么意思hcv7jop5ns3r.cn
爱居兔女装是什么档次hcv9jop6ns4r.cn 肛周脓肿是什么原因引起的hcv7jop6ns6r.cn 汽车空调不制冷是什么原因hcv8jop9ns6r.cn 梦见蛇咬我是什么意思hcv7jop7ns3r.cn 鼻炎是什么原因引起的hcv9jop1ns5r.cn
百度