title: FFmpeg decoding .mp4 video file
body: <p>I'm working on a project that needs to open .mp4 file format, read it's frames 1 by 1, decode them and encode them with better type of lossless compression and save them into a file.</p>
  
  <p>Please correct me if i'm wrong with order of doing things, because i'm not 100% sure how this particular thing should be done. From my understanding it should go like this:</p>
  
  <pre><code>1. Open input .mp4 file
  2. Find stream info -&gt; find video stream index
  3. Copy codec pointer of found video stream index into AVCodecContext type pointer
  4. Find decoder -&gt; allocate codec context -&gt; open codec
  5. Read frame by frame -&gt; decode the frame -&gt; encode the frame -&gt; save it into a file
  </code></pre>
  
  <p>So far i encountered couple of problems. For example, if i want to save a frame using <code>av_interleaved_write_frame()</code> function, i can't open input .mp4 file using <code>avformat_open_input()</code> since it's gonna populate <code>filename</code> part of the <code>AVFormatContext</code> structure with input file name and therefore i can't "write" into that file. I've tried different solution using <code>av_guess_format()</code> but when i dump format using <code>dump_format()</code> i get nothing so i can't find stream information about which codec is it using.</p>
  
  <p>So if anyone have any suggestions, i would really appreciate them. Thank you in advance.</p>