在弄清楚如何使用Apple的硬件加速视频框架来解压缩H.264视频流时,我遇到了很多麻烦.几个星期后,我想出来,想分享一个广泛的例子,因为我找不到一个.
我的目标是提供WWDC '14会议513中介绍的Video Toolbox的全面,有启发性的示例.我的代码将无法编译或运行,因为它需要与基本H.264流集成(如从文件读取视频或从在线等流式传输),并且需要根据具体情况进行调整.
我应该提一下,除了我在谷歌搜索主题时学到的东西,我对视频/解码的经验很少.我不知道有关视频格式,参数结构等的所有细节,所以我只包括我认为你需要知道的内容.
我正在使用XCode 6.2并已部署到运行iOS 8.1和8.2的iOS设备.
我正在使用AVFoundation框架.在我的示例缓冲区委托中,我有以下代码:
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
CVPixelBufferRef pb = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pb];
self.imageView.image = [UIImage imageWithCIImage:ciImage];
}
Run Code Online (Sandbox Code Playgroud)
我可以使用CIImage来运行面部检测器等但它没有出现在UIImageView中...... imageView仍然是白色的.关于这个问题的任何想法?我使用以下设置我的会话:
self.session = [[AVCaptureSession alloc] init];
self.session.sessionPreset = AVCaptureSessionPreset640x480;
self.videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
self.frameOutput = [[AVCaptureVideoDataOutput alloc] init];
self.frameOutput.videoSettings = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种使用iOS API检索视频的各个帧的方法.我尝试使用AVAssetImageGenerator,但它似乎只提供最接近的秒的帧,这对我的使用来说有点太粗糙了.
根据我对文档的理解,AVAssetReader,AVAssetReaderOutput和CMSampleBufferGetImageBuffer的管道我应该可以做一些事情,但我坚持使用CVImageBufferRef.有了这个,我正在寻找一种方法来获得CGImageRef或UIImage,但还没有找到它.
不需要实时,我越能坚持提供API越多越好.
非常感谢!
编辑:基于这个网站:http://www.7twenty7.com/blog/2010/11/video-processing-with-av-foundation和这个问题:如何将CVImageBufferRef转换为UIImage我即将解决方案.问题,AVAssetReader在第一次之后停止读取copyNextSampleBuffer而没有给我任何东西(sampleBuffer为NULL).
该视频可由MPMoviePlayerController读取.我不明白什么是错的.
需要解码h264流并获取像素缓冲区
我知道它可以在iOS 8上使用视频工具箱
1.如何将h264流转换为CMSampleBufferRef?
2.如何使用视频工具箱进行解码?
我试图从相机中获得尽可能好的图像,但只能找到示例,captureStillImageAsynchronouslyFromConnection然后直接进入:
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
Run Code Online (Sandbox Code Playgroud)
JPEG是有损的,有没有什么方法可以将数据作为PNG,甚至只是RGBA(BGRA,你有什么用?).AVCaptureStillImageOutput似乎没有任何其他NSData*方法....
实际上看着CMSampleBufferRef,它似乎已经锁定为JPEG~
formatDescription = <CMVideoFormatDescription 0xfe5e1f0 [0x3e5ac650]> {
mediaType:'vide'
mediaSubType:'jpeg'
mediaSpecific: {
codecType: 'jpeg' dimensions: 2592 x 1936
}
extensions: {(null)}
}
Run Code Online (Sandbox Code Playgroud)
是否有其他方法可以拍摄全分辨率照片并获取原始数据?
我正在尝试从QT电影的各个帧中提取像素数据.
我想我需要使用CV,因为QTKit和NSImage会太慢......
我需要比较包含网络摄像头当前帧(iSight)的缓冲区(CVImageBufferRef)中图像的每个像素.所以我需要速度.
抱歉我的英语不好,我是意大利语.
ios ×3
avfoundation ×2
h.264 ×2
ios8 ×2
buffer ×1
core-image ×1
core-video ×1
frame ×1
image ×1
ios5 ×1
iphone ×1
isight ×1
macos ×1
objective-c ×1
pixel ×1
uiimage ×1
video ×1