ffmpeg学习十三:图像数据格式的转换与图像的缩放

本文介绍了ffmpeg如何实现图像数据格式的转换和图像缩放,主要涉及sws_getContext()、sws_scale()和sws_freeContext()三个关键函数。通过示例程序展示了如何将yuv图像转换为rgb格式并按指定尺寸输出到文件。
摘要由CSDN通过智能技术生成

一.实现图像数据格式转换与图像缩放的三个重要函数

ffmpeg实现图像数据格式的转换以及图片的缩放的功能,主要使用swscale.h中的三个函数:
sws_getContext()
sws_scale()
sws_freeContext()
这三个函数的定义如下:
1.sws_getContext() :


/**
 * Allocate and return an SwsContext. You need it to perform
 * scaling/conversion operations using sws_scale().
 *
 * @param srcW the width of the source image
 * @param srcH the height of the source image
 * @param srcFormat the source image format
 * @param dstW the width of the destination image
 * @param dstH the height of the destination image
 * @param dstFormat the destination image format
 * @param flags specify which algorithm and options to use for rescaling
 * @param param extra parameters to tune the used scaler
 *              For SWS_BICUBIC param[0] and [1] tune the shape of the basis
 *              function, param[0] tunes f(1) and param[1] f麓(1)
 *              For SWS_GAUSS param[0] tunes the exponent and thus cutoff
 *              frequency
 *              For SWS_LANCZOS param[0] tunes the width of the window function
 * @return a pointer to an allocated context, or NULL in case of error
 * @note this function is to be removed after a saner alternative is
 *       written
 */
struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,
                                  int dstW, int dstH, enum AVPixelFormat dstFormat,
                                  int flags, SwsFilter *srcFilter,
                                  SwsFilter *dstFilter, const double *param);

参数介绍

/*
* @param srcW源图像的宽度
* @param srcH源图像的高度
* @param srcFormat源图像格式
* @param dstW目标图像的宽度
* @param dstH目标图像的高度
* @param dstFormat目标图像格式
* @后面三个参数一般都置为空

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值