title: Save Live Video Stream To Local Storage
body: <p><strong>Problem:</strong> </p>
  
  <pre><code>I have to save live video streams data which come as an RTP packets from RTSP Server.
  The data come in two formats : MPEG4 and h264. 
  I do not want to encode/decode input stream.
  Just write to a file which is playable with proper codecs. 
  </code></pre>
  
  <p>Any advice?</p>
  
  <p>Best Wishes</p>
  
  <p><strong>History:</strong></p>
  
  <p><strong>My Solutions and their problems:</strong></p>
  
  <p><strong>Firt attempt:</strong> FFmpeg</p>
  
  <pre><code>I use FFmpeg libary to get audio and video rtp packets. 
  But in order to write packets i have to use av_write_frame : 
  which seems that decode /encode takes place.
  Also, when i give output format as mp4 ( av_guess_format("mp4", NULL, NULL)
  the output file is unplayable. 
  [ any way ffmpeg has bad doc. hard to find what is wrong]
  </code></pre>
  
  <p><strong>Second attempth</strong>: DirectShow</p>
  
  <pre><code>Then i decide to use DirectShow. I found a RTSP Source Filter. 
  Then a Mux and File Writer.
  Cretae Single graph:
  
  RTSP Source --&gt; MPEG MUX ---&gt; File Writer
  
  It worked but the problem is that  the output file is not playable
  if graph is not stoped. If something happens, graph crashed for example
  the output file is not playable
  Also i can able to write H264 data, but the video is completely unplayable.
  </code></pre>