title: FFmpeg How to write video to a file
body: <p>What i want is</p>
  
  <pre><code> 1. Get video packet from stream source
   2. Decode it
   3. And write  that decoded data as video file(avi, mpeg etc)
  </code></pre>
  
  <p>I can able to get video Packets from a file (as AVPacket) and also can decode and save as an image.(raw)( FFmpeg tutorials show how to do it).
  <strong>But i can not</strong> ( do not know ) <strong>write that video data to a file</strong>(other) which can be played by media players(such as VLC).</p>
  
  <p>Best Wishes</p>
  
  <p>Ps: Real code samples will be great if possible...</p>
  
  <p>Now i make test with <strong>av_interleaved_write</strong>  but i got strange error "non monotone timestamps" ( i have no control over pts values of media source )</p>
  
  <p><strong>Some Extra Info</strong></p>
  
  <p>In FFmpeg I have to </p>
  
  <ol>
  <li>Read media packets from media source ( it may be real file(.avi,mov) or even rtsp server).</li>
  <li>Then write those media packets to a real file (physical .avi, .mov etc file)</li>
  </ol>
  
  <p>I need reader and writer. I can read the media source file ( even encode packets according to given format). But i can not write to  file...(which any player  can play)</p>
  
  <p>And some pseudoCode</p>
  
  <pre><code>File myFile("MyTestFile.avi");
  
  while ( source -&gt;hasVideoPackets)
  {
       packet = source-&gt;GetNextVideoPacket();
       Frame decodedFrame = Decode(packet);
       VideoPacket encodedPacket = Encode( decodedFrame);
       myFile.WriteFile(encodedPacket);
   }
  </code></pre>
  
  <p>Or Just write the original file without encode decode</p>
  
  <pre><code>     File myFile("MyTestFile.avi");
  
       while ( source -&gt;hasVideoPackets)
       {
           packet = source-&gt;GetNextVideoPacket();
           myFile.WriteFile(packet);
       }
  </code></pre>
  
  <p>Then </p>
  
  <pre><code>I can able to open MyTest.avi file with a player.
  </code></pre>