【问题标题】:How can we use AVSampleBufferDisplayLayer to render CMSampleBufferRef?我们如何使用 AVSampleBufferDisplayLayer 来渲染 CMSampleBufferRef?
【发布时间】:2019-01-31 06:13:40
【问题描述】:

我有这个委托方法

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

这给了我sampleBuffer

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

我不想把sampleBuffer转成CGImage再画出来。

非常感谢代码示例:)

【问题讨论】:

    标签: ios objective-c avfoundation avplayer cmsamplebufferref


    【解决方案1】:

    像这样:

       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];
    

    【讨论】:

      猜你喜欢
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多