AMF icon indicating copy to clipboard operation
AMF copied to clipboard

[Bug]: <B-Frames introducing motion blur>

Open hxzael opened this issue 2 years ago • 22 comments

Describe the bug The more b-frames utilized on the current H264 encoder with OBS, the more motion blur is introduced to the image in motion. To the point where visual quality subjectively drops because of the use of b-frames. This blur or ghosting effect is especially noticed in foliage and buildings in-game. This issue is present regardless of whether components such as high motion quality boost, pre-analysis, PA high motion quality boost, adaptive mini-gop, perceptual AQ, temporal AQ, or VBAQ are used or not.

To Reproduce Steps to reproduce the behavior:

  1. Set the Max B-Frames to any number >0, effect is increased the more b-frames used. This can also be achieved by manipulating the MaxConsecutiveBPictures and BPicturesPattern parameters in the AMF/FFmpeg options section of the encoder settings.
  2. Record or Stream scenes with medium to high amounts of motion.

Setup (please complete the following information):

  • OS: Windows 11
  • Driver Version: 23.12.1
  • GPU: XFX 6900 XT
  • Which component has the issue: Encoder

Debug Log (please upload or paste):

Not needed

Expected behavior B-Frames increasing the efficiency of the encoder without any motion blur added.

Screenshots 0 B-Frames 0BF 1 B-Frame 1BF 2 B-Frames 2BF 3 B-Frames 3BF

Screenshot 2023-12-29 021219 Configuration used in these screenshots, with only Max B-Frames changing

Additional context Add any other context about the problem here.

hxzael avatar Dec 29 '23 10:12 hxzael

From these JPEGs I can only see that images with B-frames have less details. Could you please share the actual videos with B-frames and without?

MikhailAMD avatar Dec 29 '23 16:12 MikhailAMD

From these JPEGs I can only see that images with B-frames have less details. Could you please share the actual videos with B-frames and without?

Absolutely. I have also provided versions with a setup using pre-analysis (EnableVBAQ=true EnablePreAnalysis=true PASceneChangeDetectionEnable=false AdaptiveMiniGOP=true PAPerceptualAQMode=1 PATemporalAQMode=0 PACAQStrength=0 PAHighMotionQualityBoostMode=1) as samples.

Note that these clips were all recorded with OBS to simulate actual streaming or recording so they won't be exactly in sync but it's still pretty easy to compare the differences. It's especially noticeable by looking at the foliage during the horse-riding sections of the clip.

https://drive.google.com/drive/folders/1yLxXsId3O00DrXflmzLXcCTEUZvBhSBw?usp=sharing

hxzael avatar Dec 29 '23 18:12 hxzael

Thanks, I created an internal ticket for bitrate rate control folks. I assume they will look into it after holidays.

MikhailAMD avatar Dec 29 '23 19:12 MikhailAMD

Thank you!

hxzael avatar Dec 30 '23 09:12 hxzael

I have opened a pull request with the fix inside the OBS repo.

Linking it here: obsproject/obs-studio #1076

rhutsAMD avatar Jan 04 '24 15:01 rhutsAMD

I appreciate you addressing this issue. One question though.

I have experienced that even while using adaptiveminigop and preanalysis this blurring issue persists, although significantly reduced compared to using a fixed b-frame pattern. Is this issue related to max consecutive b frames being hard coded to 3? Is there a way for me to simulate the fix by forcing MaxConsecutiveBPictures to a lower number? I haven't been able to reproduce the fix this way personally.

Thank you

hxzael avatar Jan 04 '24 16:01 hxzael

Thank you for following up on this. It may be the case that the heuristics in AdaptiveMiniGOP don't serve your content well, and we will work on improving this. However from the clips you sent, it is hard for us to say that the blur is worsened between the 0 B-frames and PA clips. Ideally, when AdaptiveMiniGOP is enabled, then B-frames are inserted only to improve quality and MaxConsecutiveBPictures serves as a maximum where the actual number of B-frames can be much lower regardless.

