title: How to write RTP/H264 stream as a file
body: <p>I couldn't find a solution for <a href="https://stackoverflow.com/q/9308976">my previous question</a> so I decided to try it step by step.</p>
  
  <p>The thing that I wanna do now is to store the RTP/H264 stream as a file.</p>
  
  <p>What I found so far is the below:</p>
  
  <p>(firstly my RTP/H264 is FU-A which is the form of)</p>
  
  <pre><code>| RTP HEADER 12bytes long | FU INDICATOR 1byte | FU HEADER 1byte | FU payload |
  </code></pre>
  
  <p>As I understood RFC 6184 document, I'm starting a NAL with a packet which has '1' at the first bit of FU Header and appending following packets that set '0' at the first bit until the last packet which has '1' at the second bit of FU Header.</p>
  
  <p>I think that's how to get a complete NAL before the FU-A packetization and also what I found is I need to put the 'starting bits' (0x00000001) at the front of each complete NAL.</p>
  
  <p>But no luck so far. The below is part of log</p>
  
  <pre><code> ========= the new NAL is as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]7C/1111100 [5]85/10000101 [6]B8/10111000 [7]40/1000000 ...
   ========= adding the next NAL as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]7C/1111100 [5]85/10000101 [6]B8/10111000 [7]40/1000000 ...
   ========= adding the next NAL as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]7C/1111100 [5]85/10000101 [6]B8/10111000 [7]40/1000000 ...
   ========= adding the next NAL as 716
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]7C/1111100 [5]85/10000101 [6]B8/10111000 [7]40/1000000 ...
   ========= a NAL is summed up as 4866
   ========= the new NAL is as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E2/11100010 [7]20/100000 ...
   ========= adding the next NAL as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E2/11100010 [7]20/100000 ...
   ========= adding the next NAL as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E2/11100010 [7]20/100000 ...
   ========= adding the next NAL as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E2/11100010 [7]20/100000 ...
   ========= adding the next NAL as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E2/11100010 [7]20/100000 ...
   ========= adding the next NAL as 139
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E2/11100010 [7]20/100000 ...
   ========= a NAL is summed up as 7061
   ========= the new NAL is as 1377
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]41/1000001 [5]E4/11100100 [6]40/1000000 [7]1A/11010 ...
   ========= a NAL is summed up as 1369
   ========= the new NAL is as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E6/11100110 [7]60/1100000 ...
   ========= adding the next NAL as 94
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]E6/11100110 [7]60/1100000 ...
   ========= a NAL is summed up as 1472
   ========= the new NAL is as 447
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]41/1000001 [5]E8/11101000 [6]80/10000000 [7]16/10110 ...
   ========= a NAL is summed up as 439
   ========= the new NAL is as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]EA/11101010 [7]A0/10100000  ...
   ========= adding the next NAL as 1174
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]EA/11101010 [7]A0/10100000 ...
   ========= a NAL is summed up as 2552
   ========= the new NAL is as 1400
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]EC/11101100 [7]C0/11000000 ...
   ========= adding the next NAL as 1364
   [0]0/0 [1]0/0 [2]0/0 [3]1/1 [4]5C/1011100 [5]81/10000001 [6]EC/11101100 [7]C0/11000000 ...
   ========= a NAL is summed up as 2742
   ========= the new NAL is as 1400
   ...
  </code></pre>
  
  <p>my question is,</p>
  
  <ol>
  <li><p>if I can get the complete NALs from the fragmented packets by FU-A, how can I make it as a file which is able to run by VLC or other player?</p></li>
  <li><p>I'm still confused if I have to keep the FU indicator and FU header or not. Somebody said I need to take them only for the very first packet (starting with '1' at the FU header)</p></li>
  </ol>
  
  <p>Any advice will be really appreciated.</p>
  
  <p>Thanks.</p>