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

Add server options to send raw H.264 without using the client #2971

Merged
merged 0 commits into from
Jan 26, 2022

Conversation

rom1v
Copy link
Collaborator

@rom1v rom1v commented Jan 26, 2022

This is useful to use the scrcpy-server alone (without the client) just to get the raw H.264 stream:

adb push scrcpy-server /data/local/tmp/scrcpy-server.jar
adb forward tcp:1234 localabstract:scrcpy
adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar \
    app_process / com.genymobile.scrcpy.Server 1.22 \
    raw_video_stream=true tunnel_forward=true control=false

As soon as a client connects via TCP to localhost:1234, it will receive the raw H.264 stream.

For example, it can be played with VLC (but with a lot of delay due to buffering):

vlc --demux h264 tcp://localhost:1234

Refs #1419 (comment)

rom1v added a commit that referenced this pull request Jan 26, 2022
This will allow to optionally disable it.

PR #2971 <#2971>
rom1v added a commit that referenced this pull request Jan 26, 2022
Move the options unused by the scrcpy client at the end.

These options may be useful to use scrcpy-server directly (to get a raw
H.264 stream for example).

PR #2971 <#2971>
rom1v added a commit that referenced this pull request Jan 26, 2022
Similar to send_device_frame, this option allows to disable sending the
device name and size on start.

This is only useful when using the scrcpy-server alone to get a raw
H.264 stream, without using the scrcpy client.

PR #2971 <#2971>
rom1v added a commit that referenced this pull request Jan 26, 2022
If set to false, no dummy byte is written to detect a connection error.

PR #2971 <#2971>
@rom1v rom1v merged commit 93ac6a3 into dev Jan 26, 2022
rom1v added a commit that referenced this pull request Jan 27, 2022
For convenience, this new option forces the 3 following options:
 - send_device_meta=false
 - send_frame_meta=false
 - send_dummy_byte=false

This allows to send a raw H.264 stream on the video socket.

Concretely:

    adb push scrcpy-server /data/local/tmp/scrcpy-server.jar
    adb forward tcp:1234 localabstract:scrcpy
    adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar \
        app_process / com.genymobile.scrcpy.Server 1.21 \
        raw_video_stream=true tunnel_forward=true control=false

As soon as a client connects via TCP to localhost:1234, it will receive
the raw H.264 stream.

Refs #1419 comment <#1419 (comment)>
PR #2971 <#2971>
@rom1v
Copy link
Collaborator Author

rom1v commented Jan 29, 2022

GitHub has lost the commits in the PR after a rebase. Here they are:

@elf-world
Copy link

Can windows support this?

@rom1v
Copy link
Collaborator Author

rom1v commented Feb 18, 2022

Yes, it's platform-independent.

@elf-world
Copy link

But VLC didn't respond when I used it on windows.

@elf-world
Copy link

elf-world commented Feb 18, 2022

It cannot be played due to the firewall. It has been solved now. But how to set the frame rate and code rate of the original H.264 video stream?

@rom1v
Copy link
Collaborator Author

rom1v commented Feb 18, 2022

The H.264 has no fixed framerate: a new frame is produced whenever the device screen surface "changes".

To play it with VLC, see https://code.videolan.org/rom1v/vlc/-/merge_requests/20

@Abunwer
Copy link

Abunwer commented Feb 26, 2022

@rom1v thank u for this, but I'm trying to get the server.jar file, I think I have to update the gradle file to build a jar file, I tried but I couldn't find the right way to do it? I'm new to gradle, do you have any idea how I can get the server.jar file by building the source code?

@rom1v
Copy link
Collaborator Author

rom1v commented Feb 7, 2023

adb push . \scrcpy-server /data/local/tmp/scrcpy-server

You put an extra space between . and \.

You can also add cleanup=false to avoid removing the server on the device.

@nnnpa31
Copy link

nnnpa31 commented Feb 8, 2023

You put an extra space between . and \.

Thanks, this is really a low mistake due to my oversight. That's why I deleted my reply. Thank you very much for your reply.

@nnnpa31 nnnpa31 mentioned this pull request Mar 7, 2023
1 task
@JJLo1
Copy link

JJLo1 commented Jun 29, 2023

after running the last command on adb it returns "Aborted" after about 2 seconds
im running the command in 1 line:
adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process com.genymobile.scrcpy.Server 1.22 raw_video_stream=true tunnel_forward=true control=false

my scrcpy-server is the one from the current scrcpy-win64-v2.1.zip
any idea whats the problem?

@rom1v
Copy link
Collaborator Author

rom1v commented Jun 29, 2023

@JJLo1
Copy link

JJLo1 commented Jun 29, 2023

ah, ok i broke it by accidently deleting the forward slash between app_process and com.genymobile...
ty for quick answer though
Edit: your documentation says adb push scrcpy-server-v2.1 /data/local/tmp/scrcpy-server-manual.jar even thought i have not seen scrcpy-server file with appended version number yet (neither in downloaded variants nor after building myself)

@ouinouin
Copy link

ouinouin commented Sep 9, 2024

@rom1v , I tried the commandlines , on my side i couldnt get the adb commandline to work, this gives me : aborted as a result (the phone is able to stream the camera otherwise.. the concept of scrcpy streaming directly some h264 is promising and opens a lot of possibilities of recycling old phones as cameras over tcpip (looking at you frigate and go2rtc), but for this to happen, we would need something easy to just enable the stream while the phone is starting. would it be easy to have a dead simple user interface on the apk/jar scrcpy-server sideloaded ? (unsure if the scrcpy is a jar file or an APK..).

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

Successfully merging this pull request may close these issues.

6 participants