macos - osx 上的屏幕截图

标签 macos video-streaming screen-capture

<分区>

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

最佳答案

这是一个示例代码,用于捕获屏幕并将其保存为对我有用的文件。

/**
    Record the current screen to the destination path mentioned.
 **/

-(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 找到示例代码

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

关于macos - osx 上的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14804235/

相关文章:

Java开源捕获包含滚动的页面截图

macos - 如何从 shell 脚本检查 MAC OS X 中启动的进程是否已加载?

iphone - Connect() 从 ios 到同一子网中的 ios 设备

macos - 是否可以将 Perl 与 macOS 应用程序捆绑在一起?

audio - ffmpeg同时输出到多个rtmp

c - 如何将 MP4 (h264/aac) 文件转换为 HDS 的 F4F 片段 (Adobe)

c++ - 使用 MSDN 库进行多屏幕捕获

html - 网页屏幕录制

cocoa - 如何以编程方式为 mac 应用程序设置打印选项的页面布局

video - 在H264中,field_pic_flag是什么意思,和编码间隔有关系吗?