Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video: reduce nvenc delay/async_depth to 0 #507

Merged
merged 1 commit into from
Dec 15, 2022

Conversation

psyke83
Copy link
Collaborator

@psyke83 psyke83 commented Nov 19, 2022

Description

If delay is not set manually, it defaults to INT_MAX, which is then reduced to number of surfaces - 1, which can potentially cause encode delay.

See:
https://github.com/FFmpeg/FFmpeg/blob/eb1e359a14e04367239a784506e1ae414512a104/libavcodec/nvenc_hevc.c#L110-L111
https://github.com/FFmpeg/FFmpeg/blob/eb1e359a14e04367239a784506e1ae414512a104/libavcodec/nvenc.c#L961
https://forums.developer.nvidia.com/t/nvenc-hevc-ultra-low-latency-with-ffmpeg-libraries-what-should-be-my-expectations/143954/5

Note that I don't own NVIDIA hardware, so this change needs testing by someone else.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

@Isalight
Copy link

Hi!
Quickly tested this build.
Windows 11, 3060 Ti
Checked with 90 fps and 40 Mbps.
Works fine.
Does this build include changes from here #485? I noticed that, as in that PR (#485), the desktop works fine, without frame delays. But unlike from resend-frame PR, according to the statistics overlay, FPS drops to 1-2 if there is no movement on the screen. Whereas with frame-resend PR fps drops to ~30 if nothing happens.

@psyke83
Copy link
Collaborator Author

psyke83 commented Nov 20, 2022

@Isalight

Thanks for testing. #485 is a hack to workaround the issue of ffmpeg buffering multiple frames seen in nvenc and amfenc, but this PR appears to be the legitimate fix (albeit for nvenc only). If this PR allows the encoder to throttle down to 1fps at idle but doesn't have delayed frames or excessive lag, I would consider the issue fixed.

As for #485, I am going to try some experiments with local builds of ffmpeg to properly remove the encoder delay with the amfenc codec... or, worst case scenario, I now know that I can whatever ugly workaround is necessary, only needs to apply to amfenc in future. Thanks.

@Isalight
Copy link

Ok! If there are new changes I can test AMD too.

@pinealservo
Copy link

I just tried out this build too, and it resolved the problems I was having with screen updates when streaming my Win10 desktop. Am using a 3080 w/nvenc.

@Docmine17
Copy link

Left: PC / Right: Raspberry pi 3

sunshine git + this pull

DSCN7670.MOV

0.15 .rpm

DSCN7671.MOV

The difference is noticeable, in version 0.15 the latency is higher, making gameplay difficult.

Spec:
Fedora 37 Workstation, GTX 1050 Ti

Chronometer:
https://cronometronline.com.br/

@Docmine17
Copy link

Docmine17 commented Dec 13, 2022

With this pull request the latency was around ~16-29ms on raspberry pi 3

@psyke83
Copy link
Collaborator Author

psyke83 commented Dec 13, 2022

Thanks for doing the latency testing - very informative!

I believe that 0.15 was operating with async_depth set to 3 frames (assuming number_of_surfaces was 4, as reported by the user on the nvidia forums linked at the beginning of the PR), which for 60fps streaming could add up to ~50.1ms (~16.7ms x 3) additional latency. It now appears to be 1-2 frames latency vs the host.

If not set manually, it defaults to INT_MAX, which is then reduced to
number of surfaces - 1, which can potentially cause encode delay.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants