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

Non GPU Machines Options not working #298

Closed kasirajansfm closed 5 months ago

kasirajansfm commented 6 months ago

Build an EXE with below options on Windows 10 with GPU machine,

image

its approximate file size is around 400kb. When i try to run same EXE on Windows 10 Non-GPU machine, the file size is around 1.8MB is there anything am missing on my code.? anyone faced this kind of issue?

sskodje commented 6 months ago

Hello! The different encoders have different opinions of things, and one of them is the Quality BitrateMode option. I have noticed the Microsoft sofware encoder will in many cases use a higher bitrate given the same quality number than hardware encoders.

Your code has set the bitrate for the encoder, but you also must set the encoder in "constat bitrate" or CBR mode, for that option to have effect. Quality and Bitrate is mutually exclusive.

For quality (this is default, which is why it works if omitted)

                    VideoEncoderOptions = new VideoEncoderOptions
                    {
                        Encoder = new H264VideoEncoder { BitrateMode = H264BitrateControlMode.Quality },
                        Quality = 30
                    }

for CBR:

                    VideoEncoderOptions = new VideoEncoderOptions
                    {
                        Encoder = new H264VideoEncoder { BitrateMode = H264BitrateControlMode.CBR},
                        Bitrate = 50000
                    }

I think if you change it to CBR, you will see the files have the same size between the two encoders, but probably overall larger size. At least with 50mbit bitrate, which is quite a lot (Blu-ray quality)