dvd 字幕缩放测试代码 (thinkvd开发日志)

这个测试代码字幕放大时效果还可以,但缩小时无论怎么调整有关参数:
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);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值