smasherprog / screen_capture_lite

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

Capturing section #35

Closed hardillb closed 6 years ago

hardillb commented 6 years ago

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?

smasherprog commented 6 years ago

Its probably a bug that ill take a look at tomorrow and get it fixed shortly.

smasherprog commented 6 years ago

You can take a stab at a fix if you want. There is only file to take a look at.. https://github.com/smasherprog/screen_capture_lite/blob/master/src/ios/CGFrameProcessor.cpp

Its probably line 26 that needs to be removed.

hardillb commented 6 years ago

It looks a bit more subtle than just removing the test at line 26. It looks to fail freeing if I remove that line. I'll keep poking

smasherprog commented 6 years ago

Not feeling well today so ill have to tackle this tomorrow.. The solution has to be easy through.. within that file

smasherprog commented 6 years ago

starting my mac up now to check this out.

smasherprog commented 6 years ago

just committed to master a fix for the mac build.. Try it out

hardillb commented 6 years ago

I've just tried it and I'm now I just get full frame images not the cropped section. If I put the following line into the example onNewFrame lambda:

std::cout << Width(img) << "x" << Height(img) << std::endl;

I get 3360x2100 out not 512x512

smasherprog commented 6 years ago

I see your errors I am fixing them now. . . I dont work on mac much which is why this fell through

hardillb commented 6 years ago

No problem, thanks for looking at this. Finding a cross platform library has made the task I had solve so much easier.

smasherprog commented 6 years ago

I think its fixed in master for the mac now... Please try it and let me know

hardillb commented 6 years ago

Looks good, now to just work out why I can send 32k UDP packets from Linux but not from my Mac.

Thanks a lot for the help.

I'll probably stick in another pull request up update the .gitignore file so it doesn't moan about the cmake files and the built binaries.

smasherprog commented 6 years ago

Sure.. I put all of my cmake stuff in a folder called build which is ignored

hardillb commented 6 years ago

OK, so it was so close. The width x height is looking good, but the offset doesn't seam to be being applied. So I'm always getting the top left hand corner.

smasherprog commented 6 years ago

This is for capturing of a monitor, not a window, correct?

smasherprog commented 6 years ago

can you post your CreateCaptureConfiguration section where you define the monitors/sections to gather?

Just in case you are using this for a window, I dont support partial capturing for windows.

hardillb commented 6 years ago

This is for the whole monitor not a window. I'll post code in a min (need to boot the other machine)

hardillb commented 6 years ago
  framegrabber = SL::Screen_Capture::CreateCaptureConfiguration([args]() {
    auto mons = SL::Screen_Capture::GetMonitors();
    //TODO pick region
    for (auto &m : mons) {
    // //   // capture just a 128x128 square...  USERS SHOULD MAKE SURE bounds are
    // //   // valid!!!!
      m.OffsetX += args->x;
      m.OffsetY += args->y;
      m.Height = args->height;
      m.Width = args->width;
      std::cout << m << std::endl;
    }
    return mons;
  })

where args is

  args->width = 128;
  args->height = 128;
  args->x = 128;
  args->y = 128;
  args->frames = 10;
  args->mode = false;
  args->broadcast =false;
  args->port = 9100;
  args->host = "127.0.0.1";
smasherprog commented 6 years ago

Ok ill take a look when I get home in a few hours.

smasherprog commented 6 years ago

I see the error in code.. It will take about an hour to fix

smasherprog commented 6 years ago

OK i committed code to master. Try that out and see how it works..

hardillb commented 6 years ago

Looking better, it seams to be applying the x offset but not the y

smasherprog commented 6 years ago

Added the yoffset in master as well.

smasherprog commented 6 years ago

Didnt test this on my mac, but it should be correct. Just had to advance to the correct start row.

smasherprog commented 6 years ago

Thanks for your help with this btw. I only test on mac every once and a while so this really helps.

hardillb commented 6 years ago

Looks good now. Thanks

smasherprog commented 6 years ago

cool