ffmpeg -- 时间基准

AV_TIME_BASE

ffmpeg中的内部计时单位(时间基),ffmepg中的所有时间都是于它为一个单位,AV_TIME_BASE定义为:

#define         AV_TIME_BASE   1000000

其实是一种分数的表示形式,其中的1表示分子, AV_TIME_BASE 也就是1000000,表示的是分母,所以它其实就是1微秒,也就是 1/1000000 秒。

比如一段时长为60s的视频,读出来 duration为60000000,即 duration/AV_TIME_BASE = 60000000/1000000 = 60s

AVRational

AVRational在ffmpeg中的定义为

/**
 * Rational number (pair of numerator and denominator).
 */
typedef struct AVRational{
    int num; ///< Numerator
    int den; ///< Denominator
} AVRational;

num为分数,den为分母.AVRational表示的其实是一个有理数.
在ffmpeg中在很多地方 会用AVRational time_base 表示一个时间基,即一个时间单元.比如要算一个视频帧的PTS(显示时间)

double video_time = frame->best_effort_timestamp * av_q2d(time_base);
  • best_effort_timestamp是读取到的视频帧pts

  • time_base 为 formatContext->streams[i]->time_base 即视频流的时间基,类型为AVRational, 表示每个时间单位为 num/den 秒

    • This is the fundamental unit of time (in seconds) in terms
    • of which frame timestamps are represented.
  • av_q2d 定义为

static inline double av_q2d(AVRational a){
    return a.num / (double) a.den;
}

就是一个分子处分母的运算

假设读到的 best_effort_timestamp 为 60000000, time_base 为 1 / 1000000, 则计算出来
video_time = 60000000 * (1/1000000) = 60. 表示这一帧在60s处显示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值