当前位置: 首页 > news >正文

FFmpeg源码:avpriv_set_pts_info函数分析

一、avpriv_set_pts_info函数的声明

avpriv_set_pts_info函数声明在FFmpeg源码(本文演示用的FFmpeg源码版本为7.0.1)的头文件libavformat/internal.h中:

/*** Set the time base and wrapping info for a given stream. This will be used* to interpret the stream's timestamps. If the new time base is invalid* (numerator or denominator are non-positive), it leaves the stream* unchanged.** @param st stream* @param pts_wrap_bits number of bits effectively used by the pts*        (used for wrap control)* @param pts_num time base numerator* @param pts_den time base denominator*/
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,unsigned int pts_num, unsigned int pts_den);

该函数的作用是:设置AVStream的time_base。

形参st:输出型参数,指向一个AVStream对象。执行avpriv_set_pts_info函数后,st->time_base和st->pts_wrap_bits会被设置。

形参pts_wrap_bits:输入型参数,pts有效使用的位数。执行avpriv_set_pts_info函数后,st->pts_wrap_bits的值会被设置为pts_wrap_bits。

形参pts_num:输入型参数。time_base的分子。

形参pts_den:输入型参数。time_base的分母。

二、avpriv_set_pts_info函数的定义

avpriv_set_pts_info函数定义在源文件libavformat/avformat.c中:

void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,unsigned int pts_num, unsigned int pts_den)
{FFStream *const sti = ffstream(st);AVRational new_tb;if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {if (new_tb.num != pts_num)av_log(NULL, AV_LOG_DEBUG,"st:%d removing common factor %d from timebase\n",st->index, pts_num / new_tb.num);} elseav_log(NULL, AV_LOG_WARNING,"st:%d has too large timebase, reducing\n", st->index);if (new_tb.num <= 0 || new_tb.den <= 0) {av_log(NULL, AV_LOG_ERROR,"Ignoring attempt to set invalid timebase %d/%d for st:%d\n",new_tb.num, new_tb.den,st->index);return;}st->time_base     = new_tb;if (sti->avctx)sti->avctx->pkt_timebase = new_tb;st->pts_wrap_bits = pts_wrap_bits;
}

 关于av_reduce函数可以参考:《FFmpeg源码:av_reduce函数分析》。avpriv_set_pts_info函数的核心就是通过调用av_reduce函数对有理数进行化简:

av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)


http://www.mrgr.cn/news/18045.html

相关文章:

  • 快速了解开源RAG-UI工具“kotaemon”
  • 【C++11及其特性】智能指针——unique_ptr
  • 黑马点评5——优惠券秒杀—优化秒杀
  • java 根据给定的子网掩码和网关计算起始IP和结束IP
  • Unity(2022.3.41LTS) - UI详细介绍- Button(按钮)TMP
  • 【类模板】类模板的特化
  • 金九银十来了,你准备好了吗?——迎接技术行业的旺季
  • SPI驱动学习三(spidev的使用)
  • 【C语言从不挂科到高绩点】06-流程控制语句-循环语句
  • 万亿秒查是真地吗?比 ORACLE 快 N 倍是不是吹牛?
  • 轻量级 AI 革命:Phi-3.5 小模型现可一键 input!浙大领头开源多模态基准上线,含 8 大类别图像问答
  • 点击刷新按钮或者按 F5、按 Ctrl+F5 (强制刷新)、地址栏回车有什么区别?
  • 青书学堂 看视频 看课时 php 懒人版
  • Spring Boot启动卡在Root WebApplicationContext: initialization completed in...
  • 换毛季来临,猫咪浮毛如何快速清理?好用的宠物空气净化器推荐
  • 网工面试题(安全)
  • kafka3.7.1 单节点 KRaft部署测试发送和接收消息
  • 2024java面试题
  • 古典显示格式解一偏微分方程并绘制结果的彩色图
  • ~/.bashrc、 ~/.bash_profile、~/.profile、 /etc/profile几个配置文件的区别