Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将CMSampleBuffer/UIImage转换为ffmpeg';你的照片是什么?_Iphone_Ios4_Avfoundation_Video Encoding_Libav - Fatal编程技术网

Iphone 如何将CMSampleBuffer/UIImage转换为ffmpeg';你的照片是什么?

Iphone 如何将CMSampleBuffer/UIImage转换为ffmpeg';你的照片是什么?,iphone,ios4,avfoundation,video-encoding,libav,Iphone,Ios4,Avfoundation,Video Encoding,Libav,我正在尝试使用ffmpeg的libav*库将iPhone的摄像头帧编码成H.264视频。我在这发现 如何将CMSampleBuffer转换为UIImage,但如何将其转换为ffmpeg的AVPicture 谢谢。回答我自己的问题: CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(pixelBuffer, 0); // access th

我正在尝试使用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


这解决了我的问题。谢谢。

调用avpicture_fill()不应该在调用CVPixelBufferUnlockBaseAddress()之前进行,因为前者访问CVImageBufferRef中的原始像素数据?