Ios 如何从AVCaptureSession获取NSData?
我正在iOS中使用Ios 如何从AVCaptureSession获取NSData?,ios,objective-c,record,video-capture,avcapturesession,Ios,Objective C,Record,Video Capture,Avcapturesession,我正在iOS中使用AVCaptureSession录制视频 -(id)init { if ((self = [super init])) { [self setCaptureSession:[[AVCaptureSession alloc] init]]; } return self; } -(void)addVideoPreviewLayer { [self setPreviewLayer:[[[AVCaptureVideoPreviewLaye
AVCaptureSession
录制视频
-(id)init
{
if ((self = [super init]))
{
[self setCaptureSession:[[AVCaptureSession alloc] init]];
}
return self;
}
-(void)addVideoPreviewLayer
{
[self setPreviewLayer:[[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self captureSession]] autorelease]];
[[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];
}
如何在录制的同时创建录制视频的
NSData
?访问编码帧?仅使用iOS SDK是无法做到这一点的。您可以录制一个位到文件,访问文件中的编码帧,录制一个新文件,访问更多。。。如果你需要的话
然而,如果您在尝试获取原始帧的同时也在编写,这是相当简单的。在AVCaptureAudioDataOutputSampleBufferDelegate上使用–captureOutput:didOutputSampleBuffer:fromConnection:,而不是将输出捕获到文件。只需确保将数据路由到正在编码/写入缓冲区的对象,否则您将丢失“…同时录制”特性
这不是NSData,而是CMSampleBufferRef,它取决于缓冲区是音频还是视频,可以通过各种方式转换为NSData。My be这些链接将帮助您解决问题: 检查这个