CREATE and FUCK your own AI GIRLFRIEND TRY FOR FREE
x

Ren'Py Mod help: increasing CPU usage when playing videos in sequence

flwqo

Member
Modder
Jun 6, 2021
156
220
I'm currently enhancing and interpolating videos in some games. Specifically this atm. However, I've stumbled upon a problem. Renpy is horrible at video playback?

First, it's very inefficient at playback, using many times more CPU when compared to a video player. More importantly, it seems the more videos you display in sequence, the more CPU it uses?

Currently, the game often have a structure of: video (1) -> (2) -> (3) -> (4). However, the CPU usage is always something like: 25% -> 40% -> 50% -> 65% etc, no matter the video.
Here's an example from another game of his. This is usage from one core of my cpu:
cpuusage.PNG
You can clearly see when the next video starts playing.

This becomes a big problem for my 120 fps videos, because at (2) it already starts dropping frames (>90% usage), and at (3) it stutters (>97% usage).

Now I spent many days enhancing, interpolating and encoding all these videos, so I really want to be able to keep them and not re-encode them to 60 fps, which is already borderline CPU usage.

Any help?
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,769
15,817
First, it's very inefficient at playback, using many times more CPU when compared to a video player.
A game engine in Python is less efficient than a dedicated video player in C(++)... What a surprise !


More importantly, it seems the more videos you display in sequence, the more CPU it uses?
I tried many way, and didn't get that result, so what do you mean by "display in sequence" ? A code example would be welcome.


This becomes a big problem for my 120 fps videos, because at (2) it already starts dropping frames (>90% usage), and at (3) it stutters (>97% usage).
What is the interest to have 120 FPS videos in a Ren'Py game ?
Ren'Py periodicity is 1/20th of second, therefore it will never process a video at more than 50 FPS.


[...] not re-encode them to 60 fps, which is already borderline CPU usage.
My 10yo i7-8700 at 3.7GHz have no problems to play 60 FPS videos in Ren'Py (that will limit at 50 FPS as said above) and the CPU load increase is below 10% ; yet the fact that it was through a remote connection made the increase bigger than it would normally be. This both with the 7.5.x and 8.x branches.
 

flwqo

Member
Modder
Jun 6, 2021
156
220
I tried many way, and didn't get that result, so what do you mean by "display in sequence" ? A code example would be welcome.
I meant the game (VN) often have a structure of:
text1+video(1) in background -> text2+(1) -> text3+(1) -> text4+(2) -> text5+(2) -> text6+(2) -> text7+(3) etc.
Typical VN scene with text, with a video playing in the background. The video changes as the scene progresses. The problem is, every time the video changes/new video plays, the CPU usage increase, see the picture I attached. Almost as if the new video is playing on top of the old one, instead of closing the previous video.

What is the interest to have 120 FPS videos in a Ren'Py game ?
Ren'Py periodicity is 1/20th of second, therefore it will never process a video at more than 50 FPS.
To clarify, are you saying that Renpy only updates at 50 fps? So it will never display any video >50 fps? I can't find any documentation for this limit. says Renpy can support higher. I also checked the frame rate while playing the game with the 120 fps video, it shows >120 fps. Also, if renpy can only show 50 fps, why have this setting:
renpyfps.PNG
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,769
15,817
The problem is, every time the video changes/new video plays, the CPU usage increase, see the picture I attached.
Oh... I get it now...


Almost as if the new video is playing on top of the old one, instead of closing the previous video.
Strange isn't it... Almost as if someone shown a video and never had the genius idea to hide it before passing to the next one...

The "almost as if" being obviously sarcastic. It's precisely what is happening !


To clarify, are you saying that Renpy only updates at 50 fps? So it will never display any video >50 fps? [...] says Renpy can support higher.
I guess that I need to be more precise.
Ren'Py's periodicity is 1/20th of second, what mean 50 FPS. Therefore, it will show a video at this rate at max, but it can still play videos at a higher rate if both the video and monitor support it.

Now, this being said, ; yet only for some individuals, the vast majority stand around 30-35 FPS. Therefore, higher frame rates have no interest outside of real time building (in what case it limits the possible afterglow effect in case of sudden move).
 

