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

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