为了方便,可以自己写一个img_convert函数,然后函数内部用sws_scale来实现,只是对于一些错误的处理及返回值处理不太严格,但基本能用,代码如下:
int img_convert(AVPicture *dst, int dst_pix_fmt,
const AVPicture *src, int src_pix_fmt,
int src_width, int src_height)
{
int w;
int h;
SwsContext *pSwsCtx;
w = src_width;
h = src_height;
pSwsCtx =
sws_getContext(w, h, src_pix_fmt,
w, h, dst_pix_fmt,
SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(
pSwsCtx, src->data, src->linesize,
0, h, dst->data, dst->linesize);
//这里释放掉pSwsCtx的内存
return 0;
}