我尝试将CMSampleBufferRef从VTCompressionSession导出到FFmpeg可处理的AVPacket。
我看到FFmpeg提供了函数av_read_frame()
来从编码文件中获取数据包。因此,使用此功能,我可以成功从H264编码文件中获取AVPacket(例如,使用AVAssetWritter)。所以我进入了av_read_frame()implementation并看到它从sampleBuffer中读出了一个imageBuffer。
所以我尝试在VTCompressionSessionCallback函数中使用相同的实现
void VTCompressionOutputCallback(
void *outputCallbackRefCon,
void *sourceFrameRefCon,
OSStatus status,
VTEncodeInfoFlags infoFlags,
CMSampleBufferRef sampleBuffer) {
NSLog(@"VTCompressionSession Callback");
CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
}
但事实证明这里的pixelBuffer为零,我只将blockBuffer作为有效输出。那么如何从blockBuffer中获取帧。或者更具体地说,我如何在这里使用blockBuffer获取AVPacket。