aliakseis / FFmpegPlayer

Simple FFmpeg video player
MIT License
151 stars 44 forks source link

Delayed optimization #21

Open xixihao123 opened 5 years ago

xixihao123 commented 5 years ago

Hi, when I used the ffmpet push camera and then played RTSP video with player, I found that the delay was about 1 second, mainly caused by the displayRunnable() thread, and if deleted for (;;) { const double delay = m_videoStartClock + current_frame.m_pts - GetHiResTime(); if (delay < 0.005) break; if (delay > 0.1) { boost::this_thread::sleep_for( boost::chrono::milliseconds(100 * speedDenominator / speedNumerator)); continue; }

        boost::this_thread::sleep_for(
            boost::chrono::milliseconds(int(delay * 1000. * speedDenominator / speedNumerator)));
        break;
    }

There will be no delay, but it will cause the audio and video to be out of sync. How can we optimize it?

aliakseis commented 5 years ago

Hi,

Could you please try commenting this line:

https://github.com/aliakseis/FFmpegPlayer/blob/aee8686cb7976aa5c23fa2578e7e51178dfb5471/video/videoparserunnable.cpp#L157

    //if (!context.initialized || inNextFrame)
    {
        m_videoStartClock = (m_isPaused ? m_pauseTimer : GetHiResTime()) - pts;
    }
xixihao123 commented 5 years ago

I 've already tried. comment the line. There's no delay. Using OBS to push the camera will be a little bit video and audio are out of sync. Can you shorten the display time?

aliakseis commented 5 years ago

Just to be sure. You mentioned another code line. Have you tried this one?

xixihao123 commented 5 years ago

image What do you mean? I only commented on this line of code, and the audio was about a second slower when I pushed it

aliakseis commented 5 years ago

I am sorry, it looked like you were talking about the line with boost::this_thread::sleep_for() previously

xixihao123 commented 5 years ago

The problem is not very large, playing video stream, think RTSP playing video delay should be only about 200 MS

aliakseis commented 5 years ago

This seems to be tricky area: https://trac.ffmpeg.org/ticket/5018 https://lists.ffmpeg.org/pipermail/ffmpeg-user/2018-April/039590.html