leng-yue / py-scrcpy-client

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

ConnectionError: Video stream is disconnected #41

Closed jinxiangwzh closed 1 year ago

jinxiangwzh commented 1 year ago

I use scrcpy can connect success, but I run py-scrcpy raise the error below. And I want to take part in this project, is there have any document? image

leng-yue commented 1 year ago

This means that the client's video stream to the scrcpy-server is disconnected. To help me analyze the problem:

leng-yue commented 1 year ago

Feel free to open this issue again if there is any update.

marisancans commented 1 year ago

Im having the same issue, regular scrcpy works for me, im using: scrcpy 1.12.1

dependencies:

Changing core.py log level to "verbose" doesnt yield and information on how to fix this except a stack trace.

Also scrcpy_ui/main.py doesnt work out of the box (git pull) python3 scrcpy_ui/main.py and cd && python3 main.py throws error: ImportError: attempted relative import with no known parent package

Here is the trace:

py-scrcpy-client on  main [!?] is 📦 v0.4.7 via 🐍 v3.9.15 via 🅒 pairing took 16s 
❯  cd /mnt/data/src/py-scrcpy-client ; /usr/bin/env /home/ma/anaconda3/envs/pairing/bin/python /home/ma/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 39915 -- /mnt/data/src/py-scrcpy-client/scrcpy_ui/main.py 
Traceback (most recent call last):
  File "/home/ma/anaconda3/envs/pairing/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/ma/anaconda3/envs/pairing/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/ma/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/home/ma/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/home/ma/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/home/ma/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/home/ma/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/ma/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/mnt/data/src/py-scrcpy-client/scrcpy_ui/main.py", line 198, in <module>
    main()
  File "/mnt/data/src/py-scrcpy-client/scrcpy_ui/main.py", line 192, in main
    m.client.start()
  File "/home/ma/anaconda3/envs/pairing/lib/python3.9/site-packages/scrcpy/core.py", line 200, in start
    self.__stream_loop()
  File "/home/ma/anaconda3/envs/pairing/lib/python3.9/site-packages/scrcpy/core.py", line 253, in __stream_loop
    raise e
  File "/home/ma/anaconda3/envs/pairing/lib/python3.9/site-packages/scrcpy/core.py", line 234, in __stream_loop
    raise ConnectionError("Video stream is disconnected")
ConnectionError: Video stream is disconnected
marisancans commented 1 year ago

Interestingly this simple code does work for me:

import scrcpy
# If you already know the device serial
client = scrcpy.Client(device="DEVICE SERIAL")
# You can also pass an ADBClient instance to it
from adbutils import adb
adb.connect("127.0.0.1:5555")
client = scrcpy.Client(device=adb.device_list()[0])

import cv2

def on_frame(frame):
    # If you set non-blocking (default) in constructor, the frame event receiver 
    # may receive None to avoid blocking event.
    if frame is not None:
        # frame is an bgr numpy ndarray (cv2' default format)
        cv2.imshow("viz", frame)
    cv2.waitKey(10)

client.add_listener(scrcpy.EVENT_FRAME, on_frame)

client.start()
leng-yue commented 1 year ago

So while the simple one works, the above doesn't work for you? The only difference is that the cli uses threading. Can you try add threaded=True to the client.start for the simple one?

onesu-obolik commented 1 week ago

Hello, I have exactly the same issue. The demo code posted by marisancans doesn't show anything, terminal just stay empty. If I add ("print") markers to know where the error comes from, it seems it blocks when opencv2 is supposed to render the frame. With py-scrcpy, the name of the phone appears for a millisecond before closing windows and giving the same "video stream is disconnected". with the even simpler demo here below, phone screen reacts and gets full light, but that's it. has somebody any better idea? I am losing courage after 2 evenings in a row changing parameters in program for no result...thanks in advance Phone: Redmi note 7 with E/OS

import cv2 as cv from pyscrcpy import Client # import scrcpy client

def on_frame(client, frame): client.control.text("123") cv.imshow('Video', frame) cv.waitKey(1)

if name == 'main': client = Client(max_fps=1, max_size=900) client.on_frame(on_frame) client.start()