metal2

metal 看这一篇教程即可

  https://www.jianshu.com/p/625fb38eb411

-------------------------------------

(新的--可参考)https://github.com/yinxianxiaozi/Metal_WY

--------------

 

3、重要  设置帧 速率

  MTKView *_view;
    _view.delegate = _render;
    // 设置帧速率 --> 指定时间来调用 drawInMTKView 方法--视图需要渲染时调用 默认60
    _view.preferredFramesPerSecond = 60;

 

 

1、最终视频渲染部分

https://www.jianshu.com/p/7114536d705a

ios开发工程/ios音视/LearnMetal-master/Tutorial05-视频渲染-YUV

 

2、avframe 转换部分

/Users/wangt/Desktop/下载的代码/metalios/ffmpeg-player-Metal-YUV

- (CVPixelBufferRef)createCVPixelBufferFromAVFrame:(AVFrame *)frame {
    if(![self setupCVPixelBufferIfNeed:frame]) return NULL;
    CVPixelBufferRef _pixelBufferRef;
    CVReturn cvRet = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, pixelBufferPoolRef, &_pixelBufferRef);
    if(cvRet != kCVReturnSuccess) {
        NSLog(@"create cv buffer failed: %d", cvRet);
        return NULL;
    }
    CVPixelBufferLockBaseAddress(_pixelBufferRef, 0);
    /// copy y
    size_t yBytesPerRowSize = CVPixelBufferGetBytesPerRowOfPlane(_pixelBufferRef, 0);
    void *yBase = CVPixelBufferGetBaseAddressOfPlane(_pixelBufferRef, 0);
    memcpy(yBase, frame->data[0], yBytesPerRowSize * frame->height);
    /// copy uv
    void *uvBase = CVPixelBufferGetBaseAddressOfPlane(_pixelBufferRef, 1);
    size_t uvBytesPerRowSize = CVPixelBufferGetBytesPerRowOfPlane(_pixelBufferRef, 1);
    memcpy(uvBase, frame->data[1], uvBytesPerRowSize * frame->height / 2);
    CVPixelBufferUnlockBaseAddress(_pixelBufferRef, 0);
    return _pixelBufferRef;
}

 

posted @ 2022-02-05 16:19  cnchengv  阅读(110)  评论(0编辑  收藏  举报