AVSampleBufferDisplayLayer如何显示H.264 [英] How AVSampleBufferDisplayLayer displays H.264
本文介绍了AVSampleBufferDisplayLayer如何显示H.264的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想分享我几天来所积累的知识.没有很多可以找到的.
I want to share my knowledge which I worked out in some days about it. There isnt a lot to find about it.
我仍然对声音不满.欢迎评论和提示. ;-)
I am still fizzeling about the sound. Comments and tips are welcomed. ;-)
推荐答案
此处是我的代码段.声明
here my code snippets. Declare it
@property (nonatomic, retain) AVSampleBufferDisplayLayer *videoLayer;
首先设置视频层
self.videoLayer = [[AVSampleBufferDisplayLayer alloc] init];
self.videoLayer.bounds = self.bounds;
self.videoLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
self.videoLayer.videoGravity = AVLayerVideoGravityResizeAspect;
self.videoLayer.backgroundColor = [[UIColor greenColor] CGColor];
//set Timebase
CMTimebaseRef controlTimebase;
CMTimebaseCreateWithMasterClock( CFAllocatorGetDefault(), CMClockGetHostTimeClock(), &controlTimebase );
self.videoLayer.controlTimebase = controlTimebase;
CMTimebaseSetTime(self.videoLayer.controlTimebase, CMTimeMake(5, 1));
CMTimebaseSetRate(self.videoLayer.controlTimebase, 1.0);
// connecting the videolayer with the view
[[self layer] addSublayer:_videoLayer];
将视频数据提供给图层
__block AVAssetReaderTrackOutput *outVideo = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:video outputSettings:dic];
if( [assetReaderVideo startReading] )
{
[_videoLayer requestMediaDataWhenReadyOnQueue: assetQueue usingBlock: ^{
while( [_videoLayer isReadyForMoreMediaData] )
{
CMSampleBufferRef *sampleVideo = [outVideo copyNextSampleBuffer];
[_videoLayer enqueueSampleBuffer:sampleVideo.data];
}
}];
}
有关更多详细信息:2014年WWDC的Session 513内容非常丰富.
For further details: the Session 513 in WWDC 2014 is very informative.
这篇关于AVSampleBufferDisplayLayer如何显示H.264的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文