博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(转译)用FFmpeg和SDL写播放器--08软件缩放
阅读量:4678 次
发布时间:2019-06-09

本文共 1871 字,大约阅读时间需要 6 分钟。

指导 8:软件缩放
 
软件缩放库 libswscale
 
  近来 ffmpeg 添加了新的接口:libswscale 来处理图像缩放。 但是在前面我们使用 img_convert 来把 RGB 转换成 YUV12,我们现在使用新的接口。新接口更加标准和快速,而且我相信里面有了 MMX 优化代码。换句话说,它是做更好的缩放方式。
  我们将用来缩放的基本函数是 sws_scale。但一开始,我们必需建立一个 SwsContext 的概念。这将让我们进行想要的转换,然后把它传递给 sws_scale函数。类似于在 SQL 中的预备阶段或者是在 Python 中编译的规则表达式 regexp。 要准备这个上下文,我们使sws_getContext 函数,它需要我们源的宽度和高度,我们想要缩放的宽度和高度,源的格式和想要转换成的格式,同时还有一些其它的参数和标志。然后我们像使用 img_convert 一样来使用 sws_scale 函数,唯 一不同的是我们传递给的是 SwsContext:
 
#include 
// include the header!int queue_picture(VideoState *is, AVFrame *pFrame, double pts) { static struct SwsContext *img_convert_ctx; ... if(vp->bmp) { 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.linesize[2] = vp->bmp->pitches[1]; // Convert the image into YUV format that SDL uses if(img_convert_ctx == NULL) { int w = is->video_st->codec->width; int h = is->video_st->codec->height; img_convert_ctx = sws_getContext(w, h, is->video_st->codec->pix_fmt, w, h, dst_pix_fmt, SWS_BICUBIC, NULL, NULL, NULL); if(img_convert_ctx == NULL) { fprintf(stderr, "Cannot initialize the conversion context!\n"); exit(1); } } sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, is->video_st->codec->height, pict.data, pict.linesize);

  我们把新的缩放器放到了合适的位置。希望这会让你知道 libswscale能做什么。 就这样,我们做完了!编译我们的播放器:

gcc -o tutorial08 tutorial08.c -lavutil -lavformat -lavcodec -lz -lm `sdl-config --cflags --libs`

转载于:https://www.cnblogs.com/xdao/archive/2013/06/14/ffmpeg_tutor08.html

你可能感兴趣的文章
Windows Phone 7 Coding4Fun控件简介
查看>>
Nginx 常用命令总结
查看>>
hall wrong behavior
查看>>
Collection集合
查看>>
【C++】const在不同位置修饰指针变量
查看>>
github新项目挂历模式
查看>>
编写jquery插件
查看>>
敏捷开发笔记
查看>>
学前班
查看>>
关于自关联1
查看>>
hdu-1814(2-sat)
查看>>
谷歌浏览器,添加默认搜索引擎的搜索地址
查看>>
数据结构化与保存
查看>>
为什么需要Docker?
查看>>
国内5家云服务厂商 HTTPS 安全性测试横向对比
查看>>
how to control project
查看>>
转 python新手容易犯的6个错误
查看>>
第四节 -- 列表
查看>>
决策树
查看>>
团队作业
查看>>