GPUOpen-LibrariesAndSDKs / AMF

The Advanced Media Framework (AMF) SDK provides developers with optimal access to AMD devices for multimedia processing
Other
585 stars 149 forks source link

[Bug]: Unable to make AMF encoder to follow specified CBR bitrate. Filler data parameter is ignored for CBR in some cases. #465

Open DimkaTsv opened 3 months ago

DimkaTsv commented 3 months ago

Describe the bug If sample video has close to no movement (aka static image), specified in encoding parameters bitrate won't be followed properly. Similar problem was described here long ago: https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/18 This problem does not happen when i try to capture CBR AMF AVC/HEVC with OBS. But issue is happening if i try:

  1. To capture AMF AV1 with OBS (AVC/HEVC ones are off the hook) Samples of OBS capture: https://drive.google.com/file/d/1U110VMaoxGLmUlWa6gl0jC0a6YwY722O/view?usp=sharing

  2. To capture AVC/HEVC/AV1 via ReLive with set bitrate (i used 50 mbps capture, but got files of 400-500 KB in size after 10 seconds of capture. And HEVC one for some reason was noticeably larger... 850 KB). [But i will assume it is because they use VBR with max bitrate as constraint instead of target bitrate. It is what sample metadata tells me at least] Samples of ReLive capture: https://drive.google.com/file/d/1BHT-gAZU1kOEHb0MXLVFi0WKM2RDA7ME/view?usp=sharing

  3. When i try to transcode video with mostly (or completely) static image. This happen with both AMF Transcode HW tool, and VCEEnc.

