将H.264使用RTMP打包后发送给RED5FMS进行实时发布

    技术2022-05-20  63

    需要从硬压卡上获取的NALU封装成RTMP协议格式发送给RED5/FMS进行实时发布.

     

    RTMP中传送 H.264使用的视频封装格式既是 FLV规范 中的 VideoTag

     

    Frame Type UB [4]

    Type of video frame. The following values are defined:1 = key frame (for AVC, a seekable frame)2 = inter frame (for AVC, a non-seekable frame)3 = disposable inter frame (H.263 only)4 = generated key frame (reserved for server use only)5 = video info/command frame

    CodecID UB [4]

    Codec Identifier. The following values are defined:2 = Sorenson H.2633 = Screen video4 = On2 VP65 = On2 VP6 with alpha channel6 = Screen video version 27 = AVC

    AVCPacketType F UI8

    The following values are defined:0 = AVC sequence header1 = AVC NALU2 = AVC end of sequence (lower level NALU sequence ender isnot required or supported)

    CompositionTime SI24IF AVCPacketType == 1Composition time offsetELSE0See ISO 14496-12, 8.15.3 for an explanation of compositiontimes. The offset in an FLV file is always in milliseconds.

     

    在第一个RTMP Message的数据包中,需要发送 AVC sequence header, 也就是AVCDecoderConfigurationRecord

    其中就包含有Profile / Level / SPS / PPS 等解码需要的信息

     

    然后就开始发送NALU了。

    NALU在一个RTMP Message可以发送1个或者多个。

     

    根据 NALU的 reference idc 可以得出 帧类型

    typedef enum { NALU_PRIORITY_HIGHEST = 3, NALU_PRIORITY_HIGH = 2, NALU_PRIORITY_LOW = 1, NALU_PRIORITY_DISPOSABLE = 0 } NaluRefIdc;

     

    如果这个 VideoTag中含有 NALU_PRIORITY_HIGHEST 的NALU, 那么它的VideoTag的 Frame Type 应该是 FrameType_KeyFrame

    enum FrameType { FrameType_KeyFrame = 1, FrameType_InterFrame = 2, FrameType_DisposableInterFrame = 3, FrameType_GeneratedKeyFrame = 4, FrameType_VideoInfo = 5, };


    最新回复(0)