7#include <libavutil/pixdesc.h>
17 const auto *
desc = av_pix_fmt_desc_get(
fmt);
21 const int sourceDepth = sourceSwFormatDesc ? sourceSwFormatDesc->comp[0].depth : 0;
23 if (
desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
29 if (
desc == sourceSwFormatDesc)
32 if (
desc->comp[0].depth == sourceDepth)
34 else if (
desc->comp[0].depth < sourceDepth)
35 score -= 100 + (sourceDepth -
desc->comp[0].depth);
36 if (
desc->log2_chroma_h == 1)
38 if (
desc->log2_chroma_w == 1)
40 if (
desc->flags & AV_PIX_FMT_FLAG_BE)
42 if (
desc->flags & AV_PIX_FMT_FLAG_PAL)
45 if (
desc->flags & AV_PIX_FMT_FLAG_RGB)
57 const AVPixFmtDescriptor *sourceSwFormatDesc,
64 if (
fmt == sourceFormat)
77 if (
fmt == sourceFormat)
85 AVPixelFormat sourceSWFormat)
87 const auto sourceSwFormatDesc = av_pix_fmt_desc_get(sourceSWFormat);
88 return [=](AVPixelFormat
fmt) {
99 const auto sourceFormatDesc = av_pix_fmt_desc_get(sourceSWFormat);
102 if (!constraints || !constraints->valid_sw_formats)
103 return sourceSWFormat;
106 return calculateTargetSwFormatScore(sourceFormatDesc, fmt);
115 if (!
codec->pix_fmts) {
116 qWarning() <<
"Codec pix formats are undefined, it's likely to behave incorrectly";
119 return accel || !
isHwPixelFormat(sourceFormat) ? sourceFormat : sourceSWFormat;
126std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
findHwEncoder(AVCodecID codecID,
127 const QSize &sourceSize)
129 auto matchesSizeConstraints = [&sourceSize](
const HWAccel &accel) {
130 const auto constraints = accel.constraints();
134 return sourceSize.
width() >= constraints->min_width
135 && sourceSize.
height() >= constraints->min_height
136 && sourceSize.
width() <= constraints->max_width
137 && sourceSize.
height() <= constraints->max_height;
148 AVPixelFormat sourceSWFormat)
153 if (!
codec->pix_fmts)
AVHWFramesConstraintsUPtr constraints() const
static std::pair< const AVCodec *, std::unique_ptr< HWAccel > > findEncoderWithHwAccel(AVCodecID id, const std::function< bool(const HWAccel &)> &hwAccelPredicate=nullptr)
AVPixelFormat hwFormat() const
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr AVScore BestAVScore
std::pair< const AVCodec *, std::unique_ptr< HWAccel > > findHwEncoder(AVCodecID codecID, const QSize &sourceSize)
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)
bool isHwPixelFormat(AVPixelFormat format)
AVPixelFormat findTargetSWFormat(AVPixelFormat sourceSWFormat, const HWAccel &accel)
constexpr AVScore DefaultAVScore
constexpr AVScore NotSuitableAVScore
static AVScore calculateTargetFormatScore(const HWAccel *accel, AVPixelFormat sourceFormat, const AVPixFmtDescriptor *sourceSwFormatDesc, AVPixelFormat fmt)
static AVScore calculateTargetSwFormatScore(const AVPixFmtDescriptor *sourceSwFormatDesc, AVPixelFormat fmt)
const AVCodec * findSwEncoder(AVCodecID codecID, AVPixelFormat sourceFormat, AVPixelFormat sourceSWFormat)
constexpr AVScore MinAVScore
static auto targetFormatScoreCalculator(const HWAccel *accel, AVPixelFormat sourceFormat, AVPixelFormat sourceSWFormat)
Combined button and popup list for selecting options.
GLint GLsizei GLsizei GLenum format
QVideoFrameFormat::PixelFormat fmt