【发布时间】:2021-06-17 21:22:56
【问题描述】:
我正在使用 fffmpeg 做一些视频工作,现在我遇到了一些麻烦。 我不知道如何获得转码的进度。 我检查了ffmpeg.c,发现大部分时间成本是“转码”, 这里是ffmpeg.c#transcode的源代码:
static int transcode(void)
{
XLOGD("==========transcode==========");
...
XLOGD("start transcode");
while (!received_sigterm) {
int64_t cur_time= av_gettime_relative();
/* if 'q' pressed, exits */
if (stdin_interaction)
if (check_keyboard_interaction(cur_time) < 0)
break;
/* check if there's any stream where output is still needed */
if (!need_output()) {
av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write
to, finishing.\n");
break;
}
ret = transcode_step();
if (ret < 0 && ret != AVERROR_EOF) {
av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n",
av_err2str(ret));
break;
}
/* dump report by using the output first video and audio streams */
print_report(0, timer_start, cur_time);
}
return ret;
}
我这样调用ffmpeg:
int 执行(int argc, char **argv) {
如果 CONFIG_AVDEVICE
/* parse options and open all input/output files */
ret = ffmpeg_parse_options(argc, argv);
if (ret < 0){
return exit_program(1);
}
if (nb_output_files <= 0 && nb_input_files == 0) {
show_usage();
av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
return exit_program(1);
}
/* file converter / grab */
if (nb_output_files <= 0) {
av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
return exit_program(1);
}
if (nb_input_files == 0) {
av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n");
return exit_program(1);
}
for (i = 0; i < nb_output_files; i++) {
if (strcmp(output_files[i]->ctx->oformat->name, "rtp"))
want_sdp = 0;
}
current_time = ti = getutime();
if (transcode() < 0){
return exit_program(1);
}
返回 main_return_code; }
有什么想法吗?
非常感谢。
#非常感谢,现在我想通了。 在 ffmpeg.c 中,函数
print_report(int is_last_report, int64_t timer_start, int64_t cur_time),
我得到了一些代码块:
secs = FFABS(pts) / AV_TIME_BASE;
us = FFABS(pts) % AV_TIME_BASE;
mins = secs / 60;
secs %= 60;
hours = mins / 60;
mins %= 60;
由此我可以知道转码的持续时间。
【问题讨论】:
-
这是 parse_options() 返回后 main() 中的主要(也是唯一)循环。您如何使用 ffmpeg - 命令行、API?
标签: ffmpeg