如何在Mac上使用Foundation将图片编码为H264 而不是使用 x264

我正在尝试使 Mac 广播客户端使用 FFmpeg 而不是 x264 库编码到 H264 中。所以基本上,我能够在CMSampleBufferRef或AVPicture中从 AVFoundation 中获取原始帧。那么有没有办法使用 Apple 框架将一系列这些图片编码为 H264 帧,例如AVVideoCodecH264。我知道使用 AVAssetwriter 将其编码的方式,但我不希望

我正在尝试使 Mac 广播客户端使用 FFmpeg 而不是 x264 库编码到 H264 中。所以基本上,我能够在CMSampleBufferRefPicture中从 Foundation 中获取原始帧。那么有没有办法使用 Apple 框架将一系列这些图片编码为 H264 帧,例如VideoCodecH264。我知道使用 Assetwriter 将其编码的方式,但我不希望

6

在参考VideoCore project之后,我可以使用 Apple 的 VideoToolbox 框架在硬件中进行编码。

启动 VTCompressionSession:

// Create compression session
err = VTCompressionSessionCreate(kCFAllocatorDefault,
                             frameW,
                             frameH,
                             kCMVideoCodecType_H264,
                             encoderSpecifications,
                             NULL,
                             NULL,
                             (VTCompressionOutputCallback)vtCallback,
                             self,
                             &compression_session);
if(err == noErr) {
    comp_session = session;
}

将原始帧推送到 VTCompressionSession

// Delegate method from the CaptureVideoDataOutputSampleBufferDelegate
- (void)captureOutput:(CaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(CaptureConnection *)connection {
    // get pixelbuffer out from samplebuffer
    CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    //set up all the info for the frame
    // call VT to encode frame
    VTCompressionSessionEncodeFrame(compression_session, pixelBuffer, pts, dur, NULL, NULL, NULL);
    }

获取 VTCallback 中的编码帧,这是一个要用作 VTCompressionSessionCreate()的参数的 C 方法

void vtCallback(void *outputCallbackRefCon,
        void *sourceFrameRefCon,
        OSStatus status,
        VTEncodeInfoFlags infoFlags,
        CMSampleBufferRef sampleBuffer ) {
    // Do whatever you want with the sampleBuffer
    CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
}

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(750)
在 Javascript中从国家缩写中获取完整的国家名称
上一篇
在纯函数语言中 是否有一种算法来获取反函数(self inverse function)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(87条)