Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qffmpegframerateadapter_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QFFMPEGFRAMERATEADAPTER_P_H
4#define QFFMPEGFRAMERATEADAPTER_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtMultimedia/qvideoframe.h>
18#include <QtCore/qlist.h>
19#include <QtFFmpegMediaPluginImpl/private/qffmpegrecordingengineutils_p.h>
20
21#include <optional>
22
23QT_BEGIN_NAMESPACE
24
25namespace QFFmpeg {
26
27// Adapts an incoming video stream to a target frame rate by dropping (source faster)
28// or duplicating (source slower) frames. Output PTS is slot-aligned and never adjusted
29// backward relative to the encoded frame's capture time.
31{
32public:
33 FrameRateAdapter() = default;
34
35 void setRates(std::optional<double> sourceRate, double targetRate);
36
37 [[nodiscard]] bool isActive() const { return m_slotDuration > 0; }
38 [[nodiscard]] qint64 frameDuration() const { return m_slotDuration; }
39
40 // Process one frame. Returns frames to be encoded.
41 // Returns an empty queue when the frame was buffered as a pending candidate
42 // (a later frame will trigger its emission with a forward-adjusted PTS).
43 // adjustTimeBase is stored alongside the pending frame and forwarded to
44 // the first output frame when the pending candidate is eventually emitted.
45 std::vector<FrameInfo> adapt(const QVideoFrame &frame, bool adjustTimeBase = false);
46
48
49 // Clear all internal state (call on pause/seek).
50 void reset();
51
52private:
53 [[nodiscard]] FrameInfo emitPendingFrame(bool keepPending = true);
54
55 qint64 m_slotDuration{ 0 }; // µs per encoder frame; 0 = inactive
56 qint64 m_nextSlotTime{ -1 }; // next slot boundary in µs; -1 = uninitialized
57 qint64 m_slotMatchEpsilon{ 0 };
58
59 std::optional<FrameInfo> m_pendingFrame;
60 std::optional<qint64> m_sourceDuration{ 0 };
61 bool m_pendingNeedsFlush{ false };
62};
63
64} // namespace QFFmpeg
65
66QT_END_NAMESPACE
67
68#endif
std::optional< FrameInfo > flush()
void setRates(std::optional< double > sourceRate, double targetRate)
std::vector< FrameInfo > adapt(const QVideoFrame &frame, bool adjustTimeBase=false)
QT_MANGLE_NAMESPACE(QMacScreenCaptureStreamDelegate) QMacScreenCaptureStreamDelegate
Combined button and popup list for selecting options.