Skip to content

Instantly share code, notes, and snippets.

@lextra2
Last active October 21, 2025 08:42
Show Gist options
  • Select an option

  • Save lextra2/f40641bdb3385ec7a986eed74f45c564 to your computer and use it in GitHub Desktop.

Select an option

Save lextra2/f40641bdb3385ec7a986eed74f45c564 to your computer and use it in GitHub Desktop.
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/tree/master/amf/public/include/components
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/blob/master/amf/doc/AMF_Video_Encode_HEVC_API.md
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/blob/master/amf/doc/AMF_Video_PreAnalysis_API.md
OBS
https://github.com/obsproject/obs-studio/blob/master/plugins/obs-ffmpeg/texture-amf.cpp
---------------------------------------------------------------------------------------------------------
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/439#issuecomment-1917886326
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/417#issuecomment-2040289753
{
"description": "VirtualDub external encoder profile collection",
"externalEncoders": {
"sets": {
"ProRes": {
"videoEncoder": "ProRes",
"audioEncoder": "",
"multiplexer": "",
"description": "",
"extension": "",
"processPartial": true,
"useOutputAsTemp": false
},
"ProRes Q4": {
"videoEncoder": "ProRes Q4",
"audioEncoder": "",
"multiplexer": "",
"description": "",
"extension": "",
"processPartial": true,
"useOutputAsTemp": false
}
},
"profiles": {
"ProRes": {
"name": "ProRes",
"program": "ffmpeg.exe",
"commandArguments": "-f rawvideo -pix_fmt %(pix_fmt) -s %(width)x%(height) -r %(fpsnum)/%(fpsden) -i - -c:v prores_ks -pix_fmt yuv420p10le %(tempvideofile)",
"outputFilename": "%(outputname).mov",
"type": 0,
"pixelFormat": "yuv444p16le",
"inputFormat": 0,
"checkReturnCode": true,
"logStdout": true,
"logStderr": true,
"bypassCompression": false,
"predeleteOutputFile": false
},
"ProRes Q4": {
"name": "ProRes Q4",
"program": "ffmpeg.exe",
"commandArguments": "-f rawvideo -pix_fmt %(pix_fmt) -s %(width)x%(height) -r %(fpsnum)/%(fpsden) -i - -c:v prores_ks -q:v 4 -pix_fmt yuv420p10le %(tempvideofile)",
"outputFilename": "%(outputname).mov",
"type": 0,
"pixelFormat": "yuv444p16le",
"inputFormat": 0,
"checkReturnCode": true,
"logStdout": true,
"logStderr": true,
"bypassCompression": false,
"predeleteOutputFile": false
}
}
}
}
@lextra2
Copy link
Author

lextra2 commented Oct 10, 2024

x265

  • ctu=32 for 1920x1080
  • no-sao=1
  • limit-sao=1
  • b-pyramid=0
  • aq-mode=3
  • mcstf=1 Motion-compensated spatio-temporal filtering. Give it a try

@lextra2
Copy link
Author

lextra2 commented Oct 19, 2024

x264

too many lookahead threads significantly degrades lookahead accuracy
https://code.videolan.org/videolan/x264/-/blob/master/encoder/encoder.c?ref_type=heads#L1294

x264 has a complex lookahead module designed to estimate the coding cost of frames that have not yet been
analyzed by the main encoder module. It uses these estimations to make a variety of decisions, such as adaptive B-frame
placement, explicit weighted prediction, and bit allocation for buffer-constrained ratecontrol. For performance reasons, it
operates on a half-resolution version of the frame and calculates SATD residuals only, doing no quantization or
reconstruction.
It is important to note that, in x264, the regular B-frame quantizer offsets (--pbratio) are disabled
when MBtree is on, since they serve the same role.

One might assume similarly that macroblock-tree can replace keyframe quantizer offsets. However, testing
suggested this was not the case

Benchmark Software Decoder

ffmpeg -benchmark -i H264.mkv -an -f null -

@lextra2
Copy link
Author

lextra2 commented Aug 6, 2025

Important AMD encoder settings

PASceneChangeDetectionEnable=false PALookAheadBufferDepth=41 MaxNumRefFrames=4


  • PASceneChangeDetectionEnable=false (default=true) - adaptive I-frames, Scenecut, requires Lookahead
  • AdaptiveMiniGOP=true (default=true) - adaptive B-frames, B-adapt, requires Lookahead
  • BReferenceEnable=true (default=true) - Use B-frames as Reference frames

MaxNumRefFrames=4 =4 for High 4.2 Profile (1920x1080@60)

@lextra2
Copy link
Author

lextra2 commented Aug 17, 2025

@lextra2
Copy link
Author

lextra2 commented Aug 21, 2025

@lextra2
Copy link
Author

lextra2 commented Aug 21, 2025

Important NVenc settings

AVC
lookaheadDepth=32 useBFramesAsRef=1

HEVC
lookaheadLevel=3 lookaheadDepth=32

Note: NV_ENC_LOOKAHEAD_LEVEL_0 has the highest performance,
while NV_ENC_LOOKAHEAD_LEVEL_3 has the highest quality. It increases bitrate significantly and should not be used.


https://github.com/obsproject/obs-studio/blob/ef93ef6950df0a5435c2756c11ace92d15e00d52/plugins/obs-nvenc/nvenc-properties.c#L213

useBFramesAsRef=

=1 Any B-frame can be a reference frame

=2 Halved - Uses the following logic:

4 B-frames = 2 reference frames
3 B-frames = 1 reference frame
2 B-frames = 1 reference frame
1 B-frame = 1 reference frame <-- untested, but should be logical to clamp to 1

@lextra2
Copy link
Author

lextra2 commented Sep 9, 2025

Show all supported encoders in FFMPEG:

ffmpeg -encoders

Show all encoder options:

ffmpeg -h encoder=hevc_nvenc

Lossless: NVenc

ffmpeg -y -benchmark -i INPUT.mkv -c:v hevc_nvenc -tune lossless -pix_fmt p010le -an OUTPUT.mkv

Almost Lossless: Apple ProRes 422 High Quality

ffmpeg -y -benchmark -i INPUT.mkv -c:v prores_ks -q:v 0 -profile:v 3 -bits_per_mb 1024 -vendor apl0 -pix_fmt yuv422p10le 1024.mov

Note:-bits_per_mb can go up to 8192. Higher = less lossy.

Lossless: UT Video

ffmpeg -y -benchmark -i INPUT.mkv -c:v utvideo -color_primaries bt709 -color_trc bt709 -colorspace bt709 -color_range tv OUTPUT.mkv

AV1 Basically lossless settings:

ffmpeg -y -benchmark -i INPUT.mkv -c:v libsvtav1 -svtav1-params "enable-tf=0:mbr=10M:tile-columns=2:tile-rows=0" -g 240 -qp 14 -preset 4 -pix_fmt yuv420p10le SVT_AV1.mkv

Libaom AV1 settings:

ffmpeg -y -benchmark -i TEST.mkv -c:v libaom-av1 -pix_fmt yuv420p10le -g 240 -cpu-used 4 -auto-alt-ref 0 -aq-mode 0 -tile-columns 2 -tile-rows 0 -row-mt 1 -crf 16 -pass 1 libaom-pass1.webm
ffmpeg -y -benchmark -i TEST.mkv -c:v libaom-av1 -pix_fmt yuv420p10le -g 240 -cpu-used 4 -auto-alt-ref 0 -aq-mode 0 -tile-columns 2 -tile-rows 0 -row-mt 1 -crf 16 -pass 2 libaom-pass2.webm

@lextra2
Copy link
Author

lextra2 commented Sep 16, 2025

NVEnc by rigaya
Docs

High Quality Example:

NVEncC64.exe --codec hevc --cqp 18 --preset p7 --output-depth 10 --lookahead 32 --ref 8 --split-enc forced_2 --colormatrix bt709 --colorprim bt709 --transfer bt709 --colorrange limited -i INPUT.mkv -o OUTPUT.mkv

190 FPS with 2560x1440 input from the RTX 5070 Ti

Lossless:

NVEncC64.exe --lossless --colormatrix bt709 --colorprim bt709 --transfer bt709 --colorrange limited -i INPUT.mkv -o OUTPUT_Lossless-avc.mkv

@lextra2
Copy link
Author

lextra2 commented Oct 9, 2025

ffmpeg -y -benchmark -i TEST.mkv -c:v libx264 -x264-params "ref=8:keyint=240:bframes=3:b-adapt=2:rc-lookahead=60:aq-mode=3:me=umh:merange=24:subme=9:trellis=2:lookahead-threads=2:threads=16" -crf 14 -pix_fmt yuv420p10le AVC_14.mkv

@lextra2
Copy link
Author

lextra2 commented Oct 21, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment