smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
619 stars 156 forks source link

Windows I am getting 10 fps #34

Closed peererror closed 6 years ago

peererror commented 6 years ago

Hi, The library is capturing the screen at 10fps on windows 10.Here is the code I am using in On onNewFrame I have also comment out the code but still getting 10fps and its stuck on this number.

onNewFrame([&](const SL::Screen_Capture::Image& img,
        const SL::Screen_Capture::Monitor& monitor) {

        if (closing == true) {
            return;
        }
        //auto start = std::chrono::high_resolution_clock::now();
        //auto r = realcounter.fetch_add(1);
        auto size = RowStride(img) * Height(img);
        unsigned char* imgbuffer = (unsigned char*)malloc(size);
        Extract(img, imgbuffer, size);

        std::shared_ptr<swapBufer> Swapimg = std::make_shared<swapBufer>();
        Swapimg->buffer = imgbuffer;
        Swapimg->len = size;
        {
            boost::mutex::scoped_lock lock(videMutex);
            if (encoderQeue.size() > 2) {
                auto ptr = encoderQeue.back();
                encoderQeue.pop_back();
                free(ptr->buffer);
                ptr->buffer = NULL;
                ptr.reset();
            }
            encoderQeue.push_back(Swapimg);
        //  //std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start).count() << std::endl;
        }
        //Sleep(1);
        //tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());
        if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - onNewFramestart).count() >= 1000) {
            std::cout << "onNewFrame fps" << onNewFramecounter << std::endl;
            onNewFramecounter = 0;
            onNewFramestart = std::chrono::high_resolution_clock::now();
        }
        onNewFramecounter += 1;
    })->start_capturing();
`  
smasherprog commented 6 years ago

The libraries defaults are 10 fps, you need to set it to what you want https://github.com/smasherprog/screen_capture_lite/blob/master/Example/Screen_Capture_Example.cpp#L102

namkazt commented 6 years ago

@smasherprog what is max FPS you got when running on your side ?. im not sure it is my problem or not but i think i only got around 16 FPS :-s even i set framgrabber->setFrameChangeInterval(std::chrono::milliseconds(16));

my pc is not so bad : Nvidia 970 and i7 8700K

smasherprog commented 6 years ago

depends on your OS, screen resolution, and refresh rate.

OS Mac is the slowest. Windows is the next fastest Linux is the fastest

Resolution I run (3) 4k monitors at 60hz which is 3840 2160 4 *3 = 99 MB I capture about 15 -20 ish fps which is good considering how much data is being captured a second. This is 1-2 GB/s screen capturing.

Refresh rate If you have a 30hz refresh rate your BEST rate you can capture is 30fps.. But you will never hit this since there is synchronization that happens inside the OS.

The capturing is all about CPU.

smasherprog commented 6 years ago

Take a peek at the code to help improve the performance, This entire codebase is only a few files so its easy to figure things out..

smasherprog commented 6 years ago

try setting the interval to 0 ms and see what you get without doing any other work...