我的做法:
1.avpicture 已经被弃用,我将 avpicture 函数替换为 AVFrame 和 imgutils 函数。代码示例:
//AVPicture _picture;
AVFrame *_pictureFrame;
uint8_t *_pictureFrameData;
...
_pictureFrame = av_frame_alloc();
_pictureFrame->width = _videoCodecCtx->width;
_pictureFrame->height = _videoCodecCtx->height;
_pictureFrame->format = AV_PIX_FMT_RGB24;
int size = av_image_get_buffer_size(_pictureFrame->format,
_pictureFrame->width,
_pictureFrame->height,
1);
_pictureFrameData = (uint8_t*)av_malloc(size);
av_image_fill_arrays(_pictureFrame->data,
_pictureFrame->linesize,
_pictureFrameData,
_pictureFrame->format,
_pictureFrame->width,
_pictureFrame->height,
1);
...
if (_pictureFrame) {
av_free(_pictureFrame);
if (_pictureFrameData) {
free(_pictureFrameData);
}
}
2.对齐参数
起初我将align设置为32,但是对于某些视频流它并不起作用,导致图像失真。然后我将其设置为16(我的环境:mac、Xcode、iPhone6),某些流能够正常工作。但最终我将align设置为1,因为我发现了这个。
Fill in the AVPicture fields, always assume a linesize alignment of 1.
av_image_get_linesize
获取行大小。我对这个库一无所知,只是在同一页上使用了ctrl+f查找linesize。它似乎是基于格式/尺寸的某种内部对齐要求。 - Preet KukretiPATH_TO_INSTALL_DIR/share/ffmpeg/examples/hw_decode.c
:size = av_image_get_buffer_size(tmp_frame->format, tmp_frame->width, tmp_frame->height, 1);
- megorit