sskodje / ScreenRecorderLib

A .NET library for screen recording in Windows, using native Microsoft Media Foundation for realtime encoding to h264 video or PNG images.
MIT License
414 stars 94 forks source link

Very laggy behaviour in 4k quality with 60 fps #290

Closed tamasbito99 closed 7 months ago

tamasbito99 commented 7 months ago

Hi!

When I try to record a video with both my main screen and camera recorded in 4k quality, the output i a very laggy mp4 file (and I have to wait a long time for the camera to stop).

VideoEncoderOptions = new VideoEncoderOptions { FrameRate = 60, IsFixedFramerate = true }

the resolution is 3840x2160.

When i set the FrameRate to 30, there is no problem btw, but both my camera and screen able to show 4K quality with 60hz and and I would like to use the maximum quality in the recording.

I tried all the possible variation to avoid this lagg, but I didn't succeed. Could you recommend some settings or another approach to avoid lag and keep the recording in 4K 60hz quality?

sskodje commented 7 months ago

Hi! It sounds like the video encoder is not able to process the frames fast enough, causing frames to be backed up or dropped. This library uses the Windows Media Foundation codecs, so i don't have any direct control over the encoder used. It depends on your system and hardware.

Something you can try is disabling fixed framerate. This setting forces the encoder to write 60 frames per second, even when it does not need to update that often. Generally though, high resolution, high bitrate video is very demanding to encode in real time. I don't think you can expect much more performance than the default settings.

tamasbito99 commented 7 months ago

I see, thanks for the quick reply!