title: Saving H264 RTP Packets In Useful Form
body: <p>I know that it is possible to save RTP h264 streams using Wireshark and VLC. But in order to learn more about video streaming I am trying to do it myself.  There are several related questions that make for good reading on this topic:</p>
  
  <p><a href="https://stackoverflow.com/questions/7665217/how-to-process-raw-udp-packets-so-that-they-can-be-decoded-by-a-decoder-filter-i">How to process raw UDP packets so that they can be decoded by a decoder filter in a directshow source filter</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3493742/problem-to-decode-h264-video-over-rtp-with-ffmpeg-libavcodec">Problem to Decode H264 video over RTP with ffmpeg (libavcodec)</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15404047/how-to-convert-h-264-udp-packets-to-playable-media-stream-or-file-defragmentati">How to convert H.264 UDP packets to playable media stream or file (defragmentation)</a></p>
  
  <p>With those as background, this is where I am currently:</p>
  
  <ul>
  <li>I can receive RTP packets over UTP.</li>
  <li>I parse packets as discussed in the questions above.</li>
  <li>I write the packets to a file, separated by \x000001 and add the NAL byte again according to the above guides.</li>
  <li>At the beginning of the file I put the SPS and PPS which I got from my code's RTSP conversation with the server (again seperated by the correct bytes).  </li>
  </ul>
  
  <p>I end up with a file of supposedly a lot of NAL frames.  I then try to run ffmpeg on the .264 file to create a .mp4.  This brings up several errors:</p>
  
  <p>[h264 @ 0x15257a0] decode_slice_header error</p>
  
  <p>[h264 @ 0x15257a0] no frame!</p>
  
  <p>[h264 @ 0x15257a0] non-existing PPS referenced</p>
  
  <p>[h264 @ 0x15257a0] non-existing PPS 0 referenced</p>
  
  <p>[buffer @ 0x15e16a0] Invalid pixel format string '-1'</p>
  
  <p>I am essentially at a standstill until I can figure out this problem.  I have thouroughly read the questions I linked to above, and the stream is definitely viewable because I can connect and watch it via VLC and the incoming packets are definitely H264 RTP packets according to wireshark.  If VLC can do it why can't I! I would greatly appreciate any insight into my errors and possible a summary of the three linked questions that resolves the disagreements between them.</p>