title: How to get current frame number using ffmpeg c++
body: <p>Usually, I use the below code to get the current frame number when decoding a video. </p>
  
  <pre><code>while(av_read_frame(pFormatCtx, &amp;packet)&gt;=0) {
      if(packet.stream_index==videoStream) {
        // Decode video frame
        avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);
  
        // Did we get a video frame?
        if(frameFinished) {
      int currentFrameNumber = pFrame-&gt;coded_picture_number; 
      }
      /* Free the packet that was allocated by av_read_frame*/
      av_free_packet(&amp;packet);
    }
  </code></pre>
  
  <p>Then, when I implemented seeking feature, I add av_seek_frame to seek to a desired position like this:</p>
  
  <pre><code>if(av_seek_frame(pFormatCtx, -1, seekTarget, 0 )&lt;0){
           LOG("log","error when seeking");
  }
  while(av_read_frame(pFormatCtx, &amp;packet)&gt;=0) {
          if(packet.stream_index==videoStream) {
            // Decode video frame
            avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);
  
            // Did we get a video frame?
            if(frameFinished) {
          int currentFrameNumber = pFrame-&gt;coded_picture_number; 
          }
          /* Free the packet that was allocated by av_read_frame*/
          av_free_packet(&amp;packet);
   }
  </code></pre>
  
  <p>This is when the problem arises. pFrame->coded_picture_number returns incorrect value. 
  My question is how I cam get the current frame given I have a decoded frame pFrame ? </p>