leng-yue / py-scrcpy-client

An easy to use python scrcpy client
https://leng-yue.github.io/py-scrcpy-client/
MIT License
308 stars 76 forks source link

Lag #10

Closed rhobro closed 2 years ago

rhobro commented 2 years ago

I connected my phone and opened up scrcpy and an opencv window with the inputs form py-scrcpy-client.

When I had them side by side, I noticed that scrcpy was instant while py-scrcpy-client had a roughly 3 to 5 second lag. Why is this the case?

rhobro commented 2 years ago

The same lag occurs with and without the scrcpy window open.

leng-yue commented 2 years ago

This is weird. Can you check whether your CPU is overloaded?

leng-yue commented 2 years ago

By the way, are you using the scrcpt-client[ui]?

rhobro commented 2 years ago

This is weird. Can you check whether your CPU is overloaded?

Despite running both scrcpy and py-scrcpy-client at the same time, the CPU load is minimal. Now that I have changed network, the lag seems to have reduced but py-scrcpy-client is definitely lagging behind by a second or two.

No, I'm not using scrcpy-client[ui]. Is this the problem?

Screenshot 2021-11-11 at 19 41 09

ok

leng-yue commented 2 years ago

As you mentioned network, are you using wifi to connect to the device?
Can you test official scrcpy 1.18?

leng-yue commented 2 years ago

Maybe there is some problem with wifi port forwarding, can you also test the USB connection?

rhobro commented 2 years ago

I was using Wi-fi to connect to the device. Seeing the lag, I switched to usb but the lag was still there.

rhobro commented 2 years ago

I'll test 1.18 and report the results.

rhobro commented 2 years ago

I am already on 1.19 and don't need to update to 1.18

rhobro commented 2 years ago

Can py-scrcpy-client start using v1.19 of scrcpy-server?

leng-yue commented 2 years ago

I planed to update to 1.20 when it's published.

leng-yue commented 2 years ago

Since scrcpy always publishes new versions, I don't have enough time to follow every small version.

rhobro commented 2 years ago

When will that be?

leng-yue commented 2 years ago

If scrcpy doesn't publish v1.20 this month, I will upgrade to 1.19.

rhobro commented 2 years ago

Ok. Thanks. When you do upgrade, please let me know.

rhobro commented 2 years ago

Scrcpy v1.20 has been released.

leng-yue commented 2 years ago

Great! I will upgrade the scrcpy-client in about three days.

leng-yue commented 2 years ago

A new version is publishing, can you try it later?

leng-yue commented 2 years ago

I was using Wi-fi to connect to the device. Seeing the lag, I switched to USB but the lag was still there.

How much is the lag on USB? I didn't find a lag on my devices :(

rhobro commented 2 years ago

I'll try it later.

The lag on usb with the old version was about 1 to 2 seconds

leng-yue commented 2 years ago

any update?

rhobro commented 2 years ago

There is still a 1 to 2 second lag via USB

leng-yue commented 2 years ago

I will try to figure out why this happens when I have time, and the issue won't be closed until the problem is solved.

rhobro commented 2 years ago

Ok. Thank you. Here is some context for when you're looking. I'm running macOS Monterey on an Intel Mac.

leng-yue commented 2 years ago

I can't reproduce the lag.

leng-yue commented 2 years ago

image

leng-yue commented 2 years ago

can you send me a similar timer screenshot?

rhobro commented 2 years ago

For some reason when I use opencv to show the display side by side with scrcpy, the lag is roughly 100ms but when I don't, it is roughly 500ms

leng-yue commented 2 years ago

Seems like a Qt rendering problem?

leng-yue commented 2 years ago

My screenshot shows that the lag on my laptop is about 30ms

leng-yue commented 2 years ago

Can you try the newest py-scrcpy? I updated some parts in the UI rendering.

leng-yue commented 2 years ago

I found the problem, it is here https://github.com/leng-yue/py-scrcpy-client/blob/de17bb4b5f3651cb9580a5dc1cda65e0426f3430/scrcpy/core.py#L181-L194

Using this code, I can get the same latency as the official scrcpy. However, the stream is not stable and may raise errors. If you have any ideas to solve this problem, please share them with me.

rhobro commented 2 years ago

Does OpenCV use Qt to render?

rhobro commented 2 years ago

Aha, What was the issue?

I'll try it with that code