Pregunta

Estoy tratando de codificar imágenes de cámara de iPhone en un vídeo H.264 utilizando libav de FFmpeg * bibliotecas. He encontrado en este de Apple artículo cómo convertir CMSampleBuffer a UIImage, pero ¿cómo puede me convierto a fFmpeg AVPicture?

Gracias.

¿Fue útil?

Solución

contestar a mi propia pregunta:

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);

Ahora pFrame se rellena con el contenido del tampón de muestra, que está utilizando el formato de píxel kCVPixelFormatType_32BGRA.

Esto resolvió mi problema. Gracias.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top