使用 Ffmpeg 同步解码视频
我正在使用 Ffmpeg 解码和播放视频文件。我目前已经以 CPU 解码和显示的速度播放视频和音频。问题是我想使用系统时钟同步播放视频和音频。
我四处寻找一些帮助,但除了 dranger 的 教程 05 之外找不到任何实质性内容,但是我不太明白他在做什么,因为我的程序的编写方式与他的不同。
我正在使用 mjpeg 文件,因此每次解码帧时似乎都会检索 pts,我将 pts 乘以 time_base,就像 dranger 那样以秒为单位获取值,但分辨率似乎只有秒,所以我得到当视频以每秒 25 帧的速度运行时,值“6”25 次,然后“7”25 次。
难道就没有更准确的值吗?或者获得更准确值的方法,如果是这样,我将如何同步到该值?我正在使用 SDL 来显示该值,那么我可以只使用我得到的值的 SDL_Delay() 吗?
感谢您抽出时间,
Infinitifizz
I am using Ffmpeg to decode and play video files. I have currently got the video playing and the audio playing at as fast as the CPU can decode and display them. The problem is that I want to play the video and audio in sync using the system clock.
I've searched around for some help but can't find anything substantial other than dranger's tutorial 05 but I don't really understand what he is doing because my program isn't written in the same way as his.
I am using mjpeg files and so the pts seems to be retrieved every single time a frame is decoded, I have multiplied the pts by the time_base as dranger does to get the value in seconds but the resolution seems to be only seconds and so I get the value "6" 25 times and then "7" 25 times as the video runs at 25 frames per second.
Is there not a more accurate value? Or way to get a more accurate value and if so, how would I go about syncing to this value? I am using SDL to display the value so can I just use a SDL_Delay() of the value I get?
Thanks for your time,
Infinitifizz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要将 pts 或 dts 转换为浮点秒,请在适当的 time_base 上使用 av_q2d():
这将返回视频开始时的时间(以秒为单位)。
To convert pts or dts to floating-point seconds, use av_q2d() on proper time_base:
This returns time-from-when-the-video-starts in seconds.