From 9b9c3d788d336d15914413788b4cf5dfceb9d3c9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 24 Oct 2024 11:31:29 +0400 Subject: [PATCH] Skip some first frames. --- .../ui/controls/round_video_recorder.cpp | 22 ++++++++++++++----- .../ui/controls/round_video_recorder.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp index 5c29cc65e..f58eeb2dc 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp @@ -35,6 +35,7 @@ constexpr auto kBlurredSize = 64; constexpr auto kMinithumbsPerSecond = 5; constexpr auto kMinithumbsInRow = 16; constexpr auto kFadeDuration = crl::time(150); +constexpr auto kSkipFrames = 8; using namespace FFmpeg; @@ -1317,15 +1318,23 @@ void RoundVideoRecorder::setup() { } }, raw->lifetime()); + // Skip some frames, they are sometimes black :( + _skipFrames = kSkipFrames; + _descriptor.track->setState(Webrtc::VideoState::Active); + _descriptor.track->renderNextFrame() | rpl::start_with_next([=] { const auto info = _descriptor.track->frameWithInfo(true); if (!info.original.isNull() && _lastAddedIndex != info.index) { _lastAddedIndex = info.index; - _frameOriginal = info.original; - const auto ts = info.mcstimestamp; - _private.with([copy = info.original, ts](Private &that) { - that.push(ts, copy); - }); + if (_skipFrames > 0) { + --_skipFrames; + } else { + _frameOriginal = info.original; + const auto ts = info.mcstimestamp; + _private.with([copy = info.original, ts](Private &that) { + that.push(ts, copy); + }); + } } _descriptor.track->markFrameShown(); raw->update(); @@ -1412,9 +1421,10 @@ void RoundVideoRecorder::resume(RoundVideoPartial partial) { if (!_cachedPreviewFrame.image.isNull()) { _fadePreviewAnimation.start(updater(), 1., 0., kFadeDuration); } + // Skip some frames, they are sometimes black :( + _skipFrames = kSkipFrames; _descriptor.track->setState(Webrtc::VideoState::Active); _preview->update(); } } // namespace Ui - diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.h b/Telegram/SourceFiles/ui/controls/round_video_recorder.h index 57f47b8ca..b98d313cc 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.h +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.h @@ -120,6 +120,7 @@ private: int _side = 0; int _progressStroke = 0; int _extent = 0; + int _skipFrames = 0; bool _progressReceived = false; bool _visible = false; bool _paused = false;