Tutorial 08: Software Scaling

本文档是教程08,介绍了FFmpeg中用于图像缩放的新库libswscale。相较于旧的img_convert方法,libswscale提供了一个更模块化、更快的接口,并且可能包含MMX优化。主要介绍了如何使用sws_scale函数和SwsContext来实现图像缩放,以创建高效的视频播放器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Tutorial 08: Software Scaling

Code: tutorial08.c

libswscale

ffmpeg has recently added a new interface, libswscale to handle image scaling. Whereas before in our player we would use img_convert to go from RGB to YUV12, we now use the new interface. This new interface is more modular, faster, and I believe has MMX optimization stuff. In other words, it's the preferred way to do scaling.

The basic function we're going to use to scale is sws_scale. But first, we're going to have to set up what's called an SwsContext. This allows us to compile the conversion we want, and then pass that in later to sws_scale. It's kind of like a prepared statement in SQL or a compiled regexp in Python. To prepare this context, we use the sws_getContext function, which is going to want our source width and height, our desired width and height, the source format and desired format, along with some other options and flags. Then we use sws_scale the same way as img_convert except we pass it our SwsContext:

 

and we have our new scaler in place. Hopefully this gives you a good idea of what libswscale can do.

 

That's it! We're done! Go ahead and compile your player:

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

and enjoy your movie player made in less than 1000 lines of C!

 

Of course, there's a lot of things we glanced over that we could add.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值