如何使用FFMPEG在Objective-C中使用FFMPEG记录屏幕



我知道:

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

这将生成一个视频文件。但是如何在XCode中以编程方式进行此操作呢?我正在尝试构建一个支持MacOS中FFMPEG的屏幕录音机。

您可以使用NSTASK启动其他任务,例如:

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.");
}

最新更新