C++ ffmpeg+;glfwGetTime()
我尝试使用ffmpeg+opengl控制视频的播放速度。但我有问题 我的视频以每秒25帧的速度编码,播放速度非常快。我在代码中添加了这个C++ ffmpeg+;glfwGetTime(),c++,c,ffmpeg,glfw,C++,C,Ffmpeg,Glfw,我尝试使用ffmpeg+opengl控制视频的播放速度。但我有问题 我的视频以每秒25帧的速度编码,播放速度非常快。我在代码中添加了这个 tiempo = glfwGetTime(); duracion = 1.0/25.0; // 1 second / 25 fps while(1){ ... if(glfwGetTime() > tiempo + duracion){ if(av_read_frame(pFormatCtx,&packet) &
tiempo = glfwGetTime();
duracion = 1.0/25.0; // 1 second / 25 fps
while(1){
...
if(glfwGetTime() > tiempo + duracion){
if(av_read_frame(pFormatCtx,&packet) >= 0){
if(packet.stream_index == 0){
avcodec_decode_video2(pCodecCtx,pFrame,&frameFin,&packet);
if(frameFin)sws_scale(img_convert_ctx,pFrame->data,pFrame->linesize,0,pCodecCtx->height,pFrameRGB->data,pFrameRGB->linesize);
}
av_free_packet(&packet);
}
tiempo = glfwGetTime();
}
...
}
问题是现在的视频播放速度比应该的慢。问题出在哪里?您将解码图像所需的时间添加到需要等待显示下一个图像的40毫秒。此错误是因为在循环结束时再次测量时间 而不是:
}
tiempo = glfwGetTime();
}
写:
}
tiempo+=duraction;
}
我认为这是错误的:
如果(glfwGetTime()>tiempo+duracion){
//...
tiempo=glfwGetTime()
因为对glfwGetTime的第一次调用和第二次调用不一样->您应该将其缓存在一个变量中并与之进行比较。您是否在某个地方进行了睡眠以避免此循环以最低速度运行?它似乎有效!非常感谢您的回答,朋友:-)也谢谢您,朋友:-)