capture-kit
is a framework written in Objective-C that provides functions that can be used to capture the contents of a screen.
- Create a new instance of
NVCaptureService
that encompasses screen capturing functionality.
NVCaptureService *captureService = [[NVCaptureService alloc] init];
- Set a delegate to receive recording-related events:
captureService.delegate = self;
- An optional step: If you want to capture microphone sound, you need to obtain a microphone ID. To do this, create a new instance of
NVAudioService
that provides a list of connected device IDs.
NVAudioService *audioService = [[NVAudioService alloc] initWithMediaDeviceProvider:[NVMediaDeviceProvider new]];
NSArray<NSString *> *ids = [audioService audioDevicesIDs];
You can also check whether an audio device is connected to the system like this:
BOOL isConnected = [audioService isAudioDeviceConnected:@"<device_id_here>"];
- Start screen capture
NSRect sampleRect = CGRectMake(0, 0, 1200, 1800);
NSURL *sampleURL = [[NSURL alloc] initWithString:@"file_url"];
[_captureService startRecordingWithAudioDeviceID:@"<device_id_here>"
rect:sampleRect
directDisplayID:kCGDirectMainDisplay
outputFileURL:sampleURL];
Also, you can pass a custom capture configuration using objc - (void)startRecordingWithConfiguration:deviceID:rect:directDisplayID:outputFileURL:
- For pausing, resuming, and cancelling, you can use the following methods:
- (void)pause
- (void)resume
- (void)stop
- macOS 11.0+
- Xcode 14.0
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
Bootstrapping development environment
make bootstrap
Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!
Nikita Vasilev, nv3212@gmail.com
capture-kit is available under the MIT license. See the LICENSE file for more info.