【问题标题】:screen capture on osx [closed]osx上的屏幕截图[关闭]
【发布时间】:2013-01-26 02:06:46
【问题描述】:

我需要流式传输我的 Mac 桌面,让其他人可以观看我在做什么。我尝试过使用 VLC(在当前稳定版本中不再适用)。我已经尝试过 ffmpeg,它不再适用于 osx 上的 x11grab 选项。您知道任何具有屏幕录制和流媒体功能的商业或免费软件吗?或者可以通过管道传输到 ffmpeg 或 vlc 的东西?或者也许你能指出我某个地方来研究如何为 osx 构建一个非常基本的应用程序来捕获屏幕? 谢谢

【问题讨论】:

  • 你读过这个[在 OSX 上用 C++ 捕获屏幕图像][1]?很多链接,尤其是最后一个。 [1]:stackoverflow.com/questions/1537587/…
  • 我编写了这段 C 代码来捕获 Mac 的屏幕并通过函数 glDrawPixels 将其显示在 OpenGL 窗口中:opengl-capture.c pastebin.com/pMH2rDNH

标签: macos video-streaming screen-capture


【解决方案1】:

这是捕获屏幕并将其保存为适合我的文件的示例代码。

/** 将当前屏幕记录到提到的目标路径。 **/

-(void)screenRecording:(NSURL *)destPath {

//Create capture session
mSession = [[AVCaptureSession alloc] init];

//Set session preset
//mSession.sessionPreset = AVCaptureSessionPresetMedium;
mSession.sessionPreset = AVCaptureSessionPreset1280x720;

//Specify display to be captured
CGDirectDisplayID displayId = kCGDirectMainDisplay;

//Create AVCaptureScreenInput with the display id
AVCaptureScreenInput *input = [[AVCaptureScreenInput alloc] initWithDisplayID:displayId];
if(!input) {
    //if input is null
    return;
}

//if input is not null and can be added to the session
if([mSession canAddInput:input]) {
    //Add capture screen input to the session
    [mSession addInput:input];
}

//Create AVCaptureMovieFileOutput
mMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
mMovieFileOutput.delegate = self;

if([mSession canAddOutput:mMovieFileOutput]) {
    //If movie file output can be added to session, then add it the session
    [mSession addOutput:mMovieFileOutput];
}

//Start running the session
[mSession startRunning];

//Check whether the movie file exists already
if([[NSFileManager defaultManager] fileExistsAtPath:[destPath path]]) {
    NSError *err;
    //If the movie file exists already, then delete it
    if(![[NSFileManager defaultManager] removeItemAtPath:[destPath path] error:&err]) {
        NSLog(@"Error deleting existing movie file %@", [err localizedDescription]);
    }
}

//Start recording to destination path using the AVCaptureMovieFileOutput
[mMovieFileOutput startRecordingToOutputFileURL:destPath recordingDelegate:self];

}

您可以在http://developer.apple.com/library/mac/#qa/qa1740/_index.html找到示例代码

请浏览网址。这至少可以帮助您创建捕获屏幕的基本应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 2013-01-10
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    相关资源
    最近更新 更多