Obs-studio: B-Frame reference mode flag in ffmpeg nvenc is bugged and doesn't work.

Created on 4 Feb 2020  路  17Comments  路  Source: obsproject/obs-studio

Expected Behavior


This flag enables B-frames as reference and it should improve picture quality. It's basically b-pyramid from x264.

Current Behavior



When -b_ref_mode 2 is enabled my recording starts and after 2 seconds drop's bitrate to zero. If I try to stop recording, ui button just freezes and I have to kill obs process.

Steps to Reproduce



  1. I'm using Xaymar's plugin for FFmpeg Nvenc that includes all the flags with easy to use UI.
  2. https://obsproject.com/forum/resources/ffmpeg-encoders-for-obs-studio.826/
  3. After installing just select the encoder in OBS Output
    image
  4. You can leave everything at default and just enable this option
    image

Additional information



Enabling this flag -b_ref_mode 2 in Custom Output (FFmpeg)
image should result in the same bug.

Dependency Issue Fix available

Most helpful comment

The aforementioned fix for "b_ref_mode=middle" was integrated into Zeranoe's latest Windows nightly. The change does appear to fix the issue and ffmpeg no longer produces errors.

For you OBS Studio devs, I thought I'd be cheeky and copy the .dll files from "/ffmpeg/bin/" (from a "shared" version of the ffmpeg nightly), into the /obs-studio/bin/64bit/ folder, just to see what happens. Interestingly, I can record h264/h265 using "b_ref_mode=middle" with ffmpeg custom output and Xaymar's StudioFX gui, with no problems.

*Hopefully that means little-to-no work will need to be done by yall, once the next full ffmpeg version is released and yall integrate that into a future OBS Studio version.

Thank you all again for your help!

*edited for clarity, Fenrirthviti. I didn't mean to imply that yall should do anything until an official release comes out, if I did.

All 17 comments

Please do check with ffmpeg custom output to confirm the issue is in obs or in the plugin , even if you expect the issue to be there. For issues with Xaymar's plugins, you should post to his repo. Not here.

Xaymar answered that question. But I will check Custom Output (FFmpeg) later today.
image

If Xaymar's answer is correct, it's an ffmpeg issue.
You should then test with ffmpeg cli, with version 4 and then master to see if the bug is fixed.
It doesn't seem to be an issue with obs at any rate.

For further reference: https://trac.ffmpeg.org/ticket/7303

I think we should reopen this. It is important. Technically this issue is simple to solve as it is off by one (usually 3600) error. And is only present when you stream not when you output to file.

? what's your simple fix ? @ValZapod
If there is one, feel free to PR. But it seemed to be on FFmpeg side rather than OBS.

the fix is upstream so it'll come to obs when we update the ffmpeg dll. Let's keep this closed.

But it is very important, really. Why you think it is not?

There's not really a point to re-opening this if the issue is already fixed. All that needs to happen is to release a new OBS package with an updated FFmpeg, which we can do with the next release if we need. Personally I don't think this is urgent enough to warrant an immediate hotfix.

@dodgepong I strongly disagree with you but okay. Just remember Twitch already supported it before this patch and now it may be broken because they applied some fix, you know.

ValZapod, ffmpeg -just now- put in a fix that won't make it into an official release for another month or two. OBS Studio -then- needs to take that and integrate it into their program, which will take more time.

The use-case for b-frames as reference for recording is so hilariously microscopic, that we can live without it until OBS Studio developers can get an official ffmpeg release and get to work themselves.

Please don't clutter up this ticket any more.

The aforementioned fix for "b_ref_mode=middle" was integrated into Zeranoe's latest Windows nightly. The change does appear to fix the issue and ffmpeg no longer produces errors.

For you OBS Studio devs, I thought I'd be cheeky and copy the .dll files from "/ffmpeg/bin/" (from a "shared" version of the ffmpeg nightly), into the /obs-studio/bin/64bit/ folder, just to see what happens. Interestingly, I can record h264/h265 using "b_ref_mode=middle" with ffmpeg custom output and Xaymar's StudioFX gui, with no problems.

*Hopefully that means little-to-no work will need to be done by yall, once the next full ffmpeg version is released and yall integrate that into a future OBS Studio version.

Thank you all again for your help!

*edited for clarity, Fenrirthviti. I didn't mean to imply that yall should do anything until an official release comes out, if I did.

Not exactly. You're correct there's not much work that needs to be done to link, but you've only tested a single aspect: custom ffmpeg output. We use ffmpeg for things like media source, image source, etc. as well, so we'd need to fully test against those. Also, I am not comfortable shipping a nightly unstable build.

Once the fix makes it to a stable release, we will look in to updating, but you're more than welcome to replace the shared library files with the nightly for your own use cases!

Any updates? BTW, what is the status of this commit? https://github.com/obsproject/obs-studio/commit/f27a00d266a380312025fa09878023592d9bb612 Should we reland it??? I think we should.

What about this, BTW? https://github.com/FFmpeg/FFmpeg/commit/9ce7de903882793749abc68eeb29813a19f50de5 Can you comment @BtbN?

This leaves open an issue with VFR content, for which some more complex
logic might be needed.

With VFR content, it's virtually impossible to properly do timestamp calculation when re-ordering is required, given that you can't possibly know the largest possible gap.
x264 also leaves that unsolved, so I didn't bother implementing it, since it's a non-issue in practice.

@cs9kc We fixed bframe each for hevc (avc is not supported anyway by Nvidia cards). I tested it, works nice.
https://github.com/FFmpeg/FFmpeg/commit/466c14d10728cd315c60e602ffe3797e7dd0c3d3
https://trac.ffmpeg.org/ticket/8809

So it is now fully operational. Note, each is very hardcore for some video players, like Microsoft's.

Was this page helpful?
0 / 5 - 0 ratings