Code Monkey home page Code Monkey logo

screen_capture_lite's Introduction

Above Logo created by https://github.com/mansya

Master is where development happens and should NOT be considered stable. Use tags for stable releases.

Window/Linux/Mac

Cross-platform screen and window capturing library

No External Dependencies except:

linux: sudo apt-get install libxtst-dev libxinerama-dev libx11-dev libxfixes-dev

Platforms supported:

  • Windows 7 and Up
  • MacOS
  • Linux

The image format is raw BGRA 32 bits per pixel. Alpha is unused for onNewFrame and onFrameChanged except for onMouseChanged where it IS USED!

The data exists like this if you were to march through with a for loop [A,R,G,B], [A,R,G,B], [A,R,G,B]. For a read on why this is check out the post here post here

Examples

c++

https://github.com/smasherprog/screen_capture_lite/blob/master/Example_CPP/Screen_Capture_Example.cpp

//Setup Screen Capture for all monitors
auto framgrabber =  SL::Screen_Capture::CreateCaptureConfiguration([]() {
//add your own custom filtering here if you want to capture only some monitors
    return SL::Screen_Capture::SCL_GetMonitors();
  })->onFrameChanged([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {
  
  })->onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {
  
  })->onMouseChanged([&](const SL::Screen_Capture::Image* img, const SL::Screen_Capture::MousePoint &mousepoint) {
  
  })->start_capturing();

framgrabber->SCL_SetFrameChangeInterval(std::chrono::milliseconds(100));//100 ms
framgrabber->SCL_SetMouseChangeInterval(std::chrono::milliseconds(100));//100 ms


//Setup Screen Capture for windows that have the title "cmake" in it
auto windowframgrabber =  SL::Screen_Capture::CreateCaptureConfiguration([]() {
  auto windows = SL::Screen_Capture::SCL_GetWindows();
  std::string srchterm = "cmake";
  // convert to lower case for easier comparisons
  std::transform(srchterm.begin(), srchterm.end(), srchterm.begin(), [](char c) { return std::tolower(c, std::locale());});
  decltype(windows) filtereditems;
  for(auto& a : windows) {
    std::string name = a.Name;
    std::transform(name.begin(), name.end(), name.begin(), [](char c) {return std::tolower(c, std::locale()); });
    if(name.find(srchterm) != std::string::npos) {
      filtereditems.push_back(a);
    }
  }
  return filtereditems;
  })->onFrameChanged([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Window& window) {
  
  })->onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Window& window) {
  
  })->onMouseChanged([&](const SL::Screen_Capture::Image* img, const SL::Screen_Capture::MousePoint &mousepoint) {
  
  })->start_capturing();

windowframgrabber->SCL_SetFrameChangeInterval(std::chrono::milliseconds(100));//100 ms
windowframgrabber->SCL_SetMouseChangeInterval(std::chrono::milliseconds(100));//100 ms

c#

https://github.com/smasherprog/screen_capture_lite/blob/master/Example_CSharp/Program.cs

//Setup Screen Capture for all monitors
var framgrabber = SL.Screen_Capture.CaptureConfiguration.CreateCaptureConfiguration(() =>
{
   var mons = SL.Screen_Capture.SCL_GetMonitors();
   Console.WriteLine("Library is requesting the list of monitors to capture!");
   for (int i = 0; i < mons.Length; ++i)
   {
	   WriteLine( mons[i]);
   }
   return mons;
}).onNewFrame(( SL.Screen_Capture.Image img,  SL.Screen_Capture.Monitor monitor) =>
{

}).onFrameChanged(( SL.Screen_Capture.Image img,  SL.Screen_Capture.Monitor monitor) =>
{

}).onMouseChanged((SL.Screen_Capture.Image img, SL.Screen_Capture.MousePoint mousePoint) =>
{ 

}).start_capturing();
framgrabber.SCL_SetFrameChangeInterval(100);
framgrabber.SCL_SetMouseChangeInterval(100);


