Sourcehold
Sourcehold copied to clipboard
Bink video fps isn't used in game loop
Hi,
all Bink videos are playing very fast when I run the game. It occurs after changes of https://github.com/sourcehold/Sourcehold/commit/2a1902df411004654c2310293e8a386f9a4c858a
I have figured out that the game loop doesn't used FPS rate of the video. Here is my fix:
UIState Startup::Begin()
{
...
while(Running()) {
...
switch(currentStartupState) {
...
case STARTUP_INTRO:
...
// respect FPS of Bink video (29.97fps)
if(delta > 1.0 / intro->Fps()*2) {
startTime = now;
intro->Update();
}
Fps getter have to be added to BinkVideo class too.
In my tests the video speed was correct but the audio track sounds not clear. In addition, I have no idea why the fps have to multiply by 2.
Perhaps it is better to implement a timer directly in the Update() function of the BinkVideo class.
Hi,
the Startup class doesn't actually have proper timing yet, it just delays for some time between frames (I know...). I will probably add some global method for timing main loops later.
As for BinkVideo, I haven't yet figured out how to use the new ffmpeg api, as it doesn't handle timing for you and the online documentation is mostly for the old api. This is probably the reason for the screwed-up audio too. I will have to read into that a bit more.
I've read a bit more about ffmpeg.
At this moment, the game loop acts as a player playing a video and an audio frame for each loop. Based on the loop speed, the fps can be variable (depending on processor load). I suppose that's the problem of the screwed up sound.
It looks like a separate player like ffplay is needed. (Https://github.com/FFmpeg/FFmpeg/blob/master/fftools/ffplay.c)
To use such a player, the game loop should pause while the player is running. At the moment, I have no idea how else to embed an asynchronous player into a game loop that render all visual graphics.