leixiaohua1020 / simplest_ffmpeg_player

the simplest video player based on FFmpeg
http://leixiaohua1020.github.io/
680 stars 374 forks source link

simplest_ffmpeg_player_su plays interplay mve files too fast #1

Open grepwood opened 8 years ago

grepwood commented 8 years ago

I've changed the source so that we can specify what file to play.

    //char filepath[]="Titanic.ts";
    char * filepath = NULL;
    if(argc != 2) {
        printf("Usage: %s [FILE]\n",argv[0]);
        return 1;
    }
    filepath = argv[1];

Here is a free sample that exhibits the same problem as all files of this format: https://sucs.org/~grepwood/FreeRadical/moognu.mve For comparison, the original is available here: https://archive.org/download/M00GNU/Freedom-catmoognu.ogv

If you play both files with ffplay, they play at the same speed. So, obviously there is a problem with the way simplest_ffmpeg_player_su works.

grepwood commented 8 years ago

I think I found a solution. In the function passed into SDL thread, we need to SDL_Delay by an accurate delay instead of 40, because 40ms is exactly the time that a frame is displayed at 25fps. To calculate the correct delay, do:

accurate_delay = (uint32_t)(pow((pFormatCtx->streams[0]->avg_frame_rate.num)/(double)(pFormatCtx->streams[0]->avg_frame_rate.den),-1)*1000.0);

Update: This does not fix the issue entirely. There are still 9 seconds lost for a 3m19s movie.