dvd 字幕缩放测试代码 (thinkvd开发日志)
2011-02-27 14:10
274 查看
这个测试代码字幕放大时效果还可以,但缩小时无论怎么调整有关参数:
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);
}
}
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);
}
}
相关文章推荐
- dvd 字幕转换缩放问题 (thinkvd开发日志)
- 转换dvd 字幕缩小改进(thinkvd开发日志)
- 关于dvd subtitle与effect效果有冲突问题(thinkvd开发日志)
- 测试音视频合并中存在的问题或现象(thinkvd开发日志)
- DVD subtitle stream in SDL(thinkvd开发日志)
- .Net语言 APP开发平台——Smobiler学习日志:Poplist控件在APP中的应用场景以及代码
- [置顶] Android开发之封装log打印日志的工具类,实用logutils详细代码
- 用C语言开发一个BT下载软件 (四) ------ 代码实现-3-出错处理模块和运行日志模块
- axis1,xfire,jUnit 测试案列+开Web Service开发指南+axis1.jar下载 代码
- 关于swf to video convert(thinkvd开发日志)
- tomcat免重启随意更改java代码 提高开发效率(未测试)
- ios开发--旋转、移动、缩放手势实例代码
- 多语言代码生成器开发日志1
- 优美的测试代码 - 行为驱动开发(BDD)
- hadoop日志数据分析开发步骤及代码
- 微信开发第一篇了解微信公众平台(所有测试代码已上传博客)
- 日志_测试代码_Delphi7
- 以顺其自然的思路写程序(Thinkvd开发日志)
- 关闭 晓K的专栏 我的学习历程 目录视图摘要视图订阅 赠书 | 异步2周年,技术图书免费选 每周荐书:渗透测试、K8s、架构(评论送书) 项目管理+代码托管+文档协作,开发更
- Qt浅谈之窗体缩放(仅增加测试代码)