这个测试代码字幕放大时效果还可以,但缩小时无论怎么调整有关参数:1. sws_getContext中的flags相关,2。sws_getGaussianVec(0.25, 3.0);都比较难让人满意,当画面缩小时,与主流的dvd converter 转换器还有点差异.void subtitle_scale(AVCodecContext *c){ struct SwsContext *pSWSCtx; AVFrame *pFrameRGB; int i, format, numBytes; uint8_t *buffer; AVPicture *picture; static SwsFilter filter; static int firsttime = 1; for (int i = 0; i < subtitle_av.num_rects; i++){ int width = subtitle_av.rects[i]->w; int height= subtitle_av.rects[i]->h; c->width = (int)(width * subtitle_info.ratio_w); c->height= (int)(height* subtitle_info.ratio_h); if(c->width%4!=0) c->width=c->width+4-c->width%4; pFrameRGB = avcodec_alloc_frame(); if (pFrameRGB==NULL){ printf("avcodec alloc frame failed!/n"); continue; } if (firsttime) { filter.lumH = filter.lumV = filter.chrH = filter.chrV = sws_getGaussianVec(0.25, 3.0); sws_normalizeVec(filter.lumH, 1.0); firsttime = 0; } format = PIX_FMT_GRAY8; numBytes=avpicture_get_size(format, c->width, c->height); buffer= av_malloc(numBytes); avpicture_fill((AVPicture *)pFrameRGB, buffer, format, c->width, c->height); pSWSCtx = sws_getContext( width, height, format, c->width, c->height, format, SWS_BICUBIC, &filter, NULL, NULL); //dumpInfo("w=%d, pitch=%d", c->width, c->width); sws_scale(pSWSCtx, subtitle_av.rects[i]->pict.data, subtitle_av.rects[i]->pict.linesize, 0, height, pFrameRGB->data, pFrameRGB->linesize); subtitle_av.rects[i]->w = c->width; subtitle_av.rects[i]->h = c->height; subtitle_av.rects[i]->x = (subtitle_info.video_out_w - c->width)>>1; av_free(subtitle_av.rects[i]->pict.data[0]); subtitle_av.rects[i]->pict.data[0] = av_malloc(c->width * c->height); memcpy(subtitle_av.rects[i]->pict.data[0], pFrameRGB->data[0], c->width * c->height); subtitle_av.rects[i]->pict.linesize[0] = pFrameRGB->linesize[0]; av_free(buffer); av_free(pFrameRGB); sws_freeContext(pSWSCtx); }}