//Setup Screen Capture for windows that have the title "google" in it
var framgrabber = SL.Screen_Capture.CaptureConfiguration.CreateCaptureConfiguration(() =>
{
	var windows = SL.Screen_Capture.SCL_GetWindows();
	Console.WriteLine("Library is requesting the list of windows to capture!");
	for (int i = 0; i < windows.Length; ++i)
	{
		WriteLine(windows[i]);
	}
	return windows.Where(a => a.Name.ToLower().Contains("google")).ToArray();
}).onNewFrame(( SL.Screen_Capture.Image img,  SL.Screen_Capture.Window monitor) =>
{ 

}).onFrameChanged(( SL.Screen_Capture.Image img,  SL.Screen_Capture.Window monitor) =>
{ 
}).onMouseChanged(( SL.Screen_Capture.Image img,  SL.Screen_Capture.MousePoint mousePoint) =>
{
	  
}).start_capturing();

framgrabber.SCL_SetFrameChangeInterval(100);
framgrabber.SCL_SetMouseChangeInterval(100);

Library Usage

Only define what you are interested in. Do not define a callback for onMouseChanged if you dont want that information. If you do, the library will assume that you want mouse information and monitor that --so DONT!

Again, DONT DEFINE CALLBACKS FOR EVENTS YOU DONT CARE ABOUT. If you do, the library will do extra work assuming you want the information.

The library owns all image data so if you want to use it for your own purpose after the callback has completed you MUST copy the data out!

Each monitor or window will run in its own thread so there is no blocking or internal synchronization. If you are capturing three monitors, a thread is capturing each monitor.

ICaptureConfiguration

Calls to ICaptureConfiguration cannot be changed after start_capturing is called. You must destroy it and recreate it!

  • ICaptureConfiguration::onNewFrame: This will call back when a new frame is ready on the interval specified in SCL_SetFrameChangeInterval
  • ICaptureConfiguration::onFrameChanged: This will call back when differences are detected between the last frame and the current one. This is usefull when you want to stream data that you are only sending what has changed, not everything!
  • ICaptureConfiguration::onMouseChanged: This will call back when the mouse has changed location or the mouse image has changed up to a maximum rate specified in SCL_SetMouseChangeInterval

IScreenCaptureManager

Calls to IScreenCaptureManager can be changed at any time from any thread as all calls are thread safe!

  • IScreenCaptureManager::SCL_SetFrameChangeInterval: This will set the maximum rate that the library will attempt to capture frame events.
  • IScreenCaptureManager::SCL_SetMouseChangeInterval: This will set the maximum rate that the library will attempt to capture mouse events.
  • IScreenCaptureManager::pause: all threads will stop capturing.
  • IScreenCaptureManager::SCL_IsPaused: obvious!
  • IScreenCaptureManager::SCL_Resume: all threads will SCL_Resume capturing.

screen_capture_lite's People

Contributors

0xd34d10cc avatar ababo avatar akshit-sharma avatar bradybrenot avatar brechtsanders avatar delmottea avatar dependabot[bot] avatar hardillb avatar ijonglin avatar joeludwig avatar ludos1978 avatar mansya avatar matthewbartos avatar morya avatar oktonion avatar perara avatar ptwohig avatar randomprototypes avatar renardjojo avatar retrozelda avatar smasherprog avatar tarcisioe avatar timgates42 avatar wwwmadwww avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

screen_capture_lite's Issues

Black screenshots in full screen mode

I tried to capture sceenshots from League of Legends window and it works only in windowed mode, while fullscreen mode dumps black images.
Should I workaround fullscreen mode somehow or it should work out of the box? In the latter case I'll provide more info to reproduce the bug.

The frame rate

I use the demo has a low frame rate.Almost 2fps at macos,why?
And how can I include the library to JNI?

Cannot capture screen: System is constantly in a transition state

Hello!
Trying to use the example code I'm constantly receiving an expected error from ThreadManager:67.

Starting Capture Demo
Exiting Thread due to expected error 
Exiting Thread due to expected error
Exiting Thread due to expected error
...

I'm running the script using CLion 2016.3 and OS X 10.12.3.

I would appreciate any support on this issue!

Window title missing first char on Windows

