title: How to seek by msec with ffmpeg?
body: <p>I am trying to seek in video by milliseconds with ffmpeg. I have been trying to use code from <a href="https://stackoverflow.com/questions/5261658/how-to-seek-in-ffmpeg-c-c">this question</a>, which uses <code>avformat_seek_file</code> (i use it with -1 for stream number and AVSEEK_FLAG_ANY flag).</p>
  
  <p>After that is called, i try to read next frames, that is:</p>
  
  <pre><code>if (av_read_frame(fmt_ctx, &amp;pkt) &gt;= 0)
  {
      int ret = 0;
  
      if (pkt.stream_index == video_stream_idx) {
          /* decode video frame */
          ret = avcodec_decode_video2(video_dec_ctx, frame, got_frame, &amp;pkt);
          if (ret &lt; 0) {
              fprintf(stderr, "Error decoding video frame\n");
              return ret;
          }
  //do something with frame
  }
  </code></pre>
  
  <p>However, the <code>frame-&gt;pts</code> of retrieved frame always holds the time of the frame that was immediatly after last frame that was read before seeking.</p>
  
  <p>Edit: In spite of frame->pts forming unbroken sequence, seeking does occur. For some bizarre reason next frame i read is the first one. In fact, after i run:</p>
  
  <pre><code>   int got_frame = 0;
     do
     if (av_read_frame(fmt_ctx, &amp;pkt) &gt;= 0) {
         decode_packet_ro(&amp;got_frame, 0);
         av_free_packet(&amp;pkt);
     }
     else
     {
         read_cache = true;
         pkt.data = NULL;
         pkt.size = 0;
         break;
     }
     while(!got_frame || this-&gt;frame-&gt;pts*av_q2d(video_dec_ctx-&gt;time_base) * 1000 &lt; tsms);
  </code></pre>
  
  <p>next frame i read is always the first one.</p>