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

Increasing Latency #2417

Closed
marshalsim96 opened this issue Jun 23, 2021 · 12 comments · Fixed by #2464
Closed

Increasing Latency #2417

marshalsim96 opened this issue Jun 23, 2021 · 12 comments · Fixed by #2464
Assignees
Milestone

Comments

@marshalsim96
Copy link

Is there a way to increase latency? Weird question but mainly because I dont need low latency, but instead smooth gameplay with minimal lag spikes. Since I will be streaming, I can always adjust audio to sync in OBS afterwards.

Thanks.

@rom1v
Copy link
Collaborator

rom1v commented Jun 23, 2021

No, there is currently no setting to increase latency, there is no buffering at all (the goal was to get the smallest possible latency).

instead smooth gameplay with minimal lag spikes

Do you use it over USB?

On OBS, do you capture the scrcpy window (which might add more lags), or the new V4L2 feature (on Linux)?

Note that if you record (scrcpy --record file.mkv), the timestamps recorded are the one captured on the device, so there is no jitter (but not appropriate for streaming, unless you manage to play/stream the recorded mkv file few seconds after recording started).

@marshalsim96
Copy link
Author

I typically use scrcpy with usb, works extremely well over USB. Unfortunately I do not own nor use Linux, so I cant try this V4L2 feature.

But ever since buying my new phone, it does not have an audio jack. So I have been using a bluetooth audio receiver, which apparently has a big latency issue. sndcpy sadly does not work too for my game.

So the idea is to prioritize audio latency, using the type-c port for audio, and wireless for screen sharing, in theory anyways. kinda like PTZ cameras.

But no biggie if this does not work, its just something I will have to get used too. Thanks!

@rom1v
Copy link
Collaborator

rom1v commented Jun 23, 2021

Do you also notice "lag spikes" if you just run scrcpy without OBS? Or is it just when OBS is capturing the window?

Are there "lag spikes" in the recorded file? (scrcpy --record file.mkv) (it would mean that the lag is on the device itself)

Unfortunately I do not own nor use Linux

You could try a LiveUSB on your computer (Ubuntu for example) 😉

But no biggie if this does not work

The feature might make sense (it has already been requested btw), but currently there is no way to add buffering.

@marshalsim96
Copy link
Author

marshalsim96 commented Jun 23, 2021

Do you also notice "lag spikes" if you just run scrcpy without OBS? Or is it just when OBS is capturing the window?

Yup, there is noticeable lag spikes with scrcpy running without OBS. At lower bitrate and resolution too albeit lesser.

Are there "lag spikes" in the recorded file? (scrcpy --record file.mkv) (it would mean that the lag is on the device itself)

No spikes in the recorded file.

The feature might make sense (it has already been requested btw), but currently there is no way to add buffering.

Ah I see. Probably best to consider a phone with a headphone jack, much easier fix in this situation haha.

@rom1v
Copy link
Collaborator

rom1v commented Jun 23, 2021

Ah I see. Probably best to consider a phone with a headphone jack, much easier fix in this situation haha.

I don't understand, video jitter is independent of audio, so why would a phone with a headphone jack would fix your issue?

@marshalsim96
Copy link
Author

marshalsim96 commented Jun 23, 2021

I don't understand, video jitter is independent of audio, so why would a phone with a headphone jack would fix your issue?

Ah. Then I could use scrcpy via type-c, which would eliminate any lag spikes if it was wireless. And also fix the Bluetooth latency issue, since I can use the headphone jack for audio line-in into my PC. All would be in-sync without sacrificing visual quality.

Since my current phone does not have headphone jack, the type-c can only be used for scrcpy or audio. So it's dealing with either Bluetooth latency via Bluetooth receiver, or lag spikes via wireless screen sharing. Hopefully that makes sense.

@rom1v
Copy link
Collaborator

rom1v commented Jun 23, 2021

Then I could use scrcpy via type-c, which would eliminate any lag spikes

Oh, so currently over USB, it works well without this issue for you?

@marshalsim96
Copy link
Author

Yes, works really good via USB. Probably should have clarified that part in my original post. My bad haha, totally missed that part out.

@rom1v rom1v self-assigned this Jun 24, 2021
@SLAPaper
Copy link

SLAPaper commented Jun 26, 2021

Same feature request (ability to manual add latency) but with different reason:
I'm using Bluetooth Audio Receiver (a Windows 10 App) to forward the audio to PC, while using Scrcpy to stream the video, but Bluetooth audio has a significantly larger latency (maybe ~200ms or more) than Scrcpy (even over TCP/IP), so I often experience strange slightly video-audio out-of-sync.

Implementing a configurable setting to add latency would be much help, so that I can manual sync the video and audio.

@rom1v
Copy link
Collaborator

rom1v commented Jun 26, 2021

I plan to implement this feature in v1.19.

This avoids the slight "laggy" effect due to incorrect presentation timing (on video playback for example). This is important for streaming quality.

@rom1v rom1v added this to the v1.19 milestone Jun 26, 2021
rom1v added a commit that referenced this issue Jul 6, 2021
To minimize latency (at the cost of jitter), scrcpy always displays the
latest device frame it receives, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <#2417>
rom1v added a commit that referenced this issue Jul 6, 2021
To minimize latency (at the cost of jitter), scrcpy always displays a
frame as soon as it available, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <#2417>
@rom1v
Copy link
Collaborator

rom1v commented Jul 6, 2021

Implemented by #2464

rom1v added a commit that referenced this issue Jul 6, 2021
To minimize latency (at the cost of jitter), scrcpy always displays a
frame as soon as it available, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <#2417>
rom1v added a commit that referenced this issue Jul 13, 2021
To minimize latency (at the cost of jitter), scrcpy always displays a
frame as soon as it available, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <#2417>
rom1v added a commit that referenced this issue Jul 13, 2021
To minimize latency (at the cost of jitter), scrcpy always displays a
frame as soon as it available, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <#2417>
rom1v added a commit that referenced this issue Jul 13, 2021
To minimize latency (at the cost of jitter), scrcpy always displays a
frame as soon as it available, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <#2417>
rom1v added a commit that referenced this issue Jul 14, 2021
To minimize latency (at the cost of jitter), scrcpy always displays a
frame as soon as it available, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <#2417>
@rom1v
Copy link
Collaborator

rom1v commented Jul 14, 2021

Merged into dev.

@rom1v rom1v closed this as completed Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants