RTP包中的H.264格式


今天写了个demo将264码流中的sps封成rtp包发送,用wireshark抓包后分析数据正确

int num = 0;
/*    
ByteArrayOutputStream bas = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bas);
*/
DataInputStream dis = new DataInputStream(new FileInputStream( new File(SDcardPath,"newStream264.h264") ));
    
byte[] spsbuffer = new byte[9];
//读sps
dis.readInt();          //略过前缀码
dis.read(spsbuffer,0,9);            
   
byte[] rtpbuffer = new byte[12+9];
   
RtpPacket rtp_sps = new RtpPacket(rtpbuffer,12+9);
   
rtp_sps.setSequenceNumber(seq_num++);
rtp_sps.setMarker(true);
rtp_sps.setTimestamp(time_scale+time_inc);
time_scale += time_inc;
rtp_sps.setSscr(ssrc);
//                rtp_sps.setPayloadType(96);

rtp_sps.setPayload(spsbuffer, 9);
   
socket.send(rtp_sps);         
   
socket.close();
dis.close();
dis = null;

RtpPacket这个类用起来稍显笨重,需要设置的参数主要有:

  • sequence number要求递增
  • Marker具体含义还不清楚
  • timestamp也是要递增
  • sscr具体含义不清楚
  • payload是一个buffer