Additionally, if you would like to experiment and track down the best settings for your particular setup and content, you may try to tweak the settings with playback of a short recording in uncompressed format. This uncompressed input can be added as a source in the OBS scene and you can recreate a consistent input source for testing various settings this way.

rhutsAMD avatar Jan 04 '24 19:01 rhutsAMD

Maybe I'll get more samples of the blur in the future with a different game including ones using Adaptiveminigop as well. The method you mention is how I got to compare clips and share the samples I provided in the first place. It's just confusing at times because I'm not sure how certain components are expected to behave despite reading the documentation.

Thank you for still actively supporting and working on improving the H264 encoder!

hxzael avatar Jan 04 '24 21:01 hxzael

Just a quick update, the B-frame blur fix has been merged into OBS. It will be present in one of their latest builds and will eventually be included in a release if you wish to wait a little.

rhutsAMD avatar Jan 22 '24 16:01 rhutsAMD

That's exciting to hear. I personally still have been experiencing some blur with 1-3 b frames even with adaptiveminigop enabled on every single game I test it with. I'll proceed with testing once the future release comes out. Thank you Rhuts.

hxzael avatar Jan 22 '24 16:01 hxzael

Is this still not being fixed in OBS 30.1.0-beta3? Because I still have ghosting artifacts... This is way more noticeable in grainy static games, like Open Red Alert: https://youtu.be/miAUGIbqFbE Look how units leaving traces behind them while moving. Also take a look at the shroud disappearing. None of these options has any effect for me: AdaptiveMiniGOP, BPicturesPattern, MaxConsecutiveBPictures, BReferenceEnable. I've tried literally everything just to fix this... VBR seems like doesn't have this bug, but the whole screen is blinking there like its refreshing - from top to bottom (this is might be a different bug though). This or rather just the bottom half of the screen does blinking and its compressed more then the other half of the screen.

CortexReaver avatar Feb 26 '24 00:02 CortexReaver

Just a quick update, the B-frame blur fix has been merged into OBS. It will be present in one of their latest builds and will eventually be included in a release if you wish to wait a little.

Do us a big favor and do change your job with something easier like selling icecream ! Why B-frames intel had it for decades and amd promoted last year and even now is not fixed ? Why AMD likes to humiliate it's customers so much and when AMD will give a DAMN about hire some decent programmers that do know video encoding? Is it too much to ask? Is it?

scotuss avatar Feb 28 '24 08:02 scotuss

My setup: RX6950 OBS 31.0.2 HQVBR , CBR Setting Max B-frames to anything higher than 0 results in frame ghosting almost exactly as demonstrated in original post.

pbaykalov avatar May 12 '25 19:05 pbaykalov

from all these commands:


ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 conv.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true conv_bf.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -high_motion_quality_boost_enable true conv_bf_hmb.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 3 -bf 3 -high_motion_quality_boost_enable true conv_bf3_hmb.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 2 -bf 2 -high_motion_quality_boost_enable true conv_bf2_hmb.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 2 -bf 2 -high_motion_quality_boost_enable true -pa_activity_type yuv conv_bf2_hmb_act-yuv.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 2 -bf 2 -bf_delta_qp 10 -bf_ref_delta_qp 10 conv_bf2_hqbf.mp4

only the first one produces no smearing and ghosting in certain fast motion moments. Driver 24.12.1 FFMPEG 7.1.1

pbaykalov avatar May 12 '25 22:05 pbaykalov

from all these commands:


ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 conv.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true conv_bf.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -high_motion_quality_boost_enable true conv_bf_hmb.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 3 -bf 3 -high_motion_quality_boost_enable true conv_bf3_hmb.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 2 -bf 2 -high_motion_quality_boost_enable true conv_bf2_hmb.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 2 -bf 2 -high_motion_quality_boost_enable true -pa_activity_type yuv conv_bf2_hmb_act-yuv.mp4
ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 2 -bf 2 -bf_delta_qp 10 -bf_ref_delta_qp 10 conv_bf2_hqbf.mp4

only the first one produces no smearing and ghosting in certain fast motion moments. Driver 24.12.1 FFMPEG 7.1.1

