Question: I try to control the playback speed of my video using ffmpeg + opengl. But I have problems.

My video is encoded at 25 fps and plays very fast. I added this in my code.

```
tiempo = glfwGetTime();
duracion = 1.0/25.0; // 1 second / 25 fps

while(1){

...        

  if(glfwGetTime() > tiempo + duracion){
    if(av_read_frame(pFormatCtx,&packet) >= 0){
      if(packet.stream_index == 0){
        avcodec_decode_video2(pCodecCtx,pFrame,&frameFin,&packet);
        if(frameFin)sws_scale(img_convert_ctx,pFrame->data,pFrame->linesize,0,pCodecCtx->height,pFrameRGB->data,pFrameRGB->linesize);
      }
      av_free_packet(&packet);
    }
    tiempo = glfwGetTime();
  }

...

}

```

The problem is that now the video plays slower than it should. What is the problem?

Answer: 
You added the time the decoding needs to decode the Image to the 40ms you have to wait for displaying the next. This error is because you measure the time again at the end of your loop.

instead of:

```
    }
    tiempo = glfwGetTime();
  }

```

write:

```
   }
   tiempo+=duraction;
}

```
I think this is wrong:
 if(glfwGetTime() > tiempo + duracion){
 //...
 tiempo = glfwGetTime();

because the first call to glfwGetTime and the second are not the same -> you should cache it in a variable and compare with the same.