ios - 我们如何使用 AVSampleBufferDisplayLayer 来渲染 CMSampleBufferRef?

标签 ios objective-c avfoundation avplayer cmsamplebufferref

我有这个委托(delegate)方法

-(void)airPlayServer:(id)server sampleBufferReceived:(CMSampleBufferRef)sampleBuffer
{
}

这给了我sampleBuffer .

现在我需要知道如何使用 AVSampleBufferDisplayLayer渲染我的 sampleBuffer。我知道我们必须使用 - enqueueSampleBuffer - 但我是 iOS 新手,我们该怎么做呢?

我不想将 sampleBuffer 转换为 CGImage 然后绘制它。

代码示例受到高度赞赏:)

最佳答案

像这样:

   CMSampleBufferRef sampleBufferRef = ...;

    // Force display as soon as possible

    CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBufferRef, YES);
    CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, 0);
    CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);

    [sampleBufferLayer enqueueSampleBuffer:sampleBufferRef];            
    [sampleBufferLayer setNeedsDisplay];

关于ios - 我们如何使用 AVSampleBufferDisplayLayer 来渲染 CMSampleBufferRef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54454403/

相关文章:

ios - 哪些传感器可以在 iPhone 后台运行?

objective-c - 将 xcode 更新到 4.5 后存档应用程序时出错

iphone - IOS项目中的C++前向引用(前向引用 'enum'类型)

ios - 需要UITableView的cellForRowAtIndexPath : to return nothing for some rows

objective-c - 未在视频上正确应用 CIFilter

ios - 如何将数据从 "didSelectRowAt"传递到另一个 VC 而无需呈现它或转场?

html - 从 HTML 输入触发 iOS 深色键盘

iOS - 可以播放 RBGA 视频吗?

ios - 使用 Rest API Swift 3

IOS Swift 如何在用户滚动时暂停视频