视频播放画面的缩放主要是通过libswscale这个库来实现。
我们将用来缩放的基本函数是sws_scale。但一开始,我们必需定义一个SwsContext的结构体,然后把它传递给sws_scale函数。类似于在SQL中的预备阶段或者是在Python中编译的规则表达式regexp。要获取这个SwsContext,我们得通过sws_getContext函数,它的参数有:源的宽度和高度,我们想要的宽度和高度,源的格式和想要转换成的格式,同时还有一些其它的参数和标志。然后我们像使用img_convert一样来使用sws_scale函数,唯一不同的是我们传递给的是SwsContext:
#include <ffmpeg/swscale.h> // include the header!
int queue_picture(VideoState *videoSate, AVFrame *pFrame, double pts) {
static struct SwsContext *img_convert_ctx;
...
if(vp->sdlOverlay) {
SDL_LockYUVOverlay(vp->bmp);
dst_pix_fmt = PIX_FMT_YUV420P;
/* point pict at the queue */
pict.data[0] = vp->bmp->pixels[0];
pict.data[1] = vp->bmp->pixels[2];
pict.data[2] = vp->bmp->pixels[1];
pict.linesize[0] = vp->bmp->pitches[0];
pict.linesize[1] = vp->bmp->pitches[2];
pict.linesi