自定义视频

问题描述:

我通过使用cameraOverlayView选项放置视图来录制视频,同时录制它显示我的视图,但是当我尝试保存并观看时,视图不会出现。自定义视频

任何人都可以帮助我解决这个问题吗?

在此先感谢。

+1

描述你更详细地所遇到的问题和/或张贴一些代码。这有助于我们帮助你。 – Stunner 2010-12-03 06:11:23

恐怕不会那么简单。您必须使用AVCaptureSession类实际捕获单个帧。然后,您可以在捕获图像时将覆盖视图合成到图像上,然后将合成图像提供给AVCaptureDevice。

这很相关。下面是用于设置捕捉到你一些代码开始:

// Create and configure a capture session and start it running 

- (无效)setupCaptureSession { NSError *误差=零;

// Create the session 
session = [[AVCaptureSession alloc] init]; // note we never release this...leak? 

// Configure the session to produce lower resolution video frames, if your 
// processing algorithm can cope. We'll specify medium quality for the 
// chosen device. 
session.sessionPreset = AVCaptureSessionPresetLow; // adjust this! AVCaptureSessionPresetLow 

// Find a suitable AVCaptureDevice 
AVCaptureDevice *device = [AVCaptureDevice 
          defaultDeviceWithMediaType:AVMediaTypeVideo]; 

// Create a device input with the device and add it to the session. 
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device 
                    error:&error]; 
if (!input) { 
    // Handling the error appropriately. 
    NSLog(@"Yikes, null input"); 
} 
[session addInput:input]; 

// Create a VideoDataOutput and add it to the session 
AVCaptureVideoDataOutput *output = [[[AVCaptureVideoDataOutput alloc] init] autorelease]; 
output.alwaysDiscardsLateVideoFrames = YES; // cribbed this from somewhere -- seems related to our becoming unrepsonsive 

[session addOutput:output]; 

if (!output) { 
    // Handling the error appropriately. 
    NSLog(@"ERROROROROR"); 
} 

// Configure your output. 
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL); 
[output setSampleBufferDelegate:self queue:queue]; 
dispatch_release(queue); 

// Specify the pixel format 

// kCVPixelFormatType_32RGBA or kCVPixelFormatType_32BGRA 
output.videoSettings = 
[NSDictionary dictionaryWithObject: 
[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] 
          forKey:(id)kCVPixelBufferPixelFormatTypeKey]; 


// If you wish to cap the frame rate to a known value, such as 15 fps, set 
// minFrameDuration. 
output.minFrameDuration = CMTimeMake(1, VIDEO_CAPTURE_FRAMERATE); // WATCH THIS! 

NSNotificationCenter *notify = [NSNotificationCenter defaultCenter]; 
[notify addObserver: self selector: @selector(onVideoError:) name: AVCaptureSessionRuntimeErrorNotification object: session]; 
[notify addObserver: self selector: @selector(onVideoInterrupted:) name: AVCaptureSessionWasInterruptedNotification object: session]; 
[notify addObserver: self selector: @selector(onVideoEnded:) name: AVCaptureSessionInterruptionEndedNotification object: session]; 
[notify addObserver: self selector: @selector(onVideoDidStopRunning:) name: AVCaptureSessionDidStopRunningNotification object: session]; 
[notify addObserver: self selector: @selector(onVideoStart:) name: AVCaptureSessionDidStartRunningNotification object: session]; 

}