sol
sol

Reputation: 23

How to record screen in macOS using FFmpeg in Objective-C?

I know:

# ffmpeg -f avcapture -video_device_index 0 -i "" ~/Desktop/capture.mpeg

This will generate a video file. But how to do this programmatically in Xcode? I am trying to build a screen recorder which supports FFmpeg in macOS.

Upvotes: 1

Views: 660

Answers (1)

Maarten Foukhar
Maarten Foukhar

Reputation: 359

You can use NSTask to launch other tasks, for example:

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/local/bin/ffmpeg"]; // Path to ffmpeg, if included in the resources [[NSBundle mainBundle] pathForResource:@"ffmpeg" ofType:""]
[task setArguments:@[@"-f", @"avcapture", @"-video_device_index", @"0", @"-i", @"\"", @"~/Desktop/capture.mpeg"]];    
[task launch];     
[task waitUntilExit];

int status = [task terminationStatus];
if (status == 0)
{
     NSLog(@"Task succeeded.");
}
else
{
    NSLog(@"Task failed.");
}

Upvotes: 2

Related Questions