5#include "private/qmultimediautils_p.h"
8#include <libavutil/pixdesc.h>
22 const auto *desc = av_pix_fmt_desc_get(
fmt);
26 const int sourceDepth = sourceSwFormatDesc ? sourceSwFormatDesc->comp[0].depth : 0;
28 if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
34 if (desc == sourceSwFormatDesc)
37 if (desc->comp[0].depth == sourceDepth)
39 else if (desc->comp[0].depth < sourceDepth)
40 score -= 100 + (sourceDepth - desc->comp[0].depth);
41 if (desc->log2_chroma_h == 1)
43 if (desc->log2_chroma_w == 1)
45 if (desc->flags & AV_PIX_FMT_FLAG_BE)
47 if (desc->flags & AV_PIX_FMT_FLAG_PAL)
50 if (desc->flags & AV_PIX_FMT_FLAG_RGB)
63 const auto sourceSwFormatDesc = av_pix_fmt_desc_get(sourceFormat);
70 case AV_PIX_FMT_MEDIACODEC:
84 if (constraints && constraints->valid_sw_formats)
85 return findBestAVFormat(constraints->valid_sw_formats, scoreCalculator).first;
92 return AV_PIX_FMT_NONE;
95AVPixelFormat
findTargetFormat(AVPixelFormat sourceFormat, AVPixelFormat sourceSWFormat,
101 const auto hwFormat = accel->
hwFormat();
108 if (constraints &&
hasAVFormat(constraints->valid_hw_formats, hwFormat))
116 if (!
codec->pix_fmts) {
117 qWarning() <<
"Codec pix formats are undefined, it's likely to behave incorrectly";
119 return sourceSWFormat;
126std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
findHwEncoder(AVCodecID codecID,
127 const QSize &resolution)
129 auto matchesSizeConstraints = [&resolution](
const HWAccel &accel) {
130 const auto constraints = accel.constraints();
134 return resolution.
width() >= constraints->min_width
135 && resolution.
height() >= constraints->min_height
136 && resolution.
width() <= constraints->max_width
137 && resolution.
height() <= constraints->max_height;
147const AVCodec *
findSwEncoder(AVCodecID codecID, AVPixelFormat sourceSWFormat)
152 if (!
codec->pix_fmts)
162 auto calcScore = [requestedRate](
const AVRational &
rate) {
179 if (supportedRates) {
180 auto hasFrameRate = [&]() {
193 constexpr int TimeScaleFactor = 1000;
201 if (strcmp(
codec->name,
"h264_mf") == 0) {
202 auto makeEven = [](
int size) {
return size & ~1; };
203 return QSize(makeEven(requestedResolution.width()), makeEven(requestedResolution.height()));
208 return requestedResolution;
static std::pair< const AVCodec *, std::unique_ptr< HWAccel > > findEncoderWithHwAccel(AVCodecID id, const std::function< bool(const HWAccel &)> &hwAccelPredicate=nullptr)
const AVHWFramesConstraints * constraints() const
AVPixelFormat hwFormat() const
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
const AVCodec * findAVEncoder(AVCodecID codecId, const std::optional< AVHWDeviceType > &deviceType, const std::optional< PixelOrSampleFormat > &format)
std::pair< Format, AVScore > findBestAVFormat(const Format *fmts, const CalculateScore &calculateScore)
AVPixelFormat findTargetFormat(AVPixelFormat sourceFormat, AVPixelFormat sourceSWFormat, const AVCodec *codec, const HWAccel *accel)
QSize adjustVideoResolution(const AVCodec *codec, QSize requestedResolution)
std::pair< const AVCodec *, std::unique_ptr< HWAccel > > findHwEncoder(AVCodecID codecID, const QSize &resolution)
static bool isHwFormatAcceptedByCodec(AVPixelFormat pixFormat)
constexpr AVScore DefaultAVScore
bool hasAVFormat(const Format *fmts, Format format)
const AVCodec * findSwEncoder(AVCodecID codecID, AVPixelFormat sourceSWFormat)
constexpr AVScore NotSuitableAVScore
static AVScore calculateTargetSwFormatScore(const AVPixFmtDescriptor *sourceSwFormatDesc, AVPixelFormat fmt)
static auto targetSwFormatScoreCalculator(AVPixelFormat sourceFormat)
AVRational adjustFrameRate(const AVRational *supportedRates, qreal requestedRate)
adjustFrameRate get a rational frame rate be requested qreal rate. If the codec supports fixed frame ...
AVPixelFormat findTargetSWFormat(AVPixelFormat sourceSWFormat, const AVCodec *codec, const HWAccel &accel)
AVRational adjustFrameTimeBase(const AVRational *supportedRates, AVRational frameRate)
adjustFrameTimeBase gets adjusted timebase by a list of supported frame rates and an already adjusted...
constexpr AVScore MinAVScore
auto findBestAVValue(const Value *values, const CalculateScore &calculateScore, Value invalidValue={})
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLenum GLuint GLintptr GLsizeiptr size
[1]
QVideoFrameFormat::PixelFormat fmt