-
-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use AVCaptureVideoDataOutput on capture.py #585
base: main
Are you sure you want to change the base?
Conversation
Via ChatGPT: Given your implementation and the issue you're facing with saving images, a few areas could potentially cause the delegate method not to trigger as expected, thereby not saving the images. Let's review and suggest corrections: 1. Ensure Delegate PersistsOne common issue with delegates in Objective-C (and by extension, when using PyObjC) is the delegate being deallocated if it's not strongly referenced. Since you're using a concurrent futures thread pool executor as the queue for the delegate callbacks, ensure that the delegate instance ( In your self.delegate = VideoDelegate.alloc().init() Then use self.video_data_output.setSampleBufferDelegate_queue_(self.delegate, queue) 2. Confirming Delegate Method SignatureEnsure the method signature in your 3. Debugging Delegate CallsTo verify if the issue lies with the delegate not being called, add more logging inside your delegate method and at key points in your from Foundation import NSLog
class VideoDelegate(NSObject):
def captureOutput_didOutputSampleBuffer_fromConnection_(self, output, sampleBuffer, connection):
NSLog("Delegate method called")
# Your existing code... 4. Thread Pool ExecutorYour use of Change your queue to use a dispatch queue: import objc
self.queue = objc.dispatch_queue_create("videoDataOutputQueue", None)
self.video_data_output.setSampleBufferDelegate_queue_(self.delegate, self.queue) 5. Verify Configuration and Permissions
SummaryAdjust your code to maintain a strong reference to the delegate and use a dispatch queue for the delegate callbacks. Ensure your app has the necessary permissions and add more extensive logging to help pinpoint where the issue might be occurring. If these steps don't resolve the problem, further investigation into the session's configuration and state when trying to start it would be warranted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work @0dm !
I believe the next step is to modify utils.take_screenshot
to return the latest version of this data.
What do you think about accepting a write queue as a parameter to VideoDelegate
? Then that object could optionally be passed into utils.take_screenshot
.
|
||
|
||
class Capture: | ||
"""Capture the screen, audio, and camera on macOS.""" | ||
"""Capture the screen on macOS.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove audio and camera functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't much of a use for those because we aren't capturing movies anymore. I can just duplicate the old file to keep that functionality separate (call it like movie.py) or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it back as a separate class, MovieCapture
e1682ba
ciImage = CIImage.imageWithCVImageBuffer_options_(imageBuffer, None) | ||
bitmapRep = NSBitmapImageRep.alloc().initWithCIImage_(ciImage) | ||
dict = {NSImageCompressionFactor: 1.0} | ||
pngData = bitmapRep.representationUsingType_properties_(NSPNGFileType, dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🚀
@0dm can you please remind me what is the correct way to run this?
|
I don't think it's very easy to work directly with the VideoDelegate object because we cannot call it with arguments, we just pass it to
Running it as a python module doesn't seem to work ( File "/Users/aaron/GitHub/OpenAdapt/openadapt/capture/_macos.py", line 42, in <module>
class VideoDelegate(NSObject):
objc.error: VideoDelegate is overriding existing Objective-C class So the current method is the one you had, |
WIP to resolve #570