我想分享我在最近几天里学到的关于IT技术的知识。这方面的资料并不多。
我仍然在琢磨声音的问题。欢迎大家提出评论和建议。;-)
我想分享我在最近几天里学到的关于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];
}
}];
}
更多细节请参考:WWDC 2014中的Session 513非常富有信息量。
我正在尝试这个,但发现AVSampleBufferDisplay图层上没有图像。
我从原始字节流创建NAL单元,并使用以下方式传递IDR和非IDR切片:
if ([avLayer isReadyForMoreMediaData]) {
[avLayer enqueueSampleBuffer:sampleBuffer];
}
从EnqueueSampleBuffer中没有返回错误状态,因此很难找出问题所在。