Bug Report OBS Studio 25.0.4 ffmpeg hevc_nvenc b_ref_mode error

cs9k

New Member
Hello. I've been using OBS Studio for my local recordings and occasional Twitch streaming for about a year now. In the course of tens of hours of learning about encoding, nvenc's encoders, and the deep rabbit hole known as ffmpeg, I've uncovered an error in OBS Studio regarding hevc using b-frames as refrerences, in ffmpeg custom output.

The problem: When recording using NVENC HEVC (I've tried the mp4 and mkv containers), neither custom ffmpeg output, nor Xaymar's StudioFX ffmpeg output, work when HEVC b_ref_mode is set to "middle". Output does work correctly when set to "disabled"

The reason: I believe the issue is related issue found here: https://trac.ffmpeg.org/ticket/7303 My post in the link goes to example video files and ffmpeg logs with the error displayed. It's related to the PTS and DTS not matching when using HEVC b-frames as references. The ffmpeg developers consider the issue fixed, as the workaround they implemented produces acceptable video files with ffmpeg cli.

Unfortunately, the OBS Studio ffmpeg multiplexer does not know how to handle the error, and does not encode properly. Attached are logs containing successful H264 recordings, and both successful and unsuccessful H265 recordings.

I'm using the latest official NVIDIA DCH driver 445.87, but this problem has occurred for over a year across many OBS Studio and Nvidia driver versions.
Testing was done on a fresh install of OBS Studio 25.0.4.
 

Attachments

  • FFMPEG-H264-bframe-ref-mp4-mkv.txt
    51.2 KB · Views: 26
  • FFMPEG-H265-bframe-ref-mkv.txt
    44.9 KB · Views: 16
  • FFMPEG-H265-bframe-ref-mp4.txt
    45 KB · Views: 11

cs9k

New Member
So, the fix ffmpeg themselves did was prevent dts from going negative when the reference b-frame went to do its thing, as seen here: https://github.com/FFmpeg/FFmpeg/commit/22844132069ebd2c0b2ac4e7b41c93c33890bfb9

I went digging through the OBS code and see where PTS and DTS are looked at, as well where it throws the "os_process_pipe_write for packet data failed" is thrown for recording output.


I am not a programmer, but I hope this may help someone who is workaround the issue until ffmpeg themselves fixes the actual issue in the link from the OP.
 
Top