rigaya / QSVEnc

QSVによる高速エンコードの性能実験
http://rigaya34589.blog135.fc2.com/blog-category-10.html
Other
313 stars 28 forks source link

ICQFactor changed AV1 with 4032 driver #108

Closed bavdevc closed 1 year ago

bavdevc commented 1 year ago

Hello @rigaya

I noticed some big changes in output size when encoding AV1 with ICQ mode - same input file, same qsvenc command line - but different driver/qsvenc versions.

for example: ICQ15

to get in the range of the old file size ICQ factor now is in the range 23-24.

I checked the current VPL specs: enumerator MFX_RATECONTROL_ICQ (https://spec.oneapi.io/versions/latest/elements/oneVPL/source/API_ref/VPL_enums.html?highlight=icq#_CPPv419MFX_RATECONTROL_ICQ)

Use the Intelligent Constant Quality algorithm. This algorithm improves subjective video quality of encoded stream. Depending on content, it may or may not decrease objective video quality. Only one control parameter is used - quality factor, specified by [mfxInfoMFX::ICQQuality].

and

[mfxU16] ICQQuality (https://spec.oneapi.io/versions/latest/elements/oneVPL/source/API_ref/VPL_structs_cross_component.html?highlight=icq#_CPPv4N10mfxInfoMFX10ICQQualityE)

Used by the Intelligent Constant Quality (ICQ) bitrate control algorithm. Values are in the 1 to 51 range, where 1 corresponds the best quality.

and found this commit https://github.com/oneapi-src/oneVPL-intel-gpu/commit/044994c38525e3016b0c9019f122dfde76fb01e6 they created some kind of mapping table to map those 1-51 values to the ENCODE_AV1_MAX_ICQ_QUALITYFACTOR 255 now: ` static const uint8_t ICQFactorLookup[52] = { 0, 1, 1, 1, 1, 2, 3, 4, 6, 7, 9, 11, 13, 16, 18, 23, 26, 30, 34, 39, 46, 52, 59, 68, 77, 87, 98, 104,112,120,127,134, 142,149,157,164,171,178,186,193,200,207,213,219,225,230,235,240, 245,249,252,255 };

`

87

edit: HEVC encoding seems untouched from my tests - only AV1 changed - I guess it was the latest 4032 driver for windows - can anybody confirm?

rigaya commented 1 year ago

I can confirm that with 4032 driver, ICQ limit for AV1 has changed to be 1 - 51.

For example --icq 60 are being changed to 51, resulting with very low bitrate.

Y:\Encoders>x64\QSVEncC64.exe -i sakura_op.mpg -o F:\temp\test.mp4 -c av1 --icq 60
--------------------------------------------------------------------------------
F:\temp\test.mp4
--------------------------------------------------------------------------------
PG is not supported on this platform, switched to FF mode.
vidprm.mfx.ICQQuality value changed 60 -> 51 by driver <<<================== 60 changed to 51 by driver !
cop.AUDelimiter value changed off -> auto by driver
cop.PicTimingSEI value changed off -> auto by driver
cop.SingleSeiNalUnit value changed off -> auto by driver
cop3.DirectBiasAdjustment value changed off -> auto by driver
cop3.GlobalMotionBiasAdjustment value changed off -> auto by driver
QSVEncC (x64) 7.27 (r2956) by rigaya, Jan 22 2023 18:05:49 (VC 1934/Win)
OS             Windows 11 x64 (22621) [UTF-8]
CPU Info       12th Gen Intel Core i9-12900K [5.00GHz] (8P+8E,16C/24T) <DG2>
GPU Info       Intel Arc A380 Graphics (128EU) 300-2450MHz (31.0.101.4032)
Media SDK      QuickSyncVideo (hardware encoder) FF, 2nd GPU, API v2.08
Async Depth    3 frames
Hyper Mode     off
Buffer Memory  d3d11, 17 work buffer
Input Info     avsw: mpeg1video(yv12)->nv12 [AVX2], 1280x720, 30/1 fps
AVSync         cfr
Output         AV1(yuv420) main @ Level 3.1
               1280x720p 1:1 30.000fps (30/1fps)
               avwriter: av1 => mp4
Target usage   4 - balanced
Encode Mode    ICQ (Intelligent Const. Quality)
ICQ Quality    51
QP Limit       min: none, max: none
Ref frames     4 frames
GopRefDist     8, B-pyramid: on
Max GOP Length 300 frames

encoded 3501 frames, 263.77 fps, 94.45 kbps, 1.31 MB
encode time 0:00:13, CPU: 0.4%, GPU: 42.4%, VD: 44.8%
frame type IDR   12
frame type I     12,  total size  0.04 MB
frame type P   3489,  total size  1.27 MB

As H.264 and HEVC has range of icq 1-51, it is quite understandable to have AV1 changed to also have this range.

bavdevc commented 1 year ago

ok, so the change from https://github.com/rigaya/QSVEnc/commit/2660d2aaa6f2c2f2506e4a37c4aff42c4dac8bbb is still ok, because the new driver automatically reduces the max value.

we lose some fine adjustment with that change from Intel, but it's a feature so we have to adopt to that change:

new ICQ15: 26,9 GB new ICQ23: 13,5 GB old ICQ15: 10,9 GB new ICQ24: 10,1 GB

btw. I had to double check the new scenario options because I first got an command line error with "archive": MFX_SCENARIO_UNKNOWN = 0, MFX_SCENARIO_DISPLAY_REMOTING = 1, MFX_SCENARIO_VIDEO_CONFERENCE = 2, MFX_SCENARIO_ARCHIVE = 3, MFX_SCENARIO_LIVE_STREAMING = 4, MFX_SCENARIO_CAMERA_CAPTURE = 5, MFX_SCENARIO_VIDEO_SURVEILLANCE = 6, MFX_SCENARIO_GAME_STREAMING = 7, MFX_SCENARIO_REMOTE_GAMING = 8

you named them "archieve" and "video_survillance" - I got it ;-)

bavdevc commented 1 year ago

if anyone needs to change their scripts because of ICQFactorLookup change, following table as cheat sheet:

old new 0 0 1 1 1 2 1 3 1 4 2 5 3 6 4 7 6 8 7 9 9 10 11 11 13 12 16 13 18 14 23 15 26 16 30 17 34 18 39 19 46 20 52 21 59 22 68 23 77 24 87 25 98 26 104 27 112 28 120 29 127 30 134 31 142 32 149 33 157 34 164 35 171 36 178 37 186 38 193 39 200 40 207 41 213 42 219 43 225 44 230 45 235 46 240 47 245 48 249 49 252 50 255 51

rigaya commented 1 year ago

you named them "archieve" and "video_survillance" - I got it ;-)

It's simply my mis-spelling, I'll have it fixed in the next release.

bavdevc commented 1 year ago

Thank you - as always