Rationnal数的计算。
虽然rational数字可以表示为浮点数,但是转换过程是一个有损的,浮点操作也是如此。另一方面,FFmpeg的性质要求精确地计算时间戳。这组有理数实用程序充当了一个通用接口,用于操作有理数作为数字和分母的一对。
在AVRational的许多函数中都有后缀q,这是指数学符号“”(q),它表示所有有理数的集合。
一、数据结构
struct | AVRational{ int num; int den; } |
二、函数
static AVRational | av_make_q (int num, int den) |
对不支持复合文字的编译器有用。
注意:返回值并没有减少。
static int | av_cmp_q (AVRational a, AVRational b) |
参数:a:第一个有理数
b:第二个有理数
返回:下列值的其中一个
0如果a==b
1如果a>b
-1如果a<b
INT_MIN如果其中一个值事0/0
static double | av_q2d (AVRational a) |
参数:a:用来转换的AVRationnal。
返回:一个浮点形式。
int | av_reduce (int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max) |
这对于framerate的计算很有用。
参数:dst_num:目的分子
dst_den:目的分母
num:源分子
den:源分母
max:最大允许dst_num&dst_den的值
返回:如果操作正确,返回1,否则返回0、
AVRational | av_mul_q (AVRational b, AVRational c) av_const |
参数:b:第一个有理数
c:第二个有理数
返回:b*c
AVRational | av_div_q (AVRational b, AVRational c) av_const |
参数:b:第一个有理数
c:第二个有理数
返回:b/c
AVRational | av_add_q (AVRational b, AVRational c) av_const |
参数:b:第一个有理数
c:第二个有理数
返回:b+c
AVRational | av_add_q (AVRational b, AVRational c) av_const |
参数:b:第一个有理数
c:第二个有理数
返回:b-c
static av_always_inline AVRational | av_inv_q (AVRational q) |
参数:q:值
返回:1/q
AVRational | av_d2q (double d, int max) av_const |
在无穷大的情况下,返回的值被表示为1、0或-1,这取决于符号。
参数:d:双转换
max:最大允许的分子和分母
返回:d AVRationnal形式
int | av_nearer_q (AVRational q, AVRational q1, AVRational q2) |
参数:q:理性的加以比较值
q1,q2:用来测试的有理数
返回:下列值得一个
1如果Q1接近Q而不是Q2
-1如果Q2比Q值接近Q值1
0如果它们有相同的距离
int | av_find_nearest_q_idx (AVRational q, const AVRational *q_list) |
参数:q:参考有理数
q_list:有理数的终止{0, 0}阵
返回:数组中最近值的索引
uint32_t | av_q2intfloat (AVRational q) |
参数:q:用来转换的有理数
返回:等效浮点值,表示为无符号32位整数。
注意:返回值是平台独立的。