Skip some first frames.

This commit is contained in:
John Preston 2024-10-24 11:31:29 +04:00
parent ccc6c6daa5
commit 9b9c3d788d
2 changed files with 17 additions and 6 deletions
Telegram/SourceFiles/ui/controls

View file

@ -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

View file

@ -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;