Skip to content

Commit

Permalink
fixup! Initial implementation of yuv444 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ns6089 committed Aug 2, 2024
1 parent a018906 commit 44da0d0
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 75 deletions.
171 changes: 96 additions & 75 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,12 @@ namespace video {

namespace qsv {

enum class profile_h264_e : int {
baseline = 66, ///< Baseline profile
main = 77, ///< Main profile
high = 100, ///< High profile
};

enum class profile_hevc_e : int {
enum class profile_av1_e : int {
main = 1, ///< Main profile
main_10 = 2, ///< Main 10 profile
high = 2, ///< High profile
pro = 3, ///< Professional profile
};

} // namespace qsv

util::Either<avcodec_buffer_t, int>
Expand Down Expand Up @@ -451,38 +447,32 @@ namespace video {
platf::pix_fmt_e::nv12, platf::pix_fmt_e::p010,
platf::pix_fmt_e::ayuv, platf::pix_fmt_e::yuv444p16),
{
// Common options
{},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{},
{}, // Common options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"av1_nvenc"s,
},
{
// Common options
{},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{},
{}, // Common options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"hevc_nvenc"s,
},
{
// Common options
{},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{},
{}, // Common options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"h264_nvenc"s,
},
Expand Down Expand Up @@ -519,12 +509,11 @@ namespace video {
{ "multipass"s, &config::video.nv_legacy.multipass },
{ "aq"s, &config::video.nv_legacy.aq },
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"av1_nvenc"s,
},
Expand All @@ -548,6 +537,8 @@ namespace video {
{
{ "profile"s, (int) nv::profile_hevc_e::main_10 },
},
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"hevc_nvenc"s,
Expand All @@ -569,6 +560,8 @@ namespace video {
{ "profile"s, (int) nv::profile_h264_e::high },
},
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"h264_nvenc"s,
Expand All @@ -594,13 +587,19 @@ namespace video {
{ "async_depth"s, 1 },
{ "low_delay_brc"s, 1 },
{ "low_power"s, 1 },
{ "profile"s, (int) qsv::profile_av1_e::main }, // intel doesn't follow ffmpeg profile constants for av1
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{},
{}, // SDR-specific options
{}, // HDR-specific options
{
// YUV444 SDR-specific options
{ "profile"s, (int) qsv::profile_av1_e::high },
},
{
// YUV444 HDR-specific options
{ "profile"s, (int) qsv::profile_av1_e::high },
},
{}, // Fallback options
std::nullopt, // QP rate control fallback
"av1_qsv"s,
},
Expand All @@ -615,12 +614,12 @@ namespace video {
{ "recovery_point_sei"s, 0 },
{ "pic_timing_sei"s, 0 },
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{
// Fallback options
{ "low_power"s, []() { return config::video.qsv.qsv_slow_hevc ? 0 : 1; } },
},
std::nullopt, // QP rate control fallback
Expand All @@ -640,12 +639,12 @@ namespace video {
{ "pic_timing_sei"s, 0 },
{ "max_dec_frame_buffering"s, 1 },
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{
// Fallback options
{ "low_power"s, 0 }, // Some old/low-end Intel GPUs don't support low power encoding
},
std::nullopt, // QP rate control fallback
Expand Down Expand Up @@ -675,6 +674,8 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"av1_amf"s,
Expand All @@ -697,6 +698,8 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"hevc_amf"s,
Expand All @@ -715,12 +718,12 @@ namespace video {
{ "vbaq"s, &config::video.amd.amd_vbaq },
{ "enforce_hrd"s, &config::video.amd.amd_enforce_hrd },
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{
// Fallback options
{ "usage"s, 2 /* AMF_VIDEO_ENCODER_USAGE_LOW_LATENCY */ }, // Workaround for https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/410
},
std::nullopt, // QP rate control fallback
Expand Down Expand Up @@ -749,6 +752,8 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options

// QP rate control fallback
Expand Down Expand Up @@ -776,6 +781,8 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"libx265"s,
Expand All @@ -788,6 +795,8 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt, // QP rate control fallback
"libx264"s,
Expand All @@ -811,12 +820,12 @@ namespace video {
{ "async_depth"s, 1 },
{ "idr_interval"s, std::numeric_limits<int>::max() },
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{
// Fallback options
{ "low_power"s, 0 }, // Not all VAAPI drivers expose LP entrypoints
},
std::make_optional<encoder_t::option_t>("qp"s, &config::video.qp),
Expand All @@ -830,12 +839,12 @@ namespace video {
{ "sei"s, 0 },
{ "idr_interval"s, std::numeric_limits<int>::max() },
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{
// Fallback options
{ "low_power"s, 0 }, // Not all VAAPI drivers expose LP entrypoints
},
std::make_optional<encoder_t::option_t>("qp"s, &config::video.qp),
Expand All @@ -849,12 +858,12 @@ namespace video {
{ "sei"s, 0 },
{ "idr_interval"s, std::numeric_limits<int>::max() },
},
// SDR-specific options
{},
// HDR-specific options
{},
// Fallback options
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{
// Fallback options
{ "low_power"s, 0 }, // Not all VAAPI drivers expose LP entrypoints
},
std::make_optional<encoder_t::option_t>("qp"s, &config::video.qp),
Expand Down Expand Up @@ -884,6 +893,8 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt,
"av1_videotoolbox"s,
Expand All @@ -898,6 +909,8 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{}, // Fallback options
std::nullopt,
"hevc_videotoolbox"s,
Expand All @@ -912,9 +925,12 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // YUV444 SDR-specific options
{}, // YUV444 HDR-specific options
{
// Fallback options
{ "flags"s, "-low_delay" },
}, // Fallback options
},
std::nullopt,
"h264_videotoolbox"s,
},
Expand Down Expand Up @@ -1582,6 +1598,11 @@ namespace video {
for (auto &option : (config.dynamicRange ? video_format.hdr_options : video_format.sdr_options)) {
handle_option(option);
}
if (config.chromaSamplingType == 1) {
for (auto &option : (config.dynamicRange ? video_format.hdr444_options : video_format.sdr444_options)) {
handle_option(option);
}
}
if (retries > 0) {
for (auto &option : video_format.fallback_options) {
handle_option(option);
Expand Down
2 changes: 2 additions & 0 deletions src/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ namespace video {
std::vector<option_t> common_options;
std::vector<option_t> sdr_options;
std::vector<option_t> hdr_options;
std::vector<option_t> sdr444_options;
std::vector<option_t> hdr444_options;
std::vector<option_t> fallback_options;

// QP option to set in the case that CBR/VBR is not supported
Expand Down

0 comments on commit 44da0d0

Please sign in to comment.