What's the reason in src/windows/GetWindows.cpp, the function EnumWindowsProc puts a \n at the beginning of the window title retrieved? When I use it to get window titles, every first char is somehow missing. For example, window title "Task Manager" is incorrectly set as "\nask Manager". The issue apparently can be solved by simply removing the line w.Name[textlen] = '\n';.

Add DEBUG only log

in ThreadRunner.cpp these logs should be debug only.

#ifdef _DEBUG
            std::cout << "Starting to Capture on Monitor " << Name(monitor) << std::endl;
            std::cout << "Trying DirectX Desktop Duplication " << std::endl;
#endif

#ifdef _DEBUG
                std::cout << "DirectX Desktop Duplication not supprted, falling back to GDI Capturing . . ." << std::endl;
#endif

New logo / icon

Hi, I am a graphic designer, I want to help others in graphic design.

After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new logo / icon. what do you think?

Mac Partial Capture needs implementation

I have to do more bounds checking on the captured monitors...
Mac isnt implemented yet. Might be a performance looser for the mac platform.. need to do research on this.
Windows and linux are implemented. Windows could use a little more cleanup.

Linker Error in Screen capture Example program

untitled
Unable to compile it please help
Screen_Capture_Example.obj : error LNK2019: unresolved external symbol "public: __cdecl SL::Screen_Capture::ScreenCaptureManager::ScreenCaptureManager(void)" (??0ScreenCaptureManager@Screen_Capture@SL@@qeaa@XZ) referenced in function main

why BGRA is used instead of just BGR?

May I ask a (stupid) question? Why does this library use 4 channels instead of just 3 for capturing screenshots?

When is the alpha channel not entirely filled with 255? I'm asking because I'm trying to push the boundary of the capture frame rate, and I thought maybe using just 3 channels would be more efficient, also out of curiosity.

I saw that you mentioned the alpha channel is used in onMouseChanged, could you please elaborate what exactly the alpha channel represents in onMouseChanged?

Thanks.

Microseconds interval

Hello,

this is a great and very useful library, i would like to know if microseconds capture interval is possible ?

I would like to achieve < 1 millisecond intervals How would you achieve this ? Right now when capturing a single screen with 1 millisecond interval i am at 260 FPS which is around 4 milliseconds, this is already great but barely enough for my needs, i am just using onNewFrame callback.

Also, i tried to capture a tiny part of the screen by implementing the CreateMonitor function to see if that make a difference but it seem it crashed, how can i capture a specific part of the screen ? Will it make a speed difference ?

Thank you by advance.

Screen capturing is broken on OS X devices

Hello!
Current implementation of CGFrameProcessor::ProcessFrame() seems to be unreliable and, sometimes, completely broken.
Apple CG's documentation is far from complete, but here are some points i discovered while trying to make screenshot myself:

  1. Image width may be actually smaller, than pixels per row in image data. (this was my main problem)
  2. Image bitmap data might be stored in different formats across different devices.

How to deal with that?

Here is how I deal with these problems:

// First, capture the image
CGImageRef const capturedImage = /* any way of capturing image, be it CGWindowListCreateImage or CGDisplayCreateImage */;

// Second, get bitmap and alpha data info
CGBitmapInfo const bitmapInfo = CGImageGetBitmapInfo(capturedImage);
CGImageAlphaInfo const alphaInfo = CGImageGetAlphaInfo(capturedImage);

In order to do screenshots on any platform, one must be ready to handle any combination of bitmap and alpha structures.
Now I will only look at 32-bit Little-Endian bitmap format with Alpha being the first byte.
Note that alpha is unused in screenshot capturing, so we should not care about its representation.

// Ensure 32-bit LE
assert(bitmapInfo & kCGBitmapByteOrder32Little);
// Ensure alpha is at the first byte and has any format (we'll just skip it while reading)
assert(
    alphaInfo == kCGImageAlphaFirst ||
    alphaInfo == kCGImageAlphaNoneSkipFirst ||
    alphaInfo == kCGImageAlphaPremultipliedFirst);

Many implementations add padding at the end of each pixel row. In my case (1366x768 screen), it was 10 completely transparent pixels.

