FFMPEG学习【libavutil】:Mathematics

来源:互联网 发布:北京旅游酒店推荐知乎 编辑:程序博客网 时间:2024/05/21 10:53

使用时间戳和时基的数学实用程序。


一、模块

AVRational

有理数计算



二、宏

#define ff_ctz   ff_ctz_c #define ff_ctzll   ff_ctzll_c #define ff_clz   ff_clz_c #define av_parity   __builtin_parity


三、枚举

enum  AVRounding { 
  AV_ROUND_ZERO = 0, //
  AV_ROUND_INF = 1, 
  AV_ROUND_DOWN = 2, 
  AV_ROUND_UP = 3, 
  AV_ROUND_NEAR_INF = 5, 
   AV_ROUND_PASS_MINMAX = 8192 
}舍入方法。



四、函数

static av_always_inline 
av_const int ff_ctz_c (int v)尾随零位计数。

参数:v:输入值。 如果v为0,结果为未定义。

返回:尾随0位数


static av_always_inline 
av_const int ff_ctzll_c (long long v)


static av_always_inline 
av_const unsigned ff_clz_c (unsigned x)

int64_t av_const av_gcd (int64_t a, int64_t b)计算两个整数操作数的最大公约数。

参数:a,b:操作数

返回:和b的GCD达到标志; 如果a> = 0且b> = 0,则返回值为> = 0; 如果一个== 0和b == 0,返回0。


int64_t av_rescale (int64_t a, int64_t b, int64_t c) av_const重新缩放64位整数,舍入到最接近。

该操作在数学上等同于* b / c,但直接写入可以溢出。

此函数等同于AV_ROUND_NEAR_INF的av_rescale_rnd()。


int64_t av_rescale_rnd (int64_t a, int64_t b, int64_t c, enum AVRounding rnd) av_const使用指定的舍入重新缩放64位整数。

该操作在数学上等同于* b / c,但直接写入可能会溢出,并且不支持不同的舍入方法。


int64_t av_rescale_q (int64_t a, AVRational bq, AVRational cq) av_const将64位整数重新缩放2个有理数。

该操作在数学上等同于* bq / cq。

此函数等效于AV_ROUND_NEAR_INF的av_rescale_q_rnd()。


int64_t av_rescale_q_rnd (int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd) av_const使用指定的舍入方式将64位整数重新缩放2个有理数。

该操作在数学上等同于* bq / cq。


int av_compare_ts (int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)在自己的时间基础上比较两个时间戳。

返回:以下值之一:

   -1如果ts_a在ts_b之前

   1,如果ts_a在ts_b之后

    如果它们代表相同的位置,则为0


int64_t av_compare_mod (uint64_t a, uint64_t b, uint64_t mod)比较两个整数操作数的余数除以公约数。

换句话说,比较整数a和b的最低有效log2(mod)位。

av_compare_mod(0x11, 0x02, 0x10) < 0 // since 0x11 % 0x10  (0x1) < 0x02 % 0x10  (0x2)av_compare_mod(0x11, 0x02, 0x20) > 0 // since 0x11 % 0x20 (0x11) > 0x02 % 0x20 (0x02)
参数:a,b:操作数

   mod:除数; 必须是2的倍数
返回:如果%mod <b%mod,则为负值

   一个正值,如果一个%mod> b%mod

   如果一个%mod == b%mod为零


int64_t av_rescale_delta (AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb)重新缩放时间戳,同时保留已知的持续时间。

该功能被设计为每个音频包进行调用,以将输入时间戳缩放到不同的时基。 与简单的av_rescale_q()调用相比,此功能对于可能的不一致的帧持续时间是稳健的。

最后一个参数是必须为同一个流的所有后续调用保留的状态变量。 对于第一个调用,* last应初始化为AV_NOPTS_VALUE。

参数:in_tb:输入时间时基

   in_ts:输入时间戳

   fs_tb:持续时间 。常这比int_tb和out_tb更精细(更大)

   last:指向以fs_tb表示的充当状态变量的时间戳的指针

   out_tb:输出时基

   duration:持续时间直到对该功能的下次呼叫(即当前分组/帧的持续时间)

返回:时间戳表示为out_tb

注意:在此功能的上下文中,“持续时间”是指样本,而不是秒。


int64_t av_add_stable (AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc)将值添加到时间戳。

此功能保证当重复添加相同的值时,不会发生舍入错误的累积。

参数:ts_tb:输入时间戳时基

   ts:输入时间戳

   inc_tb:inc时间基准

   inc:要添加的值

阅读全文
0 0
原创粉丝点击