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

Is it possible not to encode on the device #1584

Closed
flyingduck234 opened this issue Jul 11, 2020 · 16 comments
Closed

Is it possible not to encode on the device #1584

flyingduck234 opened this issue Jul 11, 2020 · 16 comments

Comments

@flyingduck234
Copy link

right now we are using media encoder to encode the frames and then we are using adb to transfer the data.

Is it possible to send the raw data and use the computer to do encoding or decoding

@rom1v
Copy link
Collaborator

rom1v commented Jul 11, 2020

No, scrcpy does not do that.

A raw video is HUGE. For example, 1920×1080 at 60fps in RGB would require 1920×1080×60×24 bits per second, which is about 2.8Gbps. Why that question?

@flyingduck234
Copy link
Author

flyingduck234 commented Jul 12, 2020

Thank you for the answer.

I understand that scrcpy does not do that.

There is a loss of quality in the image rendered by scrcpy and also there is a performance impact when scrcpy is running.

Usb 3.1 supports upto 10gbps, and if we can use the PC hardware to do all the work, while scrcpy-server just transmits the raw data.

just wondering if its even possible

P.s i have tested the latest scrcpy and i was able to acheive 0ms latency on 1080p.

@rom1v
Copy link
Collaborator

rom1v commented Jul 12, 2020

There is a loss of quality in the image rendered by scrcpy

Just use scrcpy -b20m (for example). Default is 8m.

@flyingduck234
Copy link
Author

flyingduck234 commented Jul 12, 2020

i tried 200m bitrate, but still there is a loss of image quality. i think its related to encoding/decoding.

Not sure if anyone noticed but scrcpy has 0 ms latency on 1080p
IMG20200712170411

@automatata
Copy link

Usb 3.1 supports upto 10gbps, and if we can use the PC hardware to do all the work, while scrcpy-server just transmits the raw data.

Just because the supported data rate is up to 10Gbps with USB 3.1, it doesn't mean a phone can actually reach the level.

I have no professional knowledge on the topic, but my older 2016 phone runs an adb pull only at 15MBps over USB 2.0 which has practical data rate around 30~48MBps on computers when say, using USB external HDDs. Interestingly phones back then may achieve better practical data rate over Wi-Fi 802.11n (with HTTP or maybe FTP but not ADB over Wi-Fi).

My 2018 flagship, still on USB 2.0, is faster at 35MBps in which case the USB 2.0 may be a bottleneck. Although sometimes it drops to 25MBps.

Of course mine aren't the newest flagships any more, but I highly doubt we had achieved the required 25~50x fold improvement on the practical data rate since 2016. The USB controller hardware may be a factor, the entire software stack underlying ADB may be a factor. I'd be really impressed if the newest phones are actually that fast, given the brands have few reasons to pursue USB data rate nowadays.

BTW your latency test above is unbelievably good. I have at least 40ms latency over both wired USB and Wi-Fi. Have to say I'm puzzled by your test because scrcpy itself is transmitting at 60fps max. Even if your latency L is below 1000/60=17ms, the camera should still occasionally see a 17ms latency with a probability of L/17. With respect, a latency well below 17ms seems too good. scrcpy only advertises >35ms latency.

@flyingduck234
Copy link
Author

Well I tested a 2018 flagship with usb3.1gen 1 which is about 5gbps. I can say that the bandwidth exists as advertised.

My latency is good and stable. The credit goes to scrcpy and rom1v. The advertised latency 35ms was probably tested in worst case situations.

Scrcpy doesn't transmit at 60fps. It depends on your screen refresh rate and how often it produces a new frame. It could be 144fps, 90 fps or below 60fps.

@rom1v
Copy link
Collaborator

rom1v commented Aug 12, 2020

scrcpy only advertises >35ms latency.

I did the tests in #646 with my main test device, a Nexus 5, which is quite old. It might be better on new devices. But I just tested on a OnePlus 7 Pro, I still get around 35ms at 1080p (which is about the half of what I get on my Nexus 5).

