title: FFmpeg API example (encode_video.c) does not work correctly
body: <p>I am using the official <a href="https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/encode_video.c" rel="nofollow noreferrer">encode_video.c</a> example to test if FFmpeg works correctly for me. 
  I got the pre-built windows edition from <a href="https://ffmpeg.zeranoe.com/builds/" rel="nofollow noreferrer">ffmpeg.zeranoe.com/builds</a>. It is built already with libx264 and other external libraries. I got both dev and shared editions and added the DLLs, header files and libs accordingly in Visual Studio. </p>
  
  <p>Now the encode_video.c example does not work correctly.</p>
  
  <p><br></p>
  
  <p><strong>What I tried:</strong></p>
  
  <p>I compiled the example and run it on many different file formats and codecs such as the following.</p>
  
  <p>First I tried all of these file formats (.mp4, .m4v, .h264, .x264, .avi, .flv) with codec name as libx264. The code executed without errors but the output video file did not play in VLC or Windows 10 default player.</p>
  
  <p>Next, I tried all of those above file formats but with codec name as mpeg4. The code executed without errors but the output video file played only for <strong>.m4v</strong> in VLC.</p>
  
  <p><br></p>
  
  <p><strong>What is expected:</strong></p>
  
  <p>All of those combinations should have produced a video file which could be played in VLC. None of them worked except for <strong>.m4v</strong> as file format and <strong>mpeg4</strong> as codec name.</p>
  
  <p><br></p>
  
  <p>Please tell me how to make this work for h264. I mainly want it to work for h264 as that is only important for now.</p>
  
  <p>I am running the code like <code>./encode_video.exe test.mp4 libx264</code> where first argument is output filename and second argument is codec name.</p>
  
  <p>This is the output for test.mp4 and libx264 as command line arguments <a href="https://imgur.com/a/AHLQwuK" rel="nofollow noreferrer">https://imgur.com/a/AHLQwuK</a></p>
  
  <p>It seems that in the <code>encode</code> function, it goes over the below code and returns because of AVERROR(EAGAIN) or AVERROR_EOF. Please tell me what is happening.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>while (ret &gt;= 0) {
          ret = avcodec_receive_packet(enc_ctx, pkt);
          if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
              return;
          else if (ret &lt; 0) {
              fprintf(stderr, "Error during encoding\n");
              exit(1);
          }
  
          printf("Write packet %3"PRId64" (size=%5d)\n", pkt-&gt;pts, pkt-&gt;size);
          fwrite(pkt-&gt;data, 1, pkt-&gt;size, outfile);
          av_packet_unref(pkt);
      }
  </code></pre>
  
  <p>I used DepenciesGUI to find out the DLLs linked and it shows that the DLLs are correctly linked. Please help me figure out what the problem is now!!</p>