cmsamplebuffer/uiimageをffmpegのavpictureに変換する方法は?
-
12-10-2019 - |
質問
iPhoneのカメラフレームをFFMPEGのLibav*ライブラリを使用してH.264ビデオにエンコードしようとしています。私はこれで見つけましたAppleの記事 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