@flyingduck234
Copy link
Author

scrcpy only advertises >35ms latency.

I did the tests in #646 with my main test device, a Nexus 5, which is quite old. It might be better on new devices. But I just tested on a OnePlus 7 Pro, I still get around 35ms at 1080p (which is about the half of what I get on my Nexus 5).

How are you measuring the latency?

I redid the tests with different configurations

Test 1: 80Mbit
IMG_20200812_210634

There is no latency

Test 2: 200Mbit
IMG_20200812_204621

This is basically I'm asking to see latency at 200mbit.its half frame latency

Test 3: I changed the resolution to OnePlus 7 pro and with 200Mbit
IMG_20200812_205826

@rom1v
Copy link
Collaborator

rom1v commented Aug 12, 2020

Test 1: 80Mbit
Test 2: 200Mbit

This probably does not change anything. The bitrate is just a value passed to the codec, I think it changes nothing above ~20Mbps (it depends on the encoder/device). To get the real bitrate, record the video and device the length by its size.

There is no latency

Yes, it's below 1 frame 🎉 Your encoder is probably very fast :)

Test 3: I changed the resolution to OnePlus 7 pro

What do you mean "changed the resolution to"? If it's not a real OnePlus 7 Pro, the encoder may be different. Anyway, in your last photo, there are about 2 frames latency (895-896 to 897-898). What is the framerate of your video sample?

@flyingduck234
Copy link
Author

Yes, it's below 1 frame 🎉 Your encoder is probably very fast :)

Correct me if I'm wrong, from my understanding it's the decoder that consumes more time than encoder.

What do you mean "changed the resolution to"? If it's not a real OnePlus 7 Pro, the encoder may be different. Anyway, in your last photo, there are about 2 frames latency (895896 to 897898). What is the framerate of your video sample?

I used the video from #646 , it says 1 frame is 35ms latency. I used the adb shell command to change the phone's resolution so everything will be rendered at that resolution regardless of actual resolution of the phone.

@rom1v
Copy link
Collaborator

rom1v commented Aug 12, 2020

Correct me if I'm wrong, from my understanding it's the decoder that consumes more time than encoder.

I didn't do any benchmark, but I would say that encoder takes more time than decoder (there is more work to do).

(That's obvious for CPU encoder vs CPU decoder, but for hardware encoder I'm not totally sure.)

I used the video from #646 , it says 1 frame is 35ms latency.

OK, so at the resolution of OnePlus 7 Pro (1440×3120), you get around 60~70ms latency.

I used the adb shell command to change the phone's resolution so everything will be rendered at that resolution regardless of actual resolution of the phone.

OK, but two devices at the same definition will not necessarily give the same latency (it depends on the hardware).

@flyingduck234
Copy link
Author

it changes nothing above ~20Mbps

Yes, it's below 1 frame 🎉 Your encoder is probably very fast :)

#646 says 1frame is 35ms latency.

So is it safe to say scrcpy latency below 35ms

@rom1v
Copy link
Collaborator

rom1v commented Aug 12, 2020

#646 says 1frame is 35ms latency.

On your last screenshot, there are almost 2 frames:

  • on the computer, we still see the shadow of 895 with 896
  • on the device, we see 897 with the shadow of 898

It's a bit less than 2 frames, but not by a lot.

@flyingduck234
Copy link
Author

flyingduck234 commented Aug 12, 2020

#646 says 1frame is 35ms latency.

On your last screenshot, there are almost 2 frames:

  • on the computer, we still see the shadow of 895 with 896
  • on the device, we see 897 with the shadow of 898

It's a bit less than 2 frames, but not by a lot.
The last screenshot is to see if there could be latency with higher resolution.

As you said with default settings I'm getting less than 1 frame latency. So it would be below 35ms isn't it.

Scrcpy is the best mirroring software out there, so people should be seeing what it's capble of doing it

@flyingduck234
Copy link
Author

IMG_20200812_231546
Latency test

@flyingduck234
Copy link
Author

the latency is very good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants