title: Reconstructing fragmented H.264 stream
body: <p>I have H.264 stream stored as a file. I am trying to create a MPEG4 file by adding this stream to MDAT BOX. I have created other headers required by MPEG-4 standards. But I am unable to read the MPEG-4 file.</p>
  
  <p>I parsed the H.264 stream and I see that there are multiple I-frames in the file. It seems to me that this is fragmented H.264 stream. </p>
  
  <p>Is there any way in which this fragmented H.264 stream can be combined into a single I-frame?</p>
  
  <p>I have gone through the link <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>I implemented what was mentioned in the link but i am still unable to run the MPEG-4 thus created.</p>
  
  <p>With the above technique, I get the fragmentType = 5. I get the following nalTypes (8, 2, 1, 0, 0, ...). I get the startBit as specified and for the other fragments, I get the 00 (for StartBit|endBit). I do not get the endBit.</p>
  
  <p>When i try using FFMPEG to reconvert the MPEG-4 file that was created, i get the following error: "header damaged". It looks like the reconstruction of IDR frames is not working properly.</p>
  
  <p>Please let me know if the method that I am following has any issues.</p>
  
  <p>The H.264 stream file is around 100KB. When this file is converted to MP4 using FFMPEG, I get around 38KB. Does it mean that FFMPEG is re-encoding the file once again inorder to recreate the MP4 file?</p>
  
  <p>With the above technique that was mentioned in the link, the MP4 that I have created is around 100KB itself.</p>
  
  <p>Please let me know what I am doing that is wrong.</p>
  
  <p>Thanks in advance.</p>