Reputation: 23
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
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