flwqo

Member
Modder
Jun 6, 2021
156
220
Strange isn't it... Almost as if someone shown a video and never had the genius idea to hide it before passing to the next one...

The "almost as if" being obviously sarcastic. It's precisely what is happening !
Thanks. I'll pass it to the dev. Hopefully he can fix it.

Now, this being said,
This is a very common myth, but it's not actually true. You can ask anyone playing games at high refresh rates (>100 fps). We can 100% tell the difference of higher fps. I did a test:

I encoded the same video as 60 and 120 fps. Then I play them side-by-side. I can clearly tell 120 fps is smoother.

I guess that I need to be more precise.
Ren'Py's periodicity is 1/20th of second, what mean 50 FPS. Therefore, it will show a video at this rate at max, but it can still play videos at a higher rate if both the video and monitor support it.
Are you 100% sure? Are you referring to Renpy documentation somewhere? Because I did some tests:

I add the 120 video to the game and play it. Now I compare the in-game video to playback outside the game side-by-side. The in-game video is smoother and closer to the 120 fps version than the 60 fps version.
My monitor can display the frame rate/fps. Just to check, I turn it on in-game, and it shows the game is displaying at >120 fps when the in-game video is playing.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,769
15,817
This is a very common myth, but it's not actually true. You can ask anyone playing games at high refresh rates (>100 fps).
Hmm, on one side, there's was doctors and scientists say, on the others what a bunch of players claim. What side will I trust the most ? Difficult choice...


I encoded the same video as 60 and 120 fps. Then I play them side-by-side. I can clearly tell 120 fps is smoother.
And when you play them alone, you'll be totally unable to tell which one is at 120 FPS if you don't know it before hand...


My monitor can display the frame rate/fps.
No. Your monitor can display how often it is asked to refresh, what is different.
I can perfectly make a software that will refresh its screen at 120 FPS while updating it only a 30 FPS, and your monitor will wrongly tell you that my software works at 120 FPS, what would be wrong.
 

flwqo

Member
Modder
Jun 6, 2021
156
220
Hmm, on one side, there's was doctors and scientists say, on the others what a bunch of players claim. What side will I trust the most ? Difficult choice...
It's not a bunch of players. It's millions of people around the world using high refresh monitors. Even just moving around your mouse pointer you can tell the difference.

And when you play them alone, you'll be totally unable to tell which one is at 120 FPS if you don't know it before hand...
No, I absolutely can tell in a blind test. But that's irrelevant; logically, if I can tell side-by-side, then there is a difference.

No. Your monitor can display how often it is asked to refresh, what is different.
I can perfectly make a software that will refresh its screen at 120 FPS while updating it only a 30 FPS, and your monitor will wrongly tell you that my software works at 120 FPS, what would be wrong.
I get what you're saying, but I should clarify. I have a variable-refresh-rate monitor. So it should only refresh based on the fps of the content.

Just to make sure, I tested playing the game several times with 60 fps and 120 fps video, and I think I can see a difference. It is not as clear compared to when I play them outside the game though, maybe due to frame pacing in-game.
Since it's not a huge difference in-game, with my old CPU at least, I guess I can accept 60 fps if dev can't fix the "overlaying videos" problem.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,769
15,817
It's not a bunch of players. It's millions of people around the world using high refresh monitors. Even just moving around your mouse pointer you can tell the difference.
*sigh*


I get what you're saying, but I should clarify. I have a variable-refresh-rate monitor. So it should only refresh based on the fps of the content.
Don't say that you got what I'm saying, when it's clearly not the case.

You monitor will refresh anytime it received data, but this doesn't mean that those data have been updated since last time. Because yes, there's (nowadays "bad") software that send their display at the end of every cycle, even if they know perfectly that they haven't touched it during that cycle.
Every FPS measure took outside of the software itself are just indicative and do not necessarily reflect the effective refresh rate of the display. Plus, but I guess that it don't apply here, unless you are playing in full screen, there's even no guaranty that the data are sent by what you try to measure.