// Get real image width and height, this has NOTHING to do with size of image data provided
std::size_t const width = CGImageGetWidth(capturedImage);
std::size_t const height = CGImageGetHeight(capturedImage);

// This is the actual row size. Many implementations add some padding at the end of each row
std::size_t const bytesPerRow = CGImageGetBytesPerRow(capturedImage);

std::size_t const bytesPerPixel = CGImageGetBitsPerPixel(capturedImage) / 8u;
std::size_t const pixelsPerRow = bytesPerRow / bytesPerPixel;

Now let's get the data provider and copy all the data from it:

GDataProviderRef const dataProvider = CGImageGetDataProvider(capturedImage);
if (!dataProvider) {
    // Handle this. I think that this can only happen if the passed CGImageRef was NULL
}

// As this will copy the data, it needs to be freed separately from the captured image.
CFDataRef const rawPixelData = CGDataProviderCopyData(dataProvider);

Then the data can be accessed as you like. Make sure to take into account bitmap and alpha info and perform all needed conversions for library's internal format

// Cast the byte pointer to whatever you like
uint32_t const * const dataPointer = reinterpret_cast<uint32_t const *>(CFDataGetBytePtr(rawPixelData));

// And access it like this:
for (unsigned row = 0; row < height; ++row) {
    for (unsigned column = 0; column < width; ++column) {
        // Note that pixelsPerRow includes padding pixels
        /* whatever */ = dataPointer[row * pixelsPerRow + column];
    }
}

Also note that src/ios/CGFrameProcessor.cpp is a mix of 4-space and tab-character indentation. This is an important issue, as tabulation character may be displayed as four, two or even eight spaces.

"Unexpected error" when starting certain applications during screen capture, causing capture to abort

Hi again! :) I'm using your excellent library to build an always-on screen frame grabber for a personal project. I have a Qt application window outputting the captured frames, and I was displaying it on my second monitor while I tried to do some common tasks on my main display which was being captured.

I found that launching certain applications (example: "The Guild 2: Renaissance," which is an older game) resulted in the capture stopping until I started it up again. To be clear, the capture stopped as the application started up, but I could alt+tab away and re-start the capture once the game had loaded. I traced the problem to a DXGI_ERROR_INVALID_CALL from _DuplLock->ReleaseFrame()

auto hr = _DuplLock->ReleaseFrame();
which eventually causes the thread to stop as it's not in the list of expected errors.

For my own purposes, adding DXGI_ERROR_INVALID_CALL to FrameInfoExpectedErrors[]

// These are the errors we expect from IDXGIOutputDuplication methods due to a transition
HRESULT FrameInfoExpectedErrors[] = {
DXGI_ERROR_DEVICE_REMOVED,
DXGI_ERROR_ACCESS_LOST,
S_OK // Terminate list with zero valued HRESULT
};
allowed capture to continue during the start-up and into the game. I'm not sure if this is an appropriate solution, but FYI in either case.

Last updates broke Linux

The last set of updates seam to have broken Linux.

When I call ExtractAndConvertToRGB or ExtractAndConvertToRGB565 I'm getting a sigsegv.

For a 128x128 image it looks like it's managing to process the first 2 lines (so the address returned for img.Data is at 256 bytes before somewhere it can't access) but falls over trying to access the first pixel of the 3rd line.

Unresolved external symbol __imp__DwmGetWindowAttribute@16 when using .lib file on Windows.

I have exported the library on a Windows machine, but when I try to use it, I get the following error:
Error LNK2019 unresolved external symbol __imp__DwmGetWindowAttribute@16 referenced in function "struct SL::Screen_Capture::WindowDimensions __cdecl SL::Screen_Capture::GetWindowRect(struct HWND__ *)" (?GetWindowRect@Screen_Capture@SL@@YA?AUWindowDimensions@12@PAUHWND__@@@Z)

