Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIndows: The encoder can't keep up with real-time frame rate in multi-threaded environment. #3768

Open
MichaelLudeo opened this issue Jul 16, 2024 · 1 comment

Comments

@MichaelLudeo
Copy link

Hi.
I am using Openh264 as a plugin to encode a game play in Unity3D engine.
The game is running 60 fps but I am encoding at 30 fps.
The encoding process looks like this: the encoder is running continuously from the start of the game.
Once a user presses a "save footage" the plugin grab the last 10 seconds of the video frames (I cache those in a buffer)
and saves it as raw h264 video steam on the disk. The problem I observe is that Openh264 can't keep up with the 30 fps. It gets an image frame (720p)fetched every 33ms , but for 10 seconds it able to produce only ~260-270 video frames when 300 is expected.To make sure the problem is not in the code around I tested also this scenario with Nvidia video encoder ( nvenc) and libx264 h264 encoders. These work fine. Additionally, the number of missing frames growth with the duration: the longer the video duration I am recording the larger the gap from the target number of video frames. I tried to set number of threads explicitly, but it doesn't change anything.
Why I think it has to do with multi-threading? I tested the encoder also in a standalone application which runs on a simple d3d11 renderer and uses just a couple of more threads,one of which is used to transform color space and encode - this one works correctly too.
Unity is heavily multi-threaded, and I suspect it impacts the encoder's performance. Maybe I am wrong about threads and it is something else. Would be glad to hear other ideas.
Thanks.

@aljam3h
Copy link

aljam3h commented Sep 16, 2024

Hi.
I am using Openh264 as a plugin to encode a game play in Unity3D engine.
The game

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants