NVENC AV1 support#1191
Conversation
chenosaurus
commented
Jun 25, 2026
- enable Nvidia GPU NVENC AV1 encoding
ChangesetThe following package versions will be affected by this PR:
|
| {"packetization-mode", "1"}, | ||
| }; | ||
|
|
||
| supported_formats_.push_back(SdpVideoFormat("H264", highParameters)); |
There was a problem hiding this comment.
why these code is commented out ?
There was a problem hiding this comment.
I removed it, we only support h264 baseline
| NvidiaVideoEncoderFactory::~NvidiaVideoEncoderFactory() {} | ||
|
|
||
| bool NvidiaVideoEncoderFactory::IsSupported() { | ||
| const NvencProbeResult probe = ProbeNvencSupport(); |
There was a problem hiding this comment.
how about using function local to avoid calling ProbeNvencSupport() more than once ?
And log it regardless if it is available or not.
Function-local static (recommended)
bool NvidiaVideoEncoderFactory::IsSupported() {
static const NvencProbeResult probe = [] {
NvencProbeResult result = ProbeNvencSupport();
RTC_LOG(LS_INFO)
<< "NVIDIA NVENC hardware encoder "
<< (result.encoder_supported ? "is available." : "is not available.");
return result;
}();
return probe.encoder_supported;
}
|
|
||
| bool supported = false; | ||
| NV_ENCODE_API_FUNCTION_LIST fnList = {NV_ENCODE_API_FUNCTION_LIST_VER}; | ||
| CUcontext cuCtx = nullptr; |
There was a problem hiding this comment.
preferably, in C++, the variables should be declared just right before they are used.
There was a problem hiding this comment.
they are outside of the do {} block so they can be cleaned up after
| uint32_t written_format_count = 0; | ||
| nvStatus = fnList.nvEncGetInputFormats( | ||
| hEncoder, encodeGuid, formats.data(), format_count, &written_format_count); | ||
| if (nvStatus != NV_ENC_SUCCESS) { |
There was a problem hiding this comment.
nit, probably you want to add || written_format_count == 0 in this check ?
| uint32_t written_guid_count = 0; | ||
| nvStatus = fnList.nvEncGetEncodeGUIDs(hEncoder, guids.data(), guid_count, | ||
| &written_guid_count); | ||
| if (nvStatus != NV_ENC_SUCCESS) { |
There was a problem hiding this comment.
what should happen if written_guid_count is 0 here ?
There was a problem hiding this comment.
also add check for || written_guid_count == 0 to short circuit and return
| EncoderInfo GetEncoderInfo() const override; | ||
|
|
||
| private: | ||
| int32_t ProcessEncodedFrame(std::vector<uint8_t>& packet, |
There was a problem hiding this comment.
nit, is packet mutable ? if not, use const std::vector<uint8_t>& packet,
| NV_ENC_TUNING_INFO_ULTRA_LOW_LATENCY); | ||
|
|
||
| nv_initialize_params_.frameRateNum = | ||
| static_cast<uint32_t>(configuration_.max_frame_rate); |
There was a problem hiding this comment.
is max_frame_rate guaranteed bigger than 1 ? otherwise it will be divided by 0
| NV_ENC_TUNING_INFO_ULTRA_LOW_LATENCY); | ||
|
|
||
| nv_initialize_params_.frameRateNum = | ||
| static_cast<uint32_t>(configuration_.max_frame_rate); |
There was a problem hiding this comment.
maybe it is safer to do
nv_initialize_params_.frameRateNum =
std::max<uint32_t>(1, static_cast<uint32_t>(std::round(configuration_.max_frame_rate)));
There was a problem hiding this comment.
it's possible, this was carried over from the other encoder implementations. I've fixed it across av1, h264, & h265.
| has_reported_init_ = true; | ||
| } | ||
|
|
||
| void NvidiaAV1EncoderImpl::ReportError() { |
There was a problem hiding this comment.
should ReportError() take the error as param and report the right errors?
| return info; | ||
| } | ||
|
|
||
| void NvidiaAV1EncoderImpl::SetRates( |
There was a problem hiding this comment.
It looks like SetRate() only set the local codec_ and configuration_ cache values.
Should it trigger encoder_->Reconfigure(... if encoder_is already running ? or that is not an supported use case
There was a problem hiding this comment.
I think this is an existing problem in all of the nvenc encoder implementations, I will address in a different PR to fully wire up SetRate().