My practice:
1 . avpicture is an outdated problem. I am replacing autoobject functions with AVFrame and imgutils . sample code:
...
//_pictureValid = avpicture_alloc(&_picture, // AV_PIX_FMT_RGB24, // _videoCodecCtx->width, // _videoCodecCtx->height) == 0; _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); //dont forget to free _pictureFrameData at last _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 parameter
at first I set align to 32 , but for some video streams it did not work, causing distorted images. Then I set it to 16 (my environment: mac, Xcode, iPhone6), some threads work fine. But finally, I set align to 1 because I found this
Fill in the AVPicture fields, always assume a linesize alignment of 1.
rotoava
source share