Skip to content

Instantly share code, notes, and snippets.

@AlLongley
Last active October 5, 2023 14:34
Show Gist options
  • Save AlLongley/a752decf49e6c789c2425e35028137a5 to your computer and use it in GitHub Desktop.
Save AlLongley/a752decf49e6c789c2425e35028137a5 to your computer and use it in GitHub Desktop.
Android screen viewing Python client to "scrcpy"
'''
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)
@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
#!/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
@bzqyzzld
Copy link

bzqyzzld commented Sep 22, 2020

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)

@zhangzhengde0225
Copy link

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