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 <qvideoframe.h>
21#include <queue>
22
23QT_BEGIN_NAMESPACE
24
25class QVideoFrameFormat;
26class QMediaEncoderSettings;
27
28namespace QFFmpeg {
30
32{
33public:
34 VideoEncoder(RecordingEngine &recordingEngine, const QMediaEncoderSettings &settings,
35 const QVideoFrameFormat &format, std::optional<AVPixelFormat> hwFormat);
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
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.
bool hasData() const override
Must return true when data is available for processing.
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType
void disconnectEncoderFromSource(EncoderThread *encoder)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)