Could you please share sample.mp4? Developer cannot repro with his files.

MikhailAMD avatar May 13 '25 18:05 MikhailAMD

@MikhailAMD just a quick example: https://drive.google.com/drive/folders/1w3N2JhWur6X__rlI03-YAVWnWqJF0EQk?usp=sharing I used MPV to study the video, it can display milliseconds and stepping is fast. In general:

  1. some objects of the rotating scene seem to rotate before the scene starts rotating
  2. some objects of the rotating scene seem to skip frames which produces ghosting in place of the skipped intermediate position
  3. it looks like the period just before and soon after fast movement causes these issues
  4. scene is not always affected evenly
  5. I've also seen zooming in/out exhibit similar ghosting
  6. not a single issue which I highlighted is present on conv.mp4 while quality is different of course
  7. even though it seems that the bitrate is too low for this scene I've seen exactly same issues ruining much better image and of course I've seen same issue with side by side comparison with Nvenc with no issues and same-ish encoding parameters.
  8. usage=transcoding means that Peak Constrained VBR is used. I've tried using CBR and with a different video and it produced HEAVILY pixelated output in same places where enabling B-frames would add ghosting. This can be a clue.

pbaykalov avatar May 14 '25 01:05 pbaykalov

@pbaykalov This input video contains intense global rotational motion, which results in very large differences between frames.

StevenXiao-AMD avatar May 16 '25 19:05 StevenXiao-AMD

Including -preanalysis true in the FFmpeg command line will, by default, enable scene detection. When a scene change is detected, the encoder will insert an I-frame, starting a new GOP.

Due to the nature of this video, many adjacent frames are identified as scene changes, leading to frequent use of I-frames. This results in an allocation of significant bits to I-frames, which in turn reduces the bit budget available for other frame types such as P-frames and B-frames, negatively impacting overall encoding efficiency.

Injecting more following pictures to encoder will improve scene detection precision, which is called lookahead feature. This can be applied by using parameter -pa_lookahead_buffer_depth in command line explicitly

Sample command line: ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -pa_lookahead_buffer_depth 10 conv_bf.mp4

In the above command line, encoder scene detection will use the following 10 frames to check if a scene change happened.

StevenXiao-AMD avatar May 16 '25 19:05 StevenXiao-AMD

@StevenXiao-AMD thanks! That almost completely eliminates the issue with FFMPEG. Could you please tell me how to reproduce same result with OBS? Should I set "Max B-frames" set to 3 + custom CMD EnablePreAnalysis=True PALookAheadBufferDepth=41 AdaptiveMiniGOP=True ?

pbaykalov avatar May 16 '25 21:05 pbaykalov

@StevenXiao-AMD as I understand it ghosting or frame skipping (since intermediate position is fully omitted) is a method of having at least every another frame in good quality. Is that correct? I do not remember ever seeing ghosted output from any other encoder. Is there an explicit option to disable ghosting as a method of compression? I have other videos which still exhibit at least some ghosting even with lookahead and disabled scene change detection.

pbaykalov avatar May 17 '25 06:05 pbaykalov

@pbaykalov For OBS, try entering the following in the AMF/FFmpeg Options box: EnablePreAnalysis=True PALookAheadBufferDepth=41 AdaptiveMiniGOP=True MaxConsecutiveBPicture=3 This configuration is basically equivalent to the parameter settings I previously provided in the FFmpeg command line. At the same time, set the Bitrate field to "6000Kbps" to keep align with FFmpeg command line.

StevenXiao-AMD avatar May 20 '25 13:05 StevenXiao-AMD

@pbaykalov please add parameter frame_skipping in FFmpeg to control skip frame.

Sample command line: ffmpeg.exe -hwaccel d3d11va -i 'sample.mp4' -c:v h264_amf -usage transcoding -b 6M -g 120 -frame_skipping false -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -pa_lookahead_buffer_depth 10 conv_bf.mp4

You can check if the ghost issue is still there.

StevenXiao-AMD avatar May 20 '25 13:05 StevenXiao-AMD