ffmpeg av lib可以返回精确的PTS吗? [英] Can the ffmpeg av libs return an accurate PTS?

查看:167
本文介绍了ffmpeg av lib可以返回精确的PTS吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用IBBP ... GOP序列的mpeg流。对于前4个AVPackets返回的(DTS,PTS)值如下:I =(0,3)B =(1,1)B =(2,2)P =(3,6)



I帧上的PTS看起来像是合法的,但是B帧上的PTS不能正确,因为B帧不应该在I帧作为PTS之前显示值表示。我也尝试解码数据包,并使用最终产生的AVFrame中的pts值,将PTS始终设置为零。



有没有办法获得准确的PTS出ffmpeg?如果没有,那么同步音频的最佳方式是什么?

解决方案

我想我终于想出了一个基于评论的发生了什么在 http://www.dranger.com/ffmpeg/tutorial05.html 中制作:


ffmpeg重新排序数据包,以便由avcodec_decode_video()处理的数据包的DTS将始终保持不变作为返回框架的PTS


翻译:如果我将一个数据包馈入到PTS为12的avcodec_decode_video()中,则avcodec_decode_video ()将不会返回包含在该数据包中的解码帧,直到我为其提供了DTS为12的分组。如果分组的PTS与其DTS相同,则给出的分组是与框架返回相同。如果分组的PTS比其DTS晚2帧,则avcodec_decode_video()将延迟帧并且不返回它,直到我再提供2个数据包。



基于此行为,我猜测av_read_frame()可能是将IPBB到IBBP的数据包重新排序,以便avcodec_decode_video()只能缓冲P帧3帧而不是5.例如,P帧的输入和输出之间的差异为3(6 - 3):

  | I B B P B B P 
| DTS:0 1 2 3 4 5 6
| decode()result:I B B P

vs。与标准排序(6 - 1)的差异为5:

  I P B B P B B 
| DTS:0 1 2 3 4 5 6
| decode()result:IBBP

< shrug />但这是纯粹的推测。

I'm working with an mpeg stream that uses a IBBP... GOP sequence. The (DTS,PTS) values returned for the first 4 AVPackets are as follows: I=(0,3) B=(1,1) B=(2,2) P=(3,6)

The PTS on the I frame looks like it is legit, but then the PTS on the B frames cannot be right, since the B frames shouldn't be displayed before the I frame as their PTS values indicate. I've also tried decoding the packets and using the pts value in the resulting AVFrame, put that PTS is always set to zero.

Is there any way to get an accurate PTS out of ffmpeg? If not, what's the best way to sync audio then?

解决方案

I think I finally figured out what's going on based on a comment made in http://www.dranger.com/ffmpeg/tutorial05.html:

ffmpeg reorders the packets so that the DTS of the packet being processed by avcodec_decode_video() will always be the same as the PTS of the frame it returns

Translation: If I feed a packet into avcodec_decode_video() that has a PTS of 12, avcodec_decode_video() will not return the decoded frame contained in that packet until I feed it a later packet that has a DTS of 12. If the packet's PTS is the same as its DTS, then the packet given is the same as the frame returned. If the packet's PTS is 2 frames later than its DTS, then avcodec_decode_video() will delay the frame and not return it until I provide 2 more packets.

Based on this behavior, I'm guessing that av_read_frame() is maybe reordering the packets from IPBB to IBBP so that avcodec_decode_video() only has to buffer the P frames for 3 frames instead of 5. For example, the difference between the input and the output of the P frame with this ordering is 3 (6 - 3):

|                  I B B P B B P
|             DTS: 0 1 2 3 4 5 6
| decode() result:       I B B P

vs. a difference of 5 with the standard ordering (6 - 1):

|                  I P B B P B B
|             DTS: 0 1 2 3 4 5 6
| decode() result:       I B B P

<shrug/> but that is pure conjecture.

这篇关于ffmpeg av lib可以返回精确的PTS吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