Last active
October 5, 2023 14:34
-
-
Save AlLongley/a752decf49e6c789c2425e35028137a5 to your computer and use it in GitHub Desktop.
Android screen viewing Python client to "scrcpy"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Connect to an existing, ADB forwarded Android "scrcpy" session | |
and pipe the video stream into FFPlay | |
https://github.com/Genymobile/scrcpy/ | |
''' | |
import socket | |
import struct | |
import sys | |
import subprocess | |
import io | |
IP = '127.0.0.1' | |
PORT = 8080 | |
print("Connecting") | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((IP, PORT)) | |
DUMMYBYTE = sock.recv(1) | |
if not len(DUMMYBYTE): | |
print("Failed to connect!") | |
exit() | |
else: | |
print("Connected!") | |
#Receive device specs | |
deviceName = sock.recv(64) | |
print("Device Name:",deviceName.decode("utf-8")) | |
res = sock.recv(4) | |
WIDTH, HEIGHT = struct.unpack(">HH", res) | |
print("WxH:",WIDTH,"x",HEIGHT) | |
#Start FFPlay in pipe mode | |
ffplayCmd =['ffplay', '-'] | |
ffp = subprocess.Popen(ffplayCmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE) | |
while True: | |
data = sock.recv(10000) | |
ffp.stdin.write(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
adb push scrcpy-server.jar /data/local/tmp/ | |
start /B adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 800 800000 true | |
timeout 1 | |
start /B adb forward tcp:8080 localabstract:scrcpy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
adb push scrcpy-server.jar /data/local/tmp/ | |
adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 800 800000 true | |
sleep 1 | |
adb forward tcp:8080 localabstract:scrcpy |
what's the version of scrcpy-server.jar
when i run command adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 800 800000 true
error info:
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalArgumentException: The server version (1.16) does not match the
client (800)
at com.genymobile.scrcpy.Server.createOptions(Server.java:119)
at com.genymobile.scrcpy.Server.main(Server.java:221)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:388)
Greetings Allong, where can I find scrcpy-server.jar file?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allong12 I want to add cursor controls in the stream, will it be possible to do so