Steps to reproduce:

  1. Run cmake CMakeLists.txt to produce Visual Studio project.
  2. Open screen_capture_lite.sln (Using Visual Studio 2017).
  3. Right click on screen_capture_lite.vcxproj, and select Build.
  4. Create a new Console Application in Visual Studio.
  5. Add the include folder and the .lib file to the project directory of the Console Application.
  6. In Project Properties, add the include folder in C/C++>>General>>Additional Include Directories, and the .lib file in Linker>>Input>>Additional Dependencies.
  7. Add code that uses the library in main.cpp (I copied the createwindowgrabber() function, removing some parts like the call to setMouseChangeInterval() and invoked createwindowgrabber() in main(). I will post full code if deemed helpful).
  8. Attempt to compile.

EnumWindows in GetWindows() crashes when encountering weird process name.

On Visual Studio 2017, When I tried the GetWindowFrame example, at the point where the EnumWindows() enumerates through processes it encounters a weird title name which crashes the program.
devenv_2018-09-21_12-30-29

Here is the weird name string:
devenv_2018-09-21_12-36-11
I tested this part of the code seperately in CodeBlocks and it worked but it crashed in VS2017 but works on changing the type of name in Window struct from char[] to std::string.

What should I do if I don't want to simply change the type? Another possible fix I can think of is check if the int value of char is < 0 and then change the string.

Segmentation fault 11

I'm trying to launch the example in Mac OS terminal, so I get this error:

$ ./Example/screen_capture_example
Starting Capture Demo/Test
Testing captured monitor bounds check
Id=69732992 Index=0 Height=1600 Width=2560 OffsetX=0 OffsetY=0 Name=Monitor 69732992
Id=69732992 Index=0 Height=1601 Width=2560 OffsetX=0 OffsetY=0 Name=Monitor 69732992
Id=69732992 Index=0 Height=1600 Width=2561 OffsetX=0 OffsetY=0 Name=Monitor 69732992
Running display capturing for 10 seconds
Library is requesting the list of monitors to capture!
Id=69732992 Index=0 Height=1600 Width=2560 OffsetX=0 OffsetY=0 Name=Monitor 69732992
onNewFrame fps9
onNewFrame fps10
onNewFrame fps11
onNewFrame fps10
onNewFrame fps11
onNewFrame fps10
onNewFrame fps11
onNewFrame fps11
onNewFrame fps10
Running window capturing for 10 seconds
Running Partial display capturing for 10 seconds
Library is requesting the list of monitors to capture!
Id=69732992 Index=0 Height=512 Width=512 OffsetX=512 OffsetY=512 Name=Monitor 69732992
onNewFrame fps0
Segmentation fault: 11

Mobile devices version

Really waiting for any mobile devices version , It will, be so great framework and library .

Yours.

GetWindows.cpp corrupts stack memory with long window names

Tested on commit (Edit: pasted wrong commit earlier)
5a82135

Running "Screen_Capture_Example" using VS2015, a stack corruption occurs in EnumWindowsProc when the user has a window open with a long title (longer than 128 chars, presumably. In my case the window was a chrome page open to https://github.com/smasherprog/Projects_Setup):

    BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM lParam)
    {
        char buffer[255];
        GetWindowTextA(hwnd, buffer, sizeof(buffer));
        srch *s = (srch *)lParam;
        std::string name = buffer;
        Window w;
        w.Handle = reinterpret_cast<size_t>(hwnd);
        auto windowrect = SL::Screen_Capture::GetWindowRect(hwnd);
        w.Position.x = windowrect.ClientRect.left;
        w.Position.y = windowrect.ClientRect.top;
        w.Size.x = windowrect.ClientRect.right - windowrect.ClientRect.left;
        w.Size.y = windowrect.ClientRect.bottom - windowrect.ClientRect.top;

        memcpy(w.Name, name.c_str(), name.size() + 1);
        s->Found.push_back(w);
        return TRUE;
    }

