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
qffmpegvideoencoder_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 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 QFFMPEGVIDEOENCODER_P_H
4#define QFFMPEGVIDEOENCODER_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 <QtFFmpegMediaPluginImpl/private/qffmpegencoderthread_p.h>
18#include <QtFFmpegMediaPluginImpl/private/qffmpeg_p.h>
19#include <QtFFmpegMediaPluginImpl/private/qffmpegvideoframeencoder_p.h>
20#include <QtFFmpegMediaPluginImpl/private/qffmpegframerateadapter_p.h>
21#include <qvideoframe.h>
22#include <queue>
23
24QT_BEGIN_NAMESPACE
25
26class QVideoFrameFormat;
27class QMediaEncoderSettings;
28
29namespace QFFmpeg {
31
33{
34public:
35 VideoEncoder(RecordingEngine &recordingEngine, const QMediaEncoderSettings &settings,
36 const QVideoFrameFormat &format, std::optional<AVPixelFormat> hwFormat);
38
39 void addFrame(const QVideoFrame &frame);
40
41protected:
42 bool checkIfCanPushFrame() const override;
43
44private:
45 FrameInfo dequeueAdaptedFrame();
46 void retrievePackets();
47
48 [[nodiscard]] bool tryPushToInputQueue(const QVideoFrame &frame);
49 void saturateEncoderQueue();
50 void flushAdapter();
51
52 bool init() override;
53 void cleanup() override;
54 bool hasData() const override;
55 void processOne() override;
56 void handlePausedChanged(bool paused) override;
57
58 std::pair<qint64, qint64> frameTimeStamps(const QVideoFrame &frame) const;
59
60 QMediaEncoderSettings m_settings;
61 VideoFrameEncoder::SourceParams m_sourceParams;
62
63 struct InputFrame
64 {
65 QVideoFrame frame;
66 bool restartTimeBase = false;
67 };
68 std::queue<InputFrame> m_inputQueue;
69 // Max queue size arbitrarily chosen to limit memory usage (332 MB @ 4K when including one
70 // adapted frame in encoder queue)
71 const size_t m_maxQueueSize = 9;
72 std::queue<FrameInfo> m_encoderQueue;
73
74 VideoFrameEncoderUPtr m_frameEncoder;
75 qint64 m_baseTime = 0;
76 bool m_shouldAdjustTimeBaseForNextFrame = true;
77 qint64 m_lastFrameTime = 0;
78
79 std::optional<qreal> m_fixedSourceFrameRate; // nullopt = variable-rate source
80 FrameRateAdapter m_frameRateAdapter;
81};
82
83} // namespace QFFmpeg
84
85QT_END_NAMESPACE
86
87#endif
The QAudioFormat class stores audio stream parameter information.
bool initialize(const std::vector< QAudioBufferSource * > &audioSources, const std::vector< QPlatformVideoSource * > &videoSources)
bool init() override
Called on this thread when thread starts.
bool checkIfCanPushFrame() const override
~VideoEncoder() override
void processOne() override
Process one work item.
void cleanup() override
Called on this thread before thread exits.
void handlePausedChanged(bool paused) override
bool hasData() const override
Must return true when data is available for processing.
void disconnectEncoderFromSource(EncoderThread *encoder)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)