To Reproduce Steps to reproduce the behavior:

  1. Use TranscodeHW or VCEEnc as transcoder applications
  2. Use sampled source (it's main perk is that most of it is just same exact screen with no changes) Sample to use in reproduction: https://drive.google.com/file/d/1NpHo2ZbKN0yutdNIR3ufiua7ueSsjamp/view?usp=sharing We will just use OBS CPU x264 sample with 20 mbps bitrate.
  3. Use commands (mine are written for drag and drop .bat files) [Target bitrate for both of them should be 20 mbps if i passed correct argument for TranscodeHW]: For TranscodeHW: %~dp0\TranscodeHW.exe -input %1 -output %~n1_processed%~x1 -codec AVC -RateControlMethod CBR -TargetBitrate 20000000 -FillerDataEnable For VCEEnc: %~dp0\VCEEncC64.exe -i %1 -o "%~n1_processed%~x1" --codec avc --cbr 20000 --filler --audio-copy

What will happen: Both will not follow CBR 20000 at all, despite having forced filler data flag. TranscodeHW file will be larger, but will also corrupt beginning by flickering (look at additional context). Here are transcoded outputs from both VCEEnc and TranscodeHW: https://drive.google.com/file/d/1XXcqNqdGlvz5CwWFKtC-JrawFEnZtSmB/view?usp=sharing

Setup (please complete the following information):

Debug Log (please upload or paste): No specific debug logs there, but VCEEnc output looks like this:

C:\Users\DimkaTsv\Videos>C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i C:\Users\DimkaTsv\Videos\OBS_CPU_x264.mkv -o "OBS_CPU_x264_processed.mkv" --codec avc --cbr 20000 --filler --audio-copy
--------------------------------------------------------------------------------
OBS_CPU_x264_processed.mkv
--------------------------------------------------------------------------------
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [31.0.24019.1006]
AMF:           Runtime 1.4.33 / SDK 1.4.30
Input Info:    avvce: H.264/AVC, 1920x1080, 60/1 fps
Output:        H.264/AVC  High @ Level 4.2
               1920x1080p 1:1 60.000fps (60/1fps)
               avwriter: h264, aac => matroska
Quality:       balanced
CBR:           20000 kbps
Max bitrate:   62500 kbps
QP:            Min: 0:0, Max: 51:51
VBV Bufsize:   78125 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    2 frames
LTR frames:    0 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       600 frames
Others:        skipframe:on deblock filler

encoded 691 frames, 533.18 fps, 728.96 kbps, 1.00 MB
encode time 0:00:01, CPU: 0.2%, GPU: 5.0%, VE: 100.0%
frame type IDR   2
frame type I     2,  avgQP  20.50,  total size  0.17 MB
frame type P   689,  avgQP  17.01,  total size  0.83 MB

C:\Users\DimkaTsv\Videos>pause
Для продолжения нажмите любую клавишу . . .

That hints that skipframe option was enabled by default (which should not be by documentation, as --skip-frame flag only allows you to enable it, but not disable as there are no arguments to this parameter), and probably conflicts with filler data?

Expected behavior CBR should follow target bitrate and filler data should work properly.

Screenshots If applicable, add screenshots to help explain your problem.


Additional context When i reproduced issue with personally created samples i encountered additional issue with TranscodeHW specifically. In addition to not following CBR target and filler data flag, TranscodeHW also will corrupt output file beginning for some reason (it will NOTICEABLY flicker). Here is transcoded via TranscodeHW sample https://drive.google.com/file/d/1m7177N8Q14yZ6UDC66OM-1RiMK5m6nRz/view?usp=sharing And here is TranscodeHW console log from this specific transcode:

C:\Users\DimkaTsv\Videos>C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\AMF-1.4.33\amf\bin\vs2019x32Debug\\TranscodeHW.exe -input C:\Users\DimkaTsv\Videos\OBS_CPU_x264.mkv -output OBS_CPU_x264_TranscodeHW.mkv -codec AVC -RateControlMethod CBR -TargetBitrate 20000000 -FillerDataEnable
DX11: List of adapters:
          0: Device ID: 747E [AMD Radeon RX 7800 XT]
DX11 : Chosen Device 0: Device ID: 747E [AMD Radeon RX 7800 XT]
InitDX11() created HW DX11.1 device
InitDX11() created HW DX11 device
Start: 1 threads
2024-03-11 19:38:57.863     9CD8 [AMFAudioEncoderFFMPEGImpl] Warning: Generated packet pts 464399 is before the input frame pts 467641
2024-03-11 19:38:57.863     9CD8 [AMFAudioEncoderFFMPEGImpl] Warning: Generated packet pts 464399 is before the input frame pts 467641
2024-03-11 19:38:57.880     5114 [matroska]   Error: C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\AMF-1.4.33\amf\public\src\components\ComponentsFFMPEG\UtilsFFMPEG.cpp(293):Application provided invalid, non monotonically increasing dts to muxer in stream 0: 34>= 0
2024-03-11 19:38:57.880     5114 [matroska]   Error: C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\AMF-1.4.33\amf\public\src\components\ComponentsFFMPEG\UtilsFFMPEG.cpp(293):Application provided invalid, non monotonically increasing dts to muxer in stream 0: 34>= 0
SubmitInput() returned error: AMF_FAIL
2024-03-11 19:38:57.881     5114 [matroska]   Error: C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\AMF-1.4.33\amf\public\src\components\ComponentsFFMPEG\UtilsFFMPEG.cpp(293):Application provided invalid, non monotonically increasing dts to muxer in stream 0: 34>= 17
2024-03-11 19:38:57.881     5114 [matroska]   Error: C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\AMF-1.4.33\amf\public\src\components\ComponentsFFMPEG\UtilsFFMPEG.cpp(293):Application provided invalid, non monotonically increasing dts to muxer in stream 0: 34>= 17
SubmitInput() returned error: AMF_FAIL
2024-03-11 19:38:57.883     5114 [matroska]   Error: C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\AMF-1.4.33\amf\public\src\components\ComponentsFFMPEG\UtilsFFMPEG.cpp(293):Application provided invalid, non monotonically increasing dts to muxer in stream 0: 34>= 33
2024-03-11 19:38:57.883     5114 [matroska]   Error: C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\AMF-1.4.33\amf\public\src\components\ComponentsFFMPEG\UtilsFFMPEG.cpp(293):Application provided invalid, non monotonically increasing dts to muxer in stream 0: 34>= 33
SubmitInput() returned error: AMF_FAIL
2024-03-11 19:38:58.018     9CD8 [AMFAudioEncoderFFMPEGImpl] Warning: Generated packet pts 63148299 is before the input frame pts 63148320
2024-03-11 19:38:58.018     9CD8 [AMFAudioEncoderFFMPEGImpl] Warning: Generated packet pts 63148299 is before the input frame pts 63148320

 Frames processed: 688 Frame process time: 1.4549ms FPS: 687.3
 Average FPS: 690.3 Combined FPS: 690.3

C:\Users\DimkaTsv\Videos>pause
Для продолжения нажмите любую клавишу . . .
DimkaTsv commented 1 week ago

24.6.1, issue still exists. Unless i do something wrong on my side, of course.