From a1209dfc5d00ea6b1cca2080edec5e7c02376205 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 10 May 2021 18:54:17 +0200 Subject: [PATCH] Fixed a video/audio synchronization issue in VideoFFmpegComponent. --- es-core/src/components/VideoFFmpegComponent.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 64445c2c9..51d9a6b7d 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -200,17 +200,14 @@ void VideoFFmpegComponent::readFrames() int allocatedSize = 0; // The pts value is the presentation time, i.e. the time stamp when - // the frame (picture) should be displayed. - double pts = 0.0l; - // This is needed to avoid a potential divide by zero. - if (mVideoFrame->pkt_duration) - pts = static_cast(mVideoFrame->pts) * mVideoTimeBase / - static_cast(mVideoFrame->pkt_duration); - else - pts = static_cast(mVideoFrame->pts) * mVideoTimeBase; + // the frame (picture) should be displayed. The packet dts value is + // used for the basis of the calculation as per the recommendation + // in the FFmpeg documentation for the av_read_frame function. + double pts = static_cast(mPacket->dts) * + av_q2d(mVideoStream->time_base); // Conversion using libswscale. Bicubic interpolation gives a good - // balance between speed and image quality. + // balance between speed and quality. struct SwsContext* conversionContext = sws_getContext( mVideoCodecContext->coded_width, mVideoCodecContext->coded_height,