ffmpeg - FFmpeg - 如何获得转码进度?
问题描述
我正在使用 fffmpeg 做一些视频工作,现在我遇到了一些麻烦。我不知道如何获得转码的进度。我检查了ffmpeg.c,发现大部分时间成本是'transcode',这里是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;
由此我可以知道已转码的持续时间。
解决方案
首先获取电影的时长:int64_t duration = output_files[0]->ctx->duration;
循环中的第二个:您可以使用以下公式计算百分比: int percent = (int)(((double)(cur_time - timer_start) / (double)(duration )) * 100);
推荐阅读
- r - 从闪亮的日历中删除几个月
- javascript - 如何通过 Phantom 使用 web3js 正确传输 Solana SOL
- css - React 应用程序上的 CSS 突然停止工作
- r - for 循环在 r 中循环通过向量
- object - MQL4 在斐波那契水平上绘制带有矩形的动态斐波那契
- graphql - 如何将 grpc 服务与 graphql 集成?
- spring-boot - Eureka 多个 defaultZone、CloudConfig 和 @Value 注解
- c# - 如何将内存中的对象作为 JSON 文件从服务器端 Blazor 下载到客户端?
- python-3.x - 石墨烯代码在 Django 数据迁移之前运行
- java - 我想我不明白工作经理的结构