该如何利用FFmpeg对yuv图片进行deinterlace,resize 操作?
........................................
yuv_media_frame_t *pYUV = (yuv_media_frame_t *)pFrame->GetData();
const u_int8_t* pY = pYUV->y;
const u_int8_t* pU = pYUV->u;
const u_int8_t* pV = pYUV->v;
u_int16_t yStride = pYUV->y_stride;
u_int16_t uvStride = pYUV->uv_stride;
u_int8_t* mallocedYuvImage = NULL;
// crop to desired aspect ratio (may be a no-op)
const u_int8_t* yImage = pY + m_videoSrcYCrop;
const u_int8_t* uImage = pU + m_videoSrcUVCrop;
const u_int8_t* vImage = pV + m_videoSrcUVCrop;
// this has to be rewritten to not mess with the original YUV,
// since it has to be done after the resizer.
if (m_videoFilter != VF_NONE)
{
AVPicture src;
avpicture_fill(&src, (uint8_t *)yImage, PIX_FMT_YUV420P,
m_videoSrcWidth, m_videoSrcHeight);
avpicture_deinterlace(&src, &src, PIX_FMT_YUV420P,
m_videoSrcWidth, m_videoSrcHeight);
}
// resize image if necessary
if (m_videoYResizer)
{
u_int8_t* resizedYUV = (u_int8_t*)Malloc(m_videoDstYUVSize);
u_int8_t* resizedY = resizedYUV;
u_int8_t* resizedU = resizedYUV + m_videoDstYSize;
u_int8_t* resizedV = resizedYUV + m_videoDstYSize +
m_videoDstUVSize;
static struct SwsContext *img_convert_ctx;
if(img_convert_ctx == NULL)
{
int w = m_videoSrcWidth;
int h = m_videoSrcHeight;
img_convert_ctx = sws_getContext(w, h,
PIX_FMT_YUV420P,
w, h, PIX_FMT_YUV420P, SWS_BICUBIC,
NULL, NULL, NULL);
if(img_convert_ctx == NULL)
{
fprintf(stderr, "Cannot initialize the conversion context!\n");
exit(1);
}
}
AVPicture src,dst;
avpicture_fill(&src, (uint8_t *)yImage, PIX_FMT_YUV420P,
m_videoSrcWidth, m_videoSrcHeight);
avpicture_fill(&dst, (uint8_t *)resizedY, PIX_FMT_YUV420P,
m_videoDstWidth, m_videoDstHeight);
sws_scale(img_convert_ctx, src.data,
src.linesize, 0,
m_videoDstHeight,
dst.data, dst.linesize);
if (mallocedYuvImage) free(mallocedYuvImage);
// switch over to resized version
mallocedYuvImage = resizedYUV;
yImage = resizedY;
uImage = resizedU;
vImage = resizedV;
yStride = m_videoDstWidth;
uvStride = yStride / 2;
}
..................................
上段代码中,ffmpeg操作那块该如何修改?主要是 avpicture_fill这块,如何将yuv的数据填充到AVPicture 中?
是否需要分别对yImage,uImage,vImage进行deinterlace和resize?