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
qffmpegvideoencoderutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QFFMPEGVIDEOENCODERUTILS_P_H
4#define QFFMPEGVIDEOENCODERUTILS_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/qffmpegdefs_p.h>
18#include <QtFFmpegMediaPluginImpl/private/qffmpeghwaccel_p.h>
19
20#include <QtMultimedia/private/qmultimedia_ranges_p.h>
21#include <QtCore/qspan.h>
22
23QT_BEGIN_NAMESPACE
24
25namespace QFFmpeg {
26
27// accel == nullptr probes/looks up the plain path (no hw_frames_ctx, i.e. ByteBuffer/MMAP-style
28// transport); accel != nullptr probes/looks up the path where the codec is opened with a
29// throwaway hw frames context using accel's hw format (Surface/DMABUF-style transport). The two
30// can accept different sw formats on real hardware (e.g. Android MediaCodec, V4L2 M2M).
31std::vector<AVPixelFormat> encoderPixelFormats(const Codec &, QSize resolution,
32 const HWAccel *accel);
33std::vector<AVPixelFormat> probePixelFormats(const Codec &, QSize resolution,
34 const HWAccel *accel);
35
36std::optional<AVPixelFormat> findTargetSWFormat(AVPixelFormat sourceSWFormat, const Codec &codec,
37 const HWAccel &accel, QSize resolution);
38
39AVScore scoreTargetSwFormat(AVPixelFormat source, AVPixelFormat target);
40
46
47// sorted by score. accel == nullptr for pure software encoders
48std::vector<ScoredPixelFormat> findAndScoreTargetSWFormats(AVPixelFormat sourceSWFormat,
49 const Codec &, const HWAccel *,
50 QSize resolution);
51
52std::optional<AVPixelFormat> findTargetFormat(AVPixelFormat sourceSWFormat, const Codec &codec,
53 const HWAccel *accel, QSize resolution);
54
55AVScore findSWFormatScores(const Codec &codec, AVPixelFormat sourceSWFormat, QSize resolution);
56
57/**
58 * @brief adjustFrameRate resolves the effective frame rate to negotiate with a codec.
59 *
60 * settingsRate is the user-requested rate from QMediaEncoderSettings
61 * (<= 0 means unset). sourceRate is the source stream's fixed rate
62 * (<= 0 means variable/unknown).
63 *
64 * Target rate priority: settingsRate, if set, always wins. Otherwise sourceRate,
65 * if fixed, is used. Otherwise, if the codec cannot do variable rate
66 * (non-empty supportedRates), DefaultVideoFrameRate is used as a
67 * last-resort target. If the codec can do variable rate (empty
68 * supportedRates) and neither settingsRate nor sourceRate is set,
69 * the result stays variable ({0, 1}).
70 *
71 * If the codec supports only fixed frame rates (non-null
72 * supportedRates), the function selects the closest supported rate
73 * to the resolved preference; otherwise it converts the preference
74 * directly to an AVRational.
75 */
76AVRational adjustFrameRate(QSpan<const AVRational> supportedRates, qreal settingsRate,
77 qreal sourceRate);
78
79/**
80 * @brief adjustFrameTimeBase gets adjusted timebase by a list of supported frame rates
81 * and an already adjusted frame rate.
82 *
83 * Timebase is the fundamental unit of time (in seconds) in terms
84 * of which frame timestamps are represented.
85 * For fixed-fps content (non-null supportedRates, or isFixedRate true),
86 * timebase should be 1/framerate.
87 *
88 * For more information, see AVStream::time_base and AVCodecContext::time_base.
89 *
90 * The adjusted time base is supposed to be set to stream and codec context.
91 */
92AVRational adjustFrameTimeBase(QSpan<const AVRational> supportedRates, AVRational frameRate,
93 bool isFixedRate);
94
95QSize adjustVideoResolution(const Codec &codec, QSize requestedResolution);
96
97SwsFlags getScaleConversionType(const QSize &sourceSize, const QSize &targetSize);
98
99} // namespace QFFmpeg
100
101QT_END_NAMESPACE
102
103#endif // QFFMPEGVIDEOENCODERUTILS_P_H
std::vector< ScoredPixelFormat > findAndScoreTargetSWFormats(AVPixelFormat sourceSWFormat, const Codec &codec, const HWAccel *accel, QSize resolution)
SwsFlags getScaleConversionType(const QSize &sourceSize, const QSize &targetSize)
QSize adjustVideoResolution(const Codec &codec, QSize requestedResolution)
std::optional< AVPixelFormat > findTargetFormat(AVPixelFormat sourceSWFormat, const Codec &codec, const HWAccel *accel, QSize resolution)
std::vector< AVPixelFormat > encoderPixelFormats(const Codec &codec, QSize resolution, const HWAccel *accel)
AVRational adjustFrameRate(QSpan< const AVRational > supportedRates, qreal settingsRate, qreal sourceRate)
adjustFrameRate resolves the effective frame rate to negotiate with a codec.
AVScore scoreTargetSwFormat(AVPixelFormat source, AVPixelFormat target)
std::optional< AVPixelFormat > findTargetSWFormat(AVPixelFormat sourceSWFormat, const Codec &codec, const HWAccel &accel, QSize resolution)
AVRational adjustFrameTimeBase(QSpan< const AVRational > supportedRates, AVRational frameRate, bool isFixedRate)
adjustFrameTimeBase gets adjusted timebase by a list of supported frame rates and an already adjusted...
AVScore findSWFormatScores(const Codec &codec, AVPixelFormat sourceSWFormat, QSize resolution)
std::vector< AVPixelFormat > probePixelFormats(const Codec &codec, QSize resolution, const HWAccel *accel)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)