buffer is a 255 char array but w.Name is only 128 chars. Re-organizing the code to:

    BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM lParam)
    {
        Window w;
        char buffer[sizeof(w.Name)];
        GetWindowTextA(hwnd, buffer, sizeof(buffer));
        ...

fixes the issue and guards against changes to the size of w.Name in the future.

Note also that a compilation issue occurred in GDIFrameProcessor.cpp at ImageRect rect = { 0 }; but presumably this is not a problem for VS2017.

no callback to call on frame tick.

I was checked that OnNewFrame callback only calls when mouse change or desktop change. if everything does not change then it will not be called. that make my record data unable to continue if screen image not moving.
is there any change i can get a callback like OnFrameTick(Image img, .. ) if img not change then still use last frame.

xHotspot and yHotspot

In onMouseChanged, the location of the cursor is provided, but xHotspot and yHotspot are not provided. Can it be provided?

windows 10 duplication api error

HI ,
I am getting following error when I try to capture screen on some systems .
Failed to get duplicate output in DUPLICATIONMANAGER Error
DirectX Desktop Duplication not supprted, falling back to GDI Capturing . . .

Refactor implementation

There is alot of code which is the same on all of the different platforms. It should be refactored

Add some Extract and Convert

here is some more extract and convert would be useful to stream.

inline void ExtractAndConvertToRGB(const Image& img, char* dst, size_t dst_size)
		{
			auto totalsize = Width(img) * 3 * Height(img);
			assert(dst_size >= static_cast<size_t>(totalsize));
			auto imgsrc = StartSrc(img);
			auto imgdist = dst;
			for (auto h = 0; h < Height(img); h++) {
				for (auto w = 0; w < Width(img); w++) {
					*imgdist++ = *(imgsrc + 2);
					*imgdist++ = *(imgsrc + 1);
					*imgdist++ = *(imgsrc);
					imgsrc += img.Pixelstride;
				}
				imgsrc += RowPadding(img);
			}
		}

		inline void ExtractAndConvertToRGB565(const Image& img, char* dst, size_t dst_size)
		{
			auto totalsize = Width(img) * 2 * Height(img);
			assert(dst_size >= static_cast<size_t>(totalsize));
			auto imgsrc = StartSrc(img);
			auto imgdist = dst;
			for (auto h = 0; h < Height(img); h++) {
				for (auto w = 0; w < Width(img); w++) {
					int short rgb = (*(imgsrc + 2) << 11) | (*(imgsrc + 1) << 5) | *(imgsrc);
					*imgdist++ = rgb;
					*imgdist++ = rgb << 8;
					imgsrc += img.Pixelstride;
				}
				imgsrc += RowPadding(img);
			}
		}

Using in QtCreator

Hello,

I am having troubles using this in QtCreator.
I have tried compiling it in VS2015, it works.

But I also get Linking Errors in QtCreator.
Can't I just include the headers and compile it into my application?

I have no idea at the moment where to start.

Windows I am getting 10 fps

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();
`  

DXGI issues: EnumDisplayDevices mismatch, and rotated monitors

  1. screen_capture_lite assumes capture will only happen on the first DXGI adapter, and that the order of outputs from DXGI matches the order of outputs that it gets from EnumDisplayDevices.
    • These assumptions don't hold; apparently depending on where on my video card I plug things into, the ordering of outputs is wrong, and I've got reports from users with laptops with hybrid GPUs who I think are suffering from the "only adapter 0" assumption, but this is hard to confirm as I don't have any such hardware.
  2. monitors rotated by 90 or 270 degrees have width/height flipped. That's as you'd expect, except DXGI gives us a surface with an un-rotated image, which screen_capture_lite can choke on as ProcessFame is assuming it's rotated.

I have a PR I'll attach shortly, not sure if the approach is one you'd want to take straight in though. It also doesn't really fix (2), in that it allows screen_capture_lite to at least work in that case (which it wasn't), but the image it gives the client is still unrotated.

Set Wallpaper when capturing

While capturing it is usually beneficial if the wallpaper changes to a color. I think this is a good feature to add in the future.

onNewFrame is switching between monitors

Hello,

i have updated the library in my project and my "old" code don't work as expected anymore, it seem that each call of "onNewFrame" switch between monitors instead of capturing all the monitors in one go. Any ideas on how to capture all monitors in one call of "onNewFrame" ?

SL::Screen_Capture::CreateCaptureConfiguration([&]() {
      auto monitors = SL::Screen_Capture::GetMonitors();

      for (auto &monitor : monitors) {
        //capture_width += monitor.Width;
        //capture_height = monitor.Height;
      }

      return monitors;
    })
onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {
    auto startsrc = StartSrc(img);
    auto capture_data_len = RowStride(img) * Height(img);
    std::memcpy(capture_data, startsrc, capture_data_len);
}})

Thank you.

internal/SCCommon.h also for production?

Hello!

I've tried this library in a project for of mine and really like it (simple, fast and cross platform). However, there is one thing that can't really put together. In the example and internal/SCCommon.h file it's written:

//DONT USE THIS HEADER IN PRODUCTION CODE!!!! ITS INTERNAL FOR A REASON IT WILL CHANGE!!! ITS HERE FOR TESTS ONLY!!!

But if I skip this header I get an error:

Error C2036 'SL::Screen_Capture::Monitor *const ': unknown size ScreenCapture

Which makes sense since structs Point, Monitor, Window and Image are defined only in SCCommon.h file. If skipped, included ScreenCapture.h only does forward declaration, hence compiler doesn't know the size of it.

So finally my question is, how to correctly use this library without SCCommon.h and successful compilation?

Thanks!

My environment: Win10 x64, VS2017 (currently doing only 32bit compilation).

ExtractAndConvertToRGB565 doesn't work

While playing with the library I tried out the ExtractAndConvertToRGB565 method and it wasn't giving me the output I was expecting.

It looks like there is no bit width reduction going on and the shifting looked wrong. I'm going to have a go at fixing it and I'll stick in a pull request.

Capturing section

I'm trying to get capturing just a small area of the screen to work and I'm having some issues.

The example seams to have some code commented out that should do this but when I uncomment it I get an error at runtime.

SL::Screen_Capture::CreateCaptureConfiguration([]() {
  auto mons = SL::Screen_Capture::GetMonitors();
  std::cout << "Library is requesting the list of monitors to capture!" << std::endl;
  for (auto &m : mons) {
    // capture just a 512x512 square...  USERS SHOULD MAKE SURE bounds are
    // valid!!!!
    m.OffsetX += 128;
    m.OffsetY += 128;
    m.Height = 128;
    m.Width = 128;
    std::cout << m << std::endl;
  }
  return mons;
 })

I get this:

Id=69733378 Index=0 Height=2100 Width=3360 OffsetX=0 OffsetY=0 Name=Monitor 69733378
Id=69733378 Index=0 Height=128 Width=128 OffsetX=128 OffsetY=128 Name=Monitor 69733378
Exiting Thread due to expected error 
Id=69733378 Index=0 Height=128 Width=128 OffsetX=128 OffsetY=128 Name=Monitor 69733378
Exiting Thread due to expected error 
Id=69733378 Index=0 Height=128 Width=128 OffsetX=128 OffsetY=128 Name=Monitor 69733378

128x128 at 128x128 should be with in the bounds of the montior

I'm on Mac if it makes any difference.

Any suggestions as what I need to change?

newbie question

Any example of how to compile the sources of the example?
thanks

Mac OS build fail

Hi, build fails on Mac OS Sierra.
cmake generation passees ok, but on the build phase I'm getting:

bash-3.2$ cmake --build . Scanning dependencies of target screen_capture_lite [ 6%] Building CXX object CMakeFiles/screen_capture_lite.dir/src/ScreenCapture.cpp.o [ 13%] Building CXX object CMakeFiles/screen_capture_lite.dir/src/SCCommon.cpp.o [ 20%] Building CXX object CMakeFiles/screen_capture_lite.dir/src/ThreadManager.cpp.o [ 26%] Building CXX object CMakeFiles/screen_capture_lite.dir/src/ios/GetWindows.cpp.o [ 33%] Building C object CMakeFiles/screen_capture_lite.dir/src/ios/NSMouseCapture.m.o [ 40%] Building CXX object CMakeFiles/screen_capture_lite.dir/src/ios/NSFrameProcessor.cpp.o [ 46%] Building CXX object CMakeFiles/screen_capture_lite.dir/src/ios/NSFrameProcessor.mm.o /Users/admin/moba/screen_capture_lite/src/ios/NSFrameProcessor.mm:73:36: error: property 'enabled' not found on object of type 'id' self.output.connections[0].enabled = NO; ^ /Users/admin/moba/screen_capture_lite/src/ios/NSFrameProcessor.mm:80:36: error: property 'enabled' not found on object of type 'id' self.output.connections[0].enabled = YES; ^ 2 errors generated. make[2]: *** [CMakeFiles/screen_capture_lite.dir/src/ios/NSFrameProcessor.mm.o] Error 1 make[1]: *** [CMakeFiles/screen_capture_lite.dir/all] Error 2 make: *** [all] Error 2

bash-3.2$ c++ --version Apple LLVM version 9.0.0 (clang-900.0.39.2) Target: x86_64-apple-darwin16.0.0

Or am I doing something wrong?

Add faster callback functions

There are cases where serious performance improvements can be gained in certain situations.
If the user is only interested in capturing the entire screen and the screen does not have pixel padding in the native image, then the native, raw image can be passed directly back to the user. This will avoid memory allocations, and skip a copy of the image.

Android Support

Hello , please does the screen-capture lite support the Android Dev ? .

so many thanks ,
Yours,Randy

c++14 only?

Hi,

This look good, but it appears to be c++14 only, is this correct?

Any chance it could be 'fixed' to work with c++11?

Bye!
Mark

cannot compile the Exemple

Determining if the pthread_create exist failed with the following output:
Change Dir: /home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_eb3eb/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_eb3eb.dir/build.make CMakeFiles/cmTC_eb3eb.dir/build
gmake[1]: Entering directory '/home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_eb3eb.dir/CheckSymbolExists.c.o
/usr/lib64/ccache/cc -o CMakeFiles/cmTC_eb3eb.dir/CheckSymbolExists.c.o -c /home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_eb3eb
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_eb3eb.dir/link.txt --verbose=1
/usr/lib64/ccache/cc -rdynamic CMakeFiles/cmTC_eb3eb.dir/CheckSymbolExists.c.o -o cmTC_eb3eb
CMakeFiles/cmTC_eb3eb.dir/CheckSymbolExists.c.o: In function main': CheckSymbolExists.c:(.text+0x16): undefined reference to pthread_create'
collect2: error: ld returned 1 exit status
gmake[1]: *** [CMakeFiles/cmTC_eb3eb.dir/build.make:87: cmTC_eb3eb] Error 1
gmake[1]: Leaving directory '/home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:126: cmTC_eb3eb/fast] Error 2

File /home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_4dd6c/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_4dd6c.dir/build.make CMakeFiles/cmTC_4dd6c.dir/build
gmake[1]: Entering directory '/home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_4dd6c.dir/CheckFunctionExists.c.o
/usr/lib64/ccache/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_4dd6c.dir/CheckFunctionExists.c.o -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTC_4dd6c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_4dd6c.dir/link.txt --verbose=1
/usr/lib64/ccache/cc -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_4dd6c.dir/CheckFunctionExists.c.o -o cmTC_4dd6c -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
gmake[1]: *** [CMakeFiles/cmTC_4dd6c.dir/build.make:87: cmTC_4dd6c] Error 1
gmake[1]: Leaving directory '/home/src/screen_capture_lite/Example/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:126: cmTC_4dd6c/fast] Error 2

libpthread is installed on my system (Fedora 27 64bit
/usr/lib/libpthread-2.26.so
/usr/lib/libpthread.so
/usr/lib/libpthread.so.0
/usr/lib/libpthread_nonshared.a
/usr/lib/debug/lib64/libpthread-2.20.so.debug
/usr/lib/debug/lib64/libpthread.so.0.debug
/usr/lib/debug/usr/lib64/libpthread.a
/usr/lib/debug/usr/lib64/libpthread_nonshared.a
/usr/lib/i686/nosegneg/libpthread-2.26.so
/usr/lib/i686/nosegneg/libpthread.so.0
/usr/lib64/libpthread-2.26.so
/usr/lib64/libpthread.a
/usr/lib64/libpthread.so
/usr/lib64/libpthread.so.0
/usr/lib64/libpthread_nonshared.a

it is possible to send you a PM? I would like to make you a proposition
thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.