如何将cmsamplebuffer/uiimage转换为ffmpeg的avpicture?
-
12-10-2019 - |
题
我正在尝试使用FFMPEG的Libav*库将iPhone的相机帧编码为H.264视频。我在这个中找到了苹果的文章 如何将cmsamplebuffer转换为uiimage,但是如何将其转换为ffmpeg的avpicture?
谢谢。
解决方案
回答我自己的问题:
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
// access the data
int width = CVPixelBufferGetWidth(pixelBuffer);
int height = CVPixelBufferGetHeight(pixelBuffer);
unsigned char *rawPixelBase = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer);
// Do something with the raw pixels here
// ...
// Fill in the AVFrame
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
AVFrame *pFrame;
pFrame = avcodec_alloc_frame();
avpicture_fill((AVPicture*)pFrame, rawPixelBase, PIX_FMT_RGB32, width, height);
现在 pFrame
用样品缓冲液的含量填充,该缓冲区正在使用像素格式 kCVPixelFormatType_32BGRA
.
这解决了我的问题。谢谢。
不隶属于 StackOverflow