FLV rtmp 里存在B帧的情况下 time stamp 时间戳

from: http://www.tuicool.com/articles/VVFZJb7


二 关于rtmp接收到的包,有可能会一个rtmp包含多个个slice)的,。需要分离出每一个slice出来,并在每一个PES包 放入slice前添加 0×00,0×00,0×00,0×01,0×09,0xF0。开始没有主意的时候,这个是根据a  pple 给的文档 第十条中说到:H.264 video access units must use Access Unit Delimiter NALs, and must be in unique PES packets. 

,ffmpeg推流的时候,刚刚开始的推会把编码器信息和第一贞连在一起发,需要把他分开,并添加h264的分隔符。需要在关键贞前面添加pps和sps信息。不能把pps和sps放在单独的PES包内发送

这里讲解下rtmp的视频包结构。。

rtmp视频包在h264的包前边再添加了9个Byte.具体内容填写参考srs的代码 SrsRawH264Stream::mux_ipb_frame 和 SrsRawH264Stream::mux_avc2flv

这个是ipb贞的编码.

buf[0] = 贞类型和编码. ( (1|2)<<4 | 7 ) 1是关键帧 2是P/B贞 7代表h264

buf[1] = 数据类型 ( 1 = NALU )

buf[2-4] = cts = pts – dts;

buf[5-8] = NAL的长度,不包括贞分隔符

buf[9-] = H264的RAW数据. 不包含分隔符,00 00 01 或者 00 00 00 01

buf[9+NAL_length- +4byte] = 下一个NAL长度 这个很重要,  一个rtmp的视频包可能包括多个NAL的, 切记转换TS的时候把它分割并添加NAL的分隔符,例如{0×00,0×00,0×01}等。 

buf[9+NAL_length+4 -] = 下一个H264的RAW数据.

……

这里需要注意的是cts这个值,如果视频流没有B侦的话,这个cts值=0 ,如果,这个cts值是一个动态数字,你需要根据这个值去计算pts,rtmp协议给的timestamp是DTS来的。如果你简单把pts等与dts的话,播放的时候画面非常乖,有前进后退,前进后退的感觉。 另外rtmp的timestamp与ts流的timestamp需要通过计算转换。

from: http://www.likecode.com/2014/11/21/111/


[转]FLV rtmp 里存在B帧的情况下,time stamp 时间戳应该怎么玩


FLV  rtmp 里存在B帧的情况下,time stamp 应该怎么玩 ?

先来引用stackoverflow的一篇文章:
CompositionTime Composition time offset
See ISO 14496-12, 8.15.3 for an explanation of composition times. The offset in an FLV file is always in milliseconds

provides the offset between decoding time and composition time. Since decoding time must be less than the composition time, the offsets are expressed as unsigned numbers such that CT(n) = DT(n) + CTTS(n) where CTTS(n) is the (uncompressed) table entry for sample n.

For MPEG-4 H.246 transcoders that deliver I-frame, P-frame, and B-frame NALUs inside an MPEG-2 transport, the resulting packetized elementary streams (PES) are timestamped with presentation time stamps (PTS) and decoder timestamps (DTS) in time units of 1/90000 of a second.

The NALUs come in DTS timestamp order in a repeating pattern like

I P B B B P B B B …

where the intended playback rendering is

I B B B P B B B P …

(This transport strategy ensures that both frames that the B-frame bridges are in the decoder before the B-frame is processed.)

For FLV, the Timestamp (FLV spec p.69) tells when the frame should be fed to the decoder in milliseconds, which is

timestamp = DTS / 90.0

The CompositionTime (FLV spec p.72) tells the renderer when to perform (“compose”) the video frame on the display device in milliseconds after it enters the decoder; thus it is

compositionTime = (PTS – DTS) / 90.0

(Because the PTS >= DTS, this delta is never negative.)

大概知道什么意思了没?再来帖 一张图,从flv的标准文档里扣的:

就是给它赋值 compostionTime即可。




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值