在使用AVCaptureMovieFileOutput保存之前修改AVCaptureSession [英] Modify AVCaptureSession before saving with AVCaptureMovieFileOutput

查看:87
本文介绍了在使用AVCaptureMovieFileOutput保存之前修改AVCaptureSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例::我想捕获来自摄像机的输入,在捕获的帧(和声音)上方绘制,并将结果另存为.mov文件.

Use Case: I want to capture input from the camera, draw on top of the captured frames (and sound) and save the result as a .mov file.

  • 我看到我可以使用AVCaptureSession捕获摄像机的输入.
  • 我可以使用AVCaptureMovieFileOutput将其保存到.mov文件.
  • AVVideoComposition可用于添加Core Animation进行播放.我想也可以录制吗?
  • I see that I can capture input for the camera using AVCaptureSession.
  • I can save this to a .mov file using AVCaptureMovieFileOutput.
  • AVVideoComposition can be used to add Core Animation for playback. I assume for recording somehow too?

问题:在将输入保存到文件之前,我看不到如何修改输入.

Problem: I can't see how to modify the input before it is saved to file.

推荐答案

The RosyWriter was almost doing what I wanted. Adding the following code to captureOutput:didOutputSampleBuffer:fromConnection: enabled me to draw onto the frame using Quartz.

    CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

    CVPixelBufferLockBaseAddress(pixelBuffer, 0);
    void *pxdata = CVPixelBufferGetBaseAddress(pixelBuffer);
    NSParameterAssert(pxdata != NULL);

    CGSize frameSize = CGSizeMake(self.videoDimensions.width, self.videoDimensions.height);

    CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(pxdata, frameSize.width,
                                                 frameSize.height, 8, 4*frameSize.width, rgbColorSpace, 
                                                 kCGImageAlphaNoneSkipFirst);

    CGContextMoveToPoint(context, 100, 100);
    CGContextAddLineToPoint(context, 200, 200);
    CGContextDrawPath(context, kCGPathStroke);

    CGColorSpaceRelease(rgbColorSpace);
    CGContextRelease(context);

这篇关于在使用AVCaptureMovieFileOutput保存之前修改AVCaptureSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