RtspServer icon indicating copy to clipboard operation
RtspServer copied to clipboard

Invalid NAL unit 0, skipping in VLC and ffplay can not play buf fixed

Open fatalfeel opened this issue 3 years ago • 1 comments

I fixed h264 h265 Invalid NAL unit 0, skipping buf fixed

  1. rtp.h //refer to live555 H264or5VideoRTPSink.cpp MultiFramedRTPSink.cpp //RTP hdr size is 12, ourMaxPacketSize()-12 = 1452 -12 #define MAX_RTP_PAYLOAD_SIZE 1420
#define MAX_RTP_PAYLOAD_SIZE   1440

//#define RTP_TCP_HEAD_SIZE	   4 //when transport_mode_ = RTP_OVER_TCP
~~~change to
#define RTP_TCP_HEAD_SIZE      0 //when transport_mode_ = RTP_OVER_UDP

2. H264Source.cpp
if (frame_size <= MAX_RTP_PAYLOAD_SIZE)
{
    frame_buf  += 4; //shift to nalu position
    frame_size -= 4;
    RtpPacket rtp_pkt;
    rtp_pkt.type = frame.type;
    rtp_pkt.timestamp = frame.timestamp;
    rtp_pkt.size = frame_size + RTP_TCP_HEAD_SIZE + RTP_HEADER_SIZE;
    rtp_pkt.last = 1;
    ...
}
else
{
    frame_buf  += 4; //shift to nalu position
    frame_size -= 4;
    char FU_A[2] = {0};
    FU_A[0] = (frame_buf[0] & 0xE0) | 28;
    FU_A[1] = 0x80 | (frame_buf[0] & 0x1F);
}

3. H265Source.cpp
if (frame_size <= MAX_RTP_PAYLOAD_SIZE)
{
    frame_buf  += 4; //shift to nalu position
    frame_size -= 4;
    RtpPacket rtp_pkt;
    rtp_pkt.type = frame.type;
    rtp_pkt.timestamp = frame.timestamp;
    rtp_pkt.size = frame_size + RTP_TCP_HEAD_SIZE + RTP_HEADER_SIZE;
    rtp_pkt.last = 1;
    ...
}
else
{
    frame_buf  += 4; //shift to nalu position
    frame_size -= 4;
    uint8_t PL_FU[3] = {0};
    uint8_t nalUnitType = (frame_buf[0] & 0x7E) >> 1;
    PL_FU[0] = (frame_buf[0] & 0x81) | (49<<1);
    PL_FU[1] = frame_buf[1];
    PL_FU[2] = 0x80 | nalUnitType;
}




fatalfeel avatar Jul 02 '22 10:07 fatalfeel

download fixed file here https://fatalfeel.blogspot.com/2013/12/rtsp-server-for-h264-h265-aac.html

fatalfeel avatar Jul 07 '22 05:07 fatalfeel