Table of Contents
tails.beandog.org
- Understanding Rate Control Modes (x264, x265, vpx) - doesn't apply to me because he's using libx264, but I like his explanation of comparing quality options in ffmpeg
- CRF Guide (Constant Rate Factor in x264, x265 and libvpx) - same guy, just more comparison
- https://slhck.info/video/2017/02/24/vbr-settings.html - details on setting VBR
- Video Encoding Settings for H.264 Excellence - doesn't really apply because they use libx264, but it's a great reference for how things work
- https://trac.ffmpeg.org/wiki/Hardware/VAAPI - AMD hardware encoding
- HandBrake git - commit to ffmpeg-8.0.1 has libdvdnav and libdvdread 7.0 as well
qmin and qmax
qmax is the highest number you are willing to encode for, where the higher the number, the worse the peak quality
qmin is the lowest number, which will max out good quality level at.
So, if you want somewhere between 15 and 22 cq, you would use -qmin 15 -qmax 26
Think of min and max as that, the numbers, not “min = minimum quality” and “max = maximum quality”. It's just numbers.
For constant quality, set them at the same value: -qmin 18 -qmax 18. Not recommended, because that would make sense for streaming, where you need a predictable source.
h264_nvenc vs hevc_nvenc
hevc_nvenc is always bigger, and slower to encode.
cuda vs bare h264_nvenc
CUDA is slower by 30 seconds than just base h264_nvenc with the exact same parameters.
ffmpeg -f dvdvideo -title 1 -i /media/steve/CAD/1.157.0917.TRANS.iso -map v -map i:0x80 -vcodec h264_nvenc -acodec libfdk_aac -metadata:s language=eng -tune hq -preset p7 -rc constqp -pix_fmt yuv420p -profile high -vbr 5 -vf bwdif=deint=interlaced,fps=59.94 -rc vbr -cq 20 -qmin 20 -qmax 20 -b:v 0 -rc-lookahead 32 -y round2-software-h264-cq-20-1.157.0917.12514.TRANS.mkv
0:52.95
ffmpeg -f dvdvideo -title 1 -hwaccel cuda -hwaccel_output_format cuda -i /media/steve/CAD/1.157.0917.TRANS.iso -init_hw_device cuda -map v -map i:0x80 -vcodec h264_nvenc -acodec libfdk_aac -metadata:s language=eng -tune hq -preset p7 -rc constqp -vf bwdif_cuda=deint=interlaced,fps=fps=59.94 -profile high -vbr 5 -rc vbr -cq 20 -qmin 20 -qmax 20 -b:v 0 -rc-lookahead 32 -y round2-software-h264-cq-20-1.157.0917.12514.TRANS.mkv
1:19.14
nvidia-drivers
modprobe.d/nvidia.conf: disable fbdev
# options nvidia-drm fbdev=0
mint: upstream nvidia and cuda drivers
Make sure native nvidia-drivers is not installed first.
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb dpkg -i cuda-keyring_1.1-1_all.deb apt-get update apt-get -y install cuda-toolkit-13-0 cuda-drivers
openrc
/etc/rc.conf
Hit I to do interactive boot.
rc_interactive="YES"
DuckDuckGo AI
Color
SMPTE170M is a color space standard primarily used for standard definition video, while YUV420P is a pixel format that describes how color information is stored in a video file, specifically using a 4:2:0 chroma subsampling method. Essentially, SMPTE170M defines the color characteristics, whereas YUV420P defines the arrangement of those colors in the video data.
Why use qmin and qmax with cq?
Understanding qmin, qmax, and Constant Quality (CQ) in FFmpeg What are qmin and qmax?
- qmin: This parameter sets the minimum quantizer scale for video encoding. It restricts the lowest quality level that the encoder can use.
- qmax: This parameter sets the maximum quantizer scale. It limits the highest quality level that can be used during encoding.
Purpose of Using qmin and qmax with CQ
- Constant Quality (CQ): This mode aims to maintain a consistent quality level throughout the video. The CQ value ranges from 0 (highest quality) to 51 (lowest quality).
- Combining CQ with qmin and qmax: Using qmin and qmax alongside CQ allows for finer control over the encoding process. It ensures that the encoder does not exceed certain quality thresholds, which can be useful in managing file sizes and maintaining a balance between quality and bitrate.
Practical Implications
- Quality Control: By setting qmin and qmax to the same value, you effectively lock the encoder to a specific quality level, similar to using a constant bitrate (CBR) approach. This can be beneficial for specific use cases where consistent quality is critical.
- Flexibility: Allowing qmin and qmax to vary while using CQ enables the encoder to adapt to different content types, optimizing quality based on the complexity of the video being encoded.
Conclusion
Using qmin and qmax with CQ in FFmpeg provides a way to control the quality and bitrate of video encoding more precisely. This combination can help achieve desired outcomes in various encoding scenarios, balancing quality and file size effectively.
what is ffmpeg constqp
ConstQP in FFmpeg refers to “Constant Quantization Parameter,” a rate control mode used during video encoding that maintains a fixed quantization level across frames. This can lead to consistent quality but may result in larger file sizes compared to other methods like Variable Bit Rate (VBR) or Constant Rate Factor (CRF) which adapt the quantization based on the content.
Overview of FFmpeg Constant QP (constqp)
Constant QP (constqp) is a rate control mode used in FFmpeg when encoding video with NVIDIA's NVENC. It stands for Constant Quantization Parameter, which means that the encoder uses a fixed quantization level for all frames. This results in a consistent quality level throughout the video.
Key Features of constqp
- Fixed Quality: The quantization parameter (QP) remains constant, which can lead to predictable quality but may waste disk space.
- Bitrate Variability: While the quality is consistent, the bitrate can vary significantly depending on the complexity of the video content.
- Usage: It is often used in scenarios where maintaining a specific quality level is more important than file size.
Recommendations
While constqp can provide good quality, it is often recommended to use Variable Bitrate (VBR) with a Constant Quality (CQ) setting instead. This approach can achieve similar quality while being more efficient with disk space. For true constant quality, set the rate control to VBR and specify the target quality level using the -cq option.
Me: What's the difference between “specific quality level” and “true constant quality”? Remember that “CQ” literally means “constant quality.”
[FUTURE PROJECT] Re-master some cartoons
Opinions (Good Ones)
Generally, see the comments
- https://www.reddit.com/r/ffmpeg/comments/1124x2z/ffmpeg_with_hevc_nvenc_am_i_doing_anything_dumb/ - extreme detail on what to use with libx264 and nvidia hwenc to get high quality
- https://superuser.com/questions/1236275/how-can-i-use-crf-encoding-with-nvenc-in-ffmpeg - translate libx264 crf to what nvenc uses (kind of)
- https://www.reddit.com/r/ffmpeg/comments/k59nr6/a_follow_up_to_my_nvenc_lossless_post_what_is_the/ - really good comment on encoding quality
- https://github.com/HandBrake/HandBrake/issues/2231#issuecomment-1003767391 - this guy made a spreadsheet looking at qmin, qmax values
- https://www.reddit.com/r/ffmpeg/comments/xtl43y/hq_ffmpeg_encoding_with_gpu_nvenc_part_iii/ - has some flaws, but interesting
Other
List listening ports
netstat -ltup
Disable IPv6 in NetworkManager
nmcli connection show nmcli connection modify 'Wired connection 1' ipv6.method disabled nmcli connection up 'Wired connection 1'


