1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-25 12:14:46 +02:00

Fixed video playback framerate for intro videos

This commit is contained in:
Ivan Savenko 2024-01-05 14:18:13 +02:00
parent 121ef77440
commit fd85d93a00

View File

@ -634,6 +634,8 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey)
pos.y = y; pos.y = y;
frameTime = 0.0; frameTime = 0.0;
auto lastTimePoint = boost::chrono::steady_clock::now();
while(nextFrame()) while(nextFrame())
{ {
if(stopOnKey) if(stopOnKey)
@ -654,10 +656,17 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey)
#else #else
auto packet_duration = frame->duration; auto packet_duration = frame->duration;
#endif #endif
double frameDurationSec = packet_duration * av_q2d(format->streams[stream]->time_base); // Framerate delay
uint32_t timeToSleepMillisec = 1000 * (frameDurationSec); double targetFrameTimeSeconds = packet_duration * av_q2d(format->streams[stream]->time_base);
auto targetFrameTime = boost::chrono::milliseconds(static_cast<int>(1000 * (targetFrameTimeSeconds)));
boost::this_thread::sleep_for(boost::chrono::milliseconds(timeToSleepMillisec)); auto timePointAfterPresent = boost::chrono::steady_clock::now();
auto timeSpentBusy = boost::chrono::duration_cast<boost::chrono::milliseconds>(timePointAfterPresent - lastTimePoint);
if (targetFrameTime > timeSpentBusy)
boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy);
lastTimePoint = boost::chrono::steady_clock::now();
} }
return true; return true;