FFMPEG 与 mp4

1. FFmpeg 中的 start_timetime_base

  • start_time

    流的起始时间戳(单位:time_base),表示第一帧的呈现时间(Presentation Time)。通常用于同步多个流(如音频和视频)。

  • time_base

    时间基,是一个分数(例如 {1, 1000} 表示毫秒级),用于将时间戳转换为秒:

    复制代码
    时间(秒) = 时间戳 × time_base.num / time_base.den
1.1 MP4 文件中的对应概念

MP4 文件使用 ISO Base Media File Format (ISOBMFF) 结构,时间信息主要存储在以下 box 中:

1.2 time_base 的对应
  • mdhd box(Media Header Box)

    每个媒体轨道(Track)的 mdhd box 包含 timescale 字段,表示该轨道的时间刻度:

    • 含义 :1 秒被分成多少个时间单位(例如 timescale=90000 表示 1/90000 秒为一个单位)。
    • 对应关系 :FFmpeg 的 time_base 通常是 {1, timescale}

    示例

    若 MP4 轨道的 timescale=90000,则 FFmpeg 可能将 time_base 设为 {1, 90000}

1.3 start_time 的对应
  • tfdt box(Track Fragment Decode Time)

    存储每个片段(Fragment)的解码时间,相对于轨道开始时间。

  • ctts box(Composition Time to Sample)

    存储解码时间(DTS)到呈现时间(PTS)的偏移量,影响 start_time 的计算。

  • stts box(Decoding Time to Sample)

    定义样本的解码时间间隔,辅助计算绝对时间。

1.4. 转换关系示例

假设 MP4 文件:

  • 视频轨道 timescale=90000
  • 第一帧的 tfdt 值为 18000(表示 18000/90000 = 0.2 秒)

FFmpeg 读取时:

  • time_base = {1, 90000}
  • time_base = 1 / timescale
  • start_time = 18000(时间戳,单位为 time_base
  • 实际起始时间(秒) = 18000 × (1/90000) = 0.2
  • start_time(起始时间(秒)) = start_time × time_base
相关推荐
Nightwish51 小时前
Oracle 数据库巡检检查清单
数据库·oracle·ffmpeg
luoyayun36114 小时前
Qt/QML + FFmpeg 实现多音频文件顺序拼接功能
qt·ffmpeg·音频拼接
wbcuc1 天前
ffmpeg工具把m4s合并为mp4 powershell脚本
ffmpeg·m4s
luoyayun3612 天前
Qt + FFmpeg 实战:实现音频格式转换功能
qt·ffmpeg·音频格式转换
都在酒里3 天前
【极致低延时】香橙派部署 MediaMTX 实现 WebRTC 推流,延时仅 500-800ms,比局域网 ffmpeg 拉流快近 10 倍!(附踩坑全记录)
linux·arm开发·ffmpeg·webrtc·orangepi·嵌入式软件
Empty-Filled3 天前
用 Kap + FFmpeg 把录屏转成小体积 GIF:产品操作演示图制作实践
ffmpeg·kap
矜辰所致3 天前
嵌入式语音开发应用基础说明
ffmpeg·ai 语音·嵌入式语音·语音播放·语音采样
luoyayun3614 天前
Qt + FFmpeg 实战:音频静音段检测
qt·ffmpeg·音视频·静音段检测
小鹿研究点东西6 天前
直播带货长视频AI自动剪辑开播:一场直播如何反复利用?
ffmpeg·自动化·音视频·语音识别
luoyayun3616 天前
Qt + FFmpeg 实战:获取音视频文件基础属性、流信息和元数据
qt·ffmpeg·音视频·元数据·获取音视频文件属性