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 <qvideoframe.h>
21#include <queue>
22
23QT_BEGIN_NAMESPACE
24
25class QVideoFrameFormat;
26class QMediaEncoderSettings;
27
28namespace QFFmpeg {
29class VideoFrameEncoder;
30
31class VideoEncoder : public EncoderThread
32{
33public:
34 VideoEncoder(RecordingEngine &recordingEngine, const QMediaEncoderSettings &settings,
35 const QVideoFrameFormat &format, std::optional<AVPixelFormat> hwFormat);
36 ~VideoEncoder() override;
37
38 void addFrame(const QVideoFrame &frame);
39
40protected:
41 bool checkIfCanPushFrame() const override;
42
43private:
44 struct FrameInfo
45 {
46 QVideoFrame frame;
47 bool shouldAdjustTimeBase = false;
48 };
49
50 FrameInfo takeFrame();
51 void retrievePackets();
52
53 bool init() override;
54 void cleanup() override;
55 bool hasData() const override;
56 void processOne() override;
57
58 std::pair<qint64, qint64> frameTimeStamps(const QVideoFrame &frame) const;
59
60private:
61 QMediaEncoderSettings m_settings;
62 VideoFrameEncoder::SourceParams m_sourceParams;
63 std::queue<FrameInfo> m_videoFrameQueue;
64 const size_t m_maxQueueSize = 10; // Arbitrarily chosen to limit memory usage (332 MB @ 4K)
65
66 VideoFrameEncoderUPtr m_frameEncoder;
67 qint64 m_baseTime = 0;
68 bool m_shouldAdjustTimeBaseForNextFrame = true;
69 qint64 m_lastFrameTime = 0;
70};
71
72} // namespace QFFmpeg
73
74QT_END_NAMESPACE
75
76#endif
77

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder_p.h