-
Notifications
You must be signed in to change notification settings - Fork 3k
Encoder FFmpeg NVENC
With the new NVIDIA NVENC integration through FFmpeg you can achieve greater recording and stream quality, at no extra expense. Since it simply uses the FFmpeg integration and exposes it to OBS Studio, including all the necessary zero-copy logic, you can switch your stream over, set some parameters, and get started with a higher quality stream right now!
Version Information
Status | Version |
---|---|
🔴Added | 0.8 |
🟠Unstable | 0.9 |
🟢Stable | 0.12.0a279 |
N/A | |
❌Removed | N/A |
This encoder shares some settings between all other FFmpeg based encoders. Please take a look at this document to learn more about them.
Changes the default values for all encoder settings except for a few FFmpeg settings like Bitrate, which can give a good baseline for your own configuration. The default value for fields varies between -1
, 0
or an actual Default
entry due to limitation with OBS's properties UI.
Defines the tune which the encoder should have, if supported by the hardware.
Available from OBS Studio 27.2.x onwards or with FFmpeg 4.4 and newer.
Settings exclusive to H.264/AVC encoding.
The profile determines which features in the codec are supposed to be enabled, with each higher option requiring additional encoder work. While the Baseline
profile has the widest support compared to Main
or High
, most devices released within the last 5-10 years should have no issues with High
.
Generally it is recommended to either pick Main
if you're targeting devices around the iPhone 3 timespan, and High
if you're targeting devices within the last 8 years. If the platform offers transcoding, you can freely choose the High
profile, with some exceptions (such as Mixer and WebRTC based platforms).
Level determines the maximum macroblocks per second, which limits the resolution and framerate, while also affecting some other things like the maximum number of B-Frames. This setting is best left at Automatic
, as the encoder knows what the ideal setting is for the given resolution, framerate, profile, tier and bitrate.
Settings exclusive to H.265/HEVC encoding.
The profile determines which features of the codec are available and enabled, while also affecting other restrictions. The Main
profile is capable of 8-bit, Main 10-bit
is capable of 10-bit, and Range Extended
is capable of more than 10-bit. Any of these profiles are capable of 4:2:0, 4:2:2 and 4:4:4, however the support depends on the installed hardware.
Bitrate limitations are controlled with the Tier and Level setting. The Main
tier is usually meant for network streaming, while the High
tier is more aimed towards intermediate storage.
Just like in H264/AVC, the Level determines the maximum macroblocks and the maximum bitrate as well. This affects the maximum possible resolution and quality at any given level. Unlike H264/AVC however, the support for Levels, Tiers and Profiles depends on the power of the target device instead of the age. This setting is best left at Automatic
, as the encoder knows what the ideal setting is for the given resolution, framerate, profile, tier and bitrate.
Settings that control the final quality and size.
NVIDIAs NVENC offers several different options for bitrate control, such as CBR
, VBR
, CQP
and CQ
. Each mode has different targets, which have to be taken into account when selecting the mode to use:
- Constant Quantization Parameter (CQP) is used for indistinguishable or lossless recording. It produces constant compression output, based on the values set in the Quantization Parameters, with lower values being large while also being higher quality.
- Constant Bitrate (CBR) is used for streaming on older protocols where a relatively constant and controllable packet size matters a lot. CBR uses the Buffer Size and Bitrate Limits to achieve its goal. There is also a High Quality variant of this which enables additional options by default.
-
Variable Bitrate (VBR) is used for local archiving as well as for modern streaming protocols. It can save space when there isn't much to encode, which pushing out high quality content when it matters. VBR uses the Buffer Size, Bitrate Limits and Quantization Parameters to achieve its goal. This also comes with a High Quality variant that enables additional options by default.
- Constant Quality (CQ) is a subset of VBR which attempts to achieve a certain quality level. It works similar to x264s CRF, but is not a replacement for CRF and should not be treated as CRF. It requires that the Buffer Size and Target Bitrate are set to 0, while Target Quality is set to any value equal to or above 1.0.
Enables/Disables a second pass over the frames, which improves bitrate distribution and may increase or decrease quality slightly. This is an expensive feature and should be turned off first if performance is an issue.
Available up to OBS Studio 27.1.x or with FFmpeg 4.3 and earlier.
May require additional GPU resources and affect performance.
Control if, how many and what passes the encoder will have while encoding the video. Multiple passes are expensive and should be disabled first if performance is a problem.
Available from OBS Studio 27.2.x onwards or with FFmpeg 4.4 and newer.
May require additional GPU resources and affect performance.
The number of frames to "look ahead", achieved by increasing the encoding delay by N frames. Setting this to 0 disables look ahead, which also disables both 'Adaptive I/B-Frames' options automatically. Increasing the number past a certain point results in diminishing returns, but the exact point is undefined and depends on Hardware used as well as content encoded. Requires additional CUDA GPU resources.
Adaptively insert I-Frames instead of P- or B-Frames when the use of such a frame would increase quality. Similar to x264s scenecut option, and seems to work fine for streaming services like Twitch and YouTube.
Adaptively insert B-Frames instead of P-Frames, or P-Frames instead of B-Frames, when the use of such a frame would increase quality.
All the possible limits for the Rate Control modes.
The quality to attempt to achieve in VBR encoding, with values closer towards 1.0 being indistinguishable from the original. Values below 1 disable the quality control and let the driver handle the ideal quality level.
Ideal target bitrate to achieve, if possible.
Ideal maximum bitrate to achieve in VBR or CQ mode.
Defines the ideal upper boundary for the bitrate over twice the Keyframe Interval duration.
Lower and upper limits for the calculated quantization parameters, which affects how much something can be compressed. May break any intended bitrate limits if used wrong.
Quantization parameter values for I/P/B-Frames, which have different meaning depending on the rate control method:
- CQP: Fixed QP values for the entire encoding duration.
- VBR: Initial QP values for the start of the encoding session.
Adaptive Quantization adjusts bitrate distibrution and usually improves subjective quality while sacrificing objective quality. This can be enabled in two different ways:
Adaptively adjusts the bitrate distribution within a single frame to favor smoother surfaces. The strength controls how aggressively it will drain bitrate from textured and complex areas of the frame. The strength of this redistribution can be controlled in 15 steps using the slider, with 0 being an invalid setting. Can improve subjective quality for individual frames. Requires additional CUDA GPU resources.
Adaptively adjusts the bitrate distribution over multiple frames by favouring some frames over others based on their content and other information. Can improve subjective quality while the frame is in motion. Requires additional CUDA GPU resources.
Options that do not fit into any other category.
Sets the highest amount of B-Frames there might be at any given point it time. When "Adaptive B-Frames" and "Look Ahead" are disables, sets a fixed amount of B-Frames instead. Not all GPUs support B-Frames for H.264/AVC and H.265/HEVC, so ensure that yours does by checking with the NVIDIA customer support. Requires additional GPU resources.
Controls if and how many B-Frames can be referenced to by the encoder, which may have an impact on encoding performance and memory requirement. Requires additional GPU resources.
Attempts to remove any reordering delay on the decoding side from the encoded video, if at all possible. Requires additional GPU resources.
Enables weighted prediction which improves quality with luminance changes when no B-Frames are enabled. Enabling this reduces encoder performance, and it is automatically disabled if B-Frames are not set to 0. B-Frames give better quality in almost all cases. Requires additional CUDA GPU resources.
If enabled, sometimes P-Frames will be marked as unreferencable and will not be used by any other frame in the encoded bitstream. Sometimes frees up some references to be used by more useful frames for improved quality, but the chances of hitting such a condition are extremely low. Requires additional CUDA GPU resources.
Defines the ideal limit of Reference Frames the encoder may use, but is not a hard limit as the encoder may at will choose to use more if it needs them. Too many reference frames can significantly reduce the number of devices that can play back the encoded bitstream, as many devices in the market only implement the absolute minimum. This limit will not be reflected in tools like MediaInfo, and may even be overriden by other limits.
Specifies the ratio of I-Frame bits to P-Frame bits for single frame VBV and CBR rate control mode. Has a direct impact on encoding latency and quality, in that setting it reduces quality significantly but improves latency. Mostly useful for Low Latency
and Ultra Low Latency
tune.
Available from OBS Studio 27.2.x onwards or with FFmpeg 4.4 and newer.
May require additional GPU resources and affect performance.
There is conflicting information from NVIDIA and NVIDIA on this. Their own documentation lists only 6 different generations, but their own website says that Turing and Ampere are 7th Generation.
- CUDA-based (any GPU)
- Kepler
- Maxwell
- Maxwell 2nd Generation
- Pascal
- Volta & GTX 1650
- GTX 1650 Super and up, Turing, Ampere
- 4000 Series
You can measure impact of options this way:
- Generate a colored noise file which usually is problematic for every encoder:
ffmpeg -hide_banner -f lavfi -y -i color=#7e7e7e:size=1920x1080:rate=60:duration=60s,noise=alls=100:allf=t+u,format=yuv420p -pix_fmt yuv420p -f yuv4mpegpipe <FILE>.y4m
- Test each option for impact with the following command (adjust as necessary):
ffmpeg -hide_banner -s 1920x1080 -r 60/1 -pix_fmt yuv420p -color_range pc -colorspace bt709 -color_primaries bt709 -color_trc bt709 -i <FILE>.y4m -c:v h264_nvenc -preset p7 -tune hq -g 120 -b:v 20000k -maxrate 20000k -bufsize 40000k -rc cbr -rc-lookahead 32 -multipass 2 -no-scenecut 0 -b_adapt 1 -spatial-aq 1 -temporal-aq 1 -nonref_p 1 -aq-strength 7 -b_ref_mode middle -bf 4 -f null -
- Write down the fps=# part after encoding is done.
The numbers below are for reference and are not guarantees, as even small differences can change a lot of numbers.
1920x1080 NV12, CBR, HQ H.264 on RTX 3090 |
P1 | P2 | P3 | P4 | P5 | P6 | P7 |
---|---|---|---|---|---|---|---|
Single Pass | 458 | 460 | 315 | 317 | 237 | 235 | 235 |
Two Pass at Quarter Resolution | 384 | 386 | 384 | 371 | 318 | 313 | 315 |
Two Pass at Full Resolution | 241 | 241 | 241 | 236 | 212 | 212 | 211 |
1920x1080, CBR, HQ H.264 on RTX 3090 |
P1 | P2 | P3 | P4 | P5 | P6 | P7 |
---|---|---|---|---|---|---|---|
High 4:4:4 Predictive | 448 | 448 | 315 | 311 | 235 | 235 | 234 |
High | 489 | 488 | 315 | 311 | 235 | 235 | 234 |
Main | 487 | 485 | 391 | 388 | 297 | 298 | 293 |
Baseline | 763 | 760 | 409 | 411 | 308 | 298 | 293 |
0 | >0 | |
---|---|---|
FPS | 106 | 99 |
% | 100 | 93.40 |
This work is licensed under a Creative Commons Attribution 4.0 International License.
The wiki has been under repeated automated attacks by bots, with attempts to phish or infect unsuspecting users with malware, trojans and similar software. As a response to these attacks and GitHubs complete ineptitude at handling this situation, we have decided to write-protect the wiki for the time being. If you wish to submit changes to the wiki, please do so over Discord. Thank you for understanding!
- 🟢 3D Transform
- 🔴 Auto-Framing
- 🟠 Blur
- 🟢 Color Grading
- 🔴 Denoising
- ❌ Displacement Mapping
- 🟢 Dynamic Mask
⚠️ SDF Effects- 🔴 Shaders
- 🔴 Spout
- 🔴 Upscaling
- 🔴 Virtual Greenscreen
- 🔴 Shaders
- 🔴 Sink
⚠️ Source Mirror
- 🔴 Shaders