From 4465342724a683c72c631200207d6cc8ad5a2e31 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 12 May 2021 22:55:00 +0200 Subject: [PATCH] Added an audio buffer to VideoFFmpegComponent to avoid underflows and distortion. --- es-core/src/components/VideoFFmpegComponent.cpp | 5 +++-- es-core/src/components/VideoFFmpegComponent.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 1aa0647fe..138986d35 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -445,9 +445,10 @@ void VideoFFmpegComponent::outputFrames() } } - // Process all available audio frames that have a pts value below mAccumulatedTime. + // Process the audio frames that have a pts value below mAccumulatedTime (plus a small + // buffer to avoid underflows). while (!mAudioFrameQueue.empty()) { - if (mAudioFrameQueue.front().pts < mAccumulatedTime) { + if (mAudioFrameQueue.front().pts < mAccumulatedTime + AUDIO_BUFFER) { // Enable only when needed, as this generates a lot of debug output. // LOG(LogDebug) << "Processing audio frame with PTS: " << // mAudioFrameQueue.front().pts; diff --git a/es-core/src/components/VideoFFmpegComponent.h b/es-core/src/components/VideoFFmpegComponent.h index 02b3033e5..b5e911400 100644 --- a/es-core/src/components/VideoFFmpegComponent.h +++ b/es-core/src/components/VideoFFmpegComponent.h @@ -9,7 +9,8 @@ #ifndef ES_CORE_COMPONENTS_VIDEO_FFMPEG_COMPONENT_H #define ES_CORE_COMPONENTS_VIDEO_FFMPEG_COMPONENT_H -#define VIDEO_FRAME_QUEUE_SIZE 3 +// Audio buffer in seconds. +#define AUDIO_BUFFER 0.2l #include "VideoComponent.h"