rigaya / VCEEnc

VCEによる高速エンコードの性能実験
https://rigaya34589.blog.fc2.com/blog-category-12.html
Other
228 stars 22 forks source link

P frames show strange value and no bframes encoded? #110

Open quamt opened 1 month ago

quamt commented 1 month ago

Hello @rigaya I ran an encode and noticed strange behaviour. The RX 7600 should support B frames for h264 when I checked via --check-features.

P frames show as strange value in this example (null):16269248

"G:\vceenc\vceencc.exe" --avhw  --fps 23.976 -i "F:\BDMV\STREAM\00881.m2ts" --codec h264 --preset fast --qp-min 0 --cqp 19:21:23 --sar 1:1 --vbv-bufsize 30000 --max-bitrate 35000 --gop-len 24 -o "G:\OUT\VID_00800.264"
--------------------------------------------------------------------------------
G:\OUT\VID_00800.264
--------------------------------------------------------------------------------
VCEEnc (x86) 8.23 (r1710) by rigaya, Jul 18 2024 12:57:30 (VC 1940/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 9 5950X 16-Core Processor [4.80GHz] (16C/32T)
GPU:           AMD Radeon RX 7600 [32.0.11029.1008]
AMF:           Runtime 1.4.34 / SDK 1.4.34
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  High @ Level 4.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
Quality:       fast
CQP:           I:19, (null):16269248
VBV Bufsize:   30000 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    2 frames
LTR frames:    0 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       24 frames
Others:        skipframe:on deblock

encoded 14152 frames, 387.77 fps, 3922.69 kbps, 276.02 MB
encode time 0:00:36, CPULoad: 0.2%
frame type IDR   590
frame type I     590,  total size   45.23 MB
frame type P   13562,  total size  230.79 MB

Enabling B frames shows that they should be encoded but not shown at the end of the info when encoding is done.

"G:\vceenc\vceencc.exe" --avhw  --fps 23.976 -i "F:\BDMV\STREAM\00881.m2ts" --codec h264 --preset fast --qp-min 0 --cqp 19:21:23 --bframes 2 --sar 1:1 --vbv-bufsize 30000 --max-bitrate 35000--gop-len 24 -o "G:\OUT\VID_00800.264VID_00800.264"
--------------------------------------------------------------------------------
G:\OUT\VID_00800.264
--------------------------------------------------------------------------------
storage->SetProperty(BPicturesDeltaQP)=6 failed: invalid param..
storage->SetProperty(ReferenceBPicturesDeltaQP)=4 failed: invalid param..
VCEEnc (x86) 8.23 (r1710) by rigaya, Jul 18 2024 12:57:30 (VC 1940/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 9 5950X 16-Core Processor [4.92GHz] (16C/32T)
GPU:           AMD Radeon RX 7600 [32.0.11029.1008]
AMF:           Runtime 1.4.34 / SDK 1.4.34
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  High @ Level 4.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
Quality:       fast
CQP:           I:19, (null):16269248, B:23
VBV Bufsize:   30000 kb
Bframes:       2 frames, b-pyramid: (null)
Delta QP:      Bframe: 0, RefBframe: 0
Pre Analysis:  off
Ref frames:    2 frames
LTR frames:    0 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       24 frames
Others:        skipframe:on deblock

encoded 14152 frames, 285.91 fps, 3251.00 kbps, 228.75 MB
encode time 0:00:49, CPU: 0.3%, GPU: 100.0%, VE: 100.0%
frame type IDR   590
frame type I     590,  total size   45.23 MB
frame type P   13562,  total size  183.52 MB

I use the latest driver from AMD. I also tested version 8.22 of VCEEnc and encountered the same strange P frame values shown in HEVC encodings.

DimkaTsv commented 1 month ago

At first... Why do you use --qp-min 0 and --cqp 19:21:23 at same time? These parameters should be incompatible and both --qp-min and --qp-max are ignored with --cqp bitrate control method.

You also didn't specify b-frame usage in first example, so encoder only used IDR (keyframes) and P frames as baseline. To do that use --bframes parameter (or -b) with integer value telling how many b-frames are allowed in row at max. You can also use --b-pyramid parameter.

But regarding second example and root of the issue... I wonder why it reports this line? CQP: I:19, (null):16269248, B:23

It supposed to be like this: CQP: I:19, P:21, B:23

Here is example:

C:\Users\-----\Videos\Processing>C:\Users\-----\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i C:\Users\-----\Videos\Processing\test_fragmented.mkv -o "test_fragmented_processed.mkv" --codec AVC --profile main --level auto --preset fast --cqp 19:21:23 --bframes 2 --audio-copy --chapter-copy --sub-copy
------------------------------------------------------------------------------------------
test_fragmented_processed.mkv
------------------------------------------------------------------------------------------
storage->SetProperty(BPicturesDeltaQP)=6 failed: invalid param..
storage->SetProperty(ReferenceBPicturesDeltaQP)=4 failed: invalid param..
VCEEnc (x64) 8.23 (r1710) by rigaya, Jul 18 2024 12:57:57 (VC 1940/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.45GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [32.0.11029.1008]
AMF:           Runtime 1.4.34 / SDK 1.4.34
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  Main @ Level 4
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, eac3, eac3, truehd, truehd, subtitle#1,
                subtitle#2, subtitle#3, subtitle#4, subtitle#5 => matroska
Quality:       fast
CQP:           I:19, P:21, B:23
VBV Bufsize:   5000 kb
Bframes:       2 frames, b-pyramid: off
Delta QP:      Bframe: 0, RefBframe: 0
Pre Analysis:  off
Ref frames:    2 frames
LTR frames:    0 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock

encoded 2909 frames, 420.62 fps, 2313.29 kbps, 33.46 MB
encode time 0:00:06, CPU: 0.9%, GPU: 2.8%, VE: 100.0%
frame type IDR   13
frame type I     13,  avgQP  19.00,  total size   1.87 MB
frame type P    970,  avgQP  21.00,  total size  23.95 MB
frame type B   1926,  avgQP  23.00,  total size   7.64 MB

Definitely not cleanest example, though, as it throws errors like these: (speaking of which... @rigaya is it supposed to do that? It happens both at CQP and VBR setups):

storage->SetProperty(BPicturesDeltaQP)=6 failed: invalid param..
storage->SetProperty(ReferenceBPicturesDeltaQP)=4 failed: invalid param..
quamt commented 1 month ago

At first... Why do you use --qp-min 0 and --cqp 19:21:23 at same time? These parameters should be incompatible and both --qp-min and --qp-max are ignored with --cqp bitrate control method.

Because I am running some tests, I did not remove it. As stated in the options, it will be ignored. Same as you mentioned as well. It shouldn't interfere, or?

--qp-min <int> or <int>:<int>:<int>
Set the minimum QP value with <I frame>:<P frame>:<B frame>. This option will be ignored in CQP mode.

You also didn't specify b-frame usage in first example, so encoder only used IDR (keyframes) and P frames as baseline. To do that use --bframes parameter (or -b) with integer value telling how many b-frames are allowed in row at max. You can also use --b-pyramid parameter.

Thank you for highlighting this; there is a sentence or two missing.

Does the behaviour differ from that of NVEnc and QSVEnc regarding b-frames encoding compared to VCEEnc? If I do not declare b-frames in NVEnc or QSVEnc, they automatically encode a "minimum" bframes.

DimkaTsv commented 1 month ago

It shouldn't interfere, or?

No, it shouldn't. At least in theory.

Does the behaviour differ from that of NVEnc and QSVEnc regarding b-frames encoding compared to VCEEnc? If I do not declare b-frames in NVEnc or QSVEnc, they automatically encode a "minimum" bframes.

I... Don't think that is same for VCEEnc. Probably because B-frame support is only implemented (or reimplemented) in hardware starting from RDNA2, so it was made in such way for compatability reasons.

C:\Users\-----\Videos\Processing>C:\Users\-----\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i "C:\Users\-----\Videos\Processing\test_fragmented.mkv" -o "test_fragmented_processed.mkv" --codec AVC --cqp 19:21:23 --audio-copy --chapter-copy --sub-copy
------------------------------------------------------------------------------------------
test_fragmented_processed.mkv
------------------------------------------------------------------------------------------
VCEEnc (x64) 8.23 (r1710) by rigaya, Jul 18 2024 12:57:57 (VC 1940/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.46GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [32.0.11029.1008]
AMF:           Runtime 1.4.34 / SDK 1.4.34
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  High @ Level 4
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, eac3, eac3, truehd, truehd, subtitle#1,
                subtitle#2, subtitle#3, subtitle#4, subtitle#5 => matroska
Quality:       balanced
CQP:           I:19, P:21
VBV Bufsize:   5000 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    2 frames
LTR frames:    0 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock

encoded 2909 frames, 680.95 fps, 3002.33 kbps, 43.42 MB
encode time 0:00:04, CPU: 1.2%, GPU: 4.0%, VE: 100.0%
frame type IDR   13
frame type I     13,  avgQP  19.00,  total size   1.87 MB
frame type P   2896,  avgQP  21.00,  total size  41.55 MB
rigaya commented 1 month ago

Does the behaviour differ from that of NVEnc and QSVEnc regarding b-frames encoding compared to VCEEnc? If I do not declare b-frames in NVEnc or QSVEnc, they automatically encode a "minimum" bframes.

For VCEEnc, the default for B frames is always 0, and you need to explicitly enable them. This is because older gen GPUs (around Polaris) in H.264 encoding got very poor quality (even if the bitrate is high) when we used B frames.

CQP: I:19, (null):16269248, B:23 Bframes: 2 frames, b-pyramid: (null)

I've checked the code, but I could not come up of why it's showing this line. However, this is only showing the log, and this will not be the cause of bframes not being used.

storage->SetProperty(BPicturesDeltaQP)=6 failed: invalid param.. storage->SetProperty(ReferenceBPicturesDeltaQP)=4 failed: invalid param..

No problem with this and please just ignore. I don't think this is the major cause of the issue.

I've tested on

but had no problem here using both 24.6.1 and 24.7.1 driver.

x64\VCEEncC64.exe -i sample_movie_1080p_new_short8.mp4 -o F:\temp\test.mp4 -c h264 --preset fast --qp-min 0 --cqp 19:21:23 --sar 1:1 --vbv-bufsize 30000 --max-bitrate 35000 --gop-len 24 -b 2

storage->SetProperty(BPicturesDeltaQP)=6 failed: invalid param..
storage->SetProperty(ReferenceBPicturesDeltaQP)=4 failed: invalid param..
VCEEnc (x64) 8.23 (r1710) by rigaya, Jul 18 2024 12:57:57 (VC 1940/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 9 7950X 16-Core Processor [5.52GHz] (16C/32T)
GPU:           AMD Radeon RX 7900 XT [32.0.11029.1008]
AMF:           Runtime 1.4.34 / SDK 1.4.34
Input Info:    avvce: H.264/AVC, 1920x1080, 30000/1001 fps
Output:        H.264/AVC  High @ Level 4.1
               1920x1080p 1:1 29.970fps (30000/1001fps)
               avwriter: h264 => mp4
Quality:       fast
CQP:           I:19, P:21, B:23
VBV Bufsize:   30000 kb
Bframes:       2 frames, b-pyramid: off
Delta QP:      Bframe: 0, RefBframe: 0
Pre Analysis:  off
Ref frames:    2 frames
LTR frames:    0 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       24 frames
Others:        skipframe:on deblock

encoded 4550 frames, 436.70 fps, 6565.99 kbps, 118.83 MB
encode time 0:00:10, CPU: 0.1%, GPU: 3.9%, VE: 100.0%
frame type IDR  190
frame type I    190,  avgQP  19.00,  total size  21.82 MB
frame type P   1517,  avgQP  21.00,  total size  60.25 MB
frame type B   2843,  avgQP  23.00,  total size  36.76 MB

I cannot come up of a reason why the behavior differs.

quamt commented 1 month ago

I've checked the code, but I could not come up of why it's showing this line. However, this is only showing the log, and this will not be the cause of bframes not being used.

Thank you for checking. I will retest it this weekend after clean remove the drivers, and reinstalling them.

quamt commented 1 month ago

I cannot come up of a reason why the behavior differs.

I used DDU to remove the AMD drivers, restart the standard Windows instance and install the AMD drivers.

The issue is only related to the 32-bit version of VCEEnc. The 64-bit version of VCEEnc displays everything as it should.

rigaya commented 1 month ago

I see, I also can see log issues with 32 bit version.

How about the major issue, B frames not being encoded? Was that fixed be reinstalled driver?

Although having log issues on 32bit version, I was able to get B frames encoded.

quamt commented 1 month ago

I see, I also can see log issues with 32 bit version.

How about the major issue, B frames not being encoded? Was that fixed be reinstalled driver?

Although having log issues on 32bit version, I was able to get B frames encoded.

Yes, B frames are encoded after reinstalling the drivers.