Skip to content

What is the best way to interrupt recording (programmable) in Windows? #818

Closed

Description

@williamfzc

:) hi

scrcpy --no-display --record file.mp4
scrcpy -Nr file.mkv
# interrupt recording with Ctrl+C
# Ctrl+C does not terminate properly on Windows, so disconnect the device

I can only get a broken video after sending a CTRL_C_EVENT signal to scrcpy process.
And, disconnect the device is not a programmable way.
I have to restart my adb-server instead (it works), but it may influence other devices.

Any suggestions ~?

Activity

  1. rom1v commented on Sep 25, 2019

    @rom1v
    Collaborator

    I can only get a broken video after sending a CTRL_C_EVENT signal to scrcpy process.

    Yes, it is not good.

    (note that if you record in mkv instead of mp4, the video is less broken, since mp4 writes its header at the end – which is then not written)

    Any suggestions ~?

    Unfortunately, no good solution.

    You could kill the adb shell process which runs the server.

  2. williamfzc commented on Sep 25, 2019

    @williamfzc
    Author

    image

    import subprocess
    import time
    
    p = subprocess.Popen(['scrcpy', '--record', 'haha.mkv'])
    time.sleep(3)
    p.kill()

    emmm, both of them were broken thoroughly I think.

    You could kill the adb shell process which runs the server.

    It works. A little weird but much better than restart adb server at least. Thanks!

  3. rom1v commented on Sep 25, 2019

    @rom1v
    Collaborator

    both of them were broken thoroughly I think.

    If you record longer (and actually move things on screen), data will be written to the mkv, and it will play in VLC or whatever. With mp4, data will be written, but it will not play.

  4. williamfzc commented on Sep 26, 2019

    @williamfzc
    Author

    ok, thank you :)

    about how to find the adb shell process which runs the server

    check the cmdline of the process named adb.exe. scrcpy's cmdline will always be:

    'adb', 'shell', 'CLASSPATH=/data/local/tmp/scrcpy-server.jar', 'app_process', '/', 'com.genymobile.scrcpy.Server', '0', '8000000', 'false', '-', 'true', 'true'
    

    for multi devices:

    'adb', '-s', '123456F', 'shell', 'CLASSPATH=/data/local/tmp/scrcpy-server.jar' ...
    
  5. rom1v commented on Sep 27, 2019

    @rom1v
    Collaborator

    You could also kill the process on the device instead:

    adb shell pkill app_process
    

    (assuming it is the only one running)

  6. williamfzc commented on Feb 28, 2020

    @williamfzc
    Author

    BTW,

    For Windows, for simplicity, prebuilt archives with all the dependencies (including adb) are available

    Scrcpy will use the adb, which was included in prebuilt archives by default (I guess), if you configure scrcpy to $PATH.

    And if you already have an installed adb on your PC, actually you can not access your phone with this adb directly, because current adb design only supports one adb server connection per adbd.

    So if you gonna running adb shell pkill app_process, you need to keep only one adb in your $PATH (or, keep a specific order?). What's more, pkill seems to works above android 6 at least.

  7. lbathina commented on May 6, 2020

    @lbathina

    I see the same issue with macOS as well. It will be helpful to have stop method/option with scrcpy to be executed from command line

  8. rom1v commented on May 6, 2020

    @rom1v
    Collaborator

    On macOS, Ctrl+C should work as expected, doesn't it?

  9. rom1v commented on May 8, 2020

    @rom1v
    Collaborator

    I implemented a fix for Windows: 28abd98

    Please test by replacing these files in the v1.13 release:

    • scrcpy.exe
      SHA256: 5c6516793f638d7d2b5ef518b1c59421087e1a3bbc3a1e3ac3a44617b6d2315d
    • scrcpy-server
      SHA256: 6d124307e081b8bbccc478dcf82731aad3cc994e7502197c9bae3847d3169dc7
  10. added a commit that references this issue on May 8, 2020
    28abd98
  11. lbathina commented on May 8, 2020

    @lbathina

    @rom1v Manually it had no issues. I was able to get it worked on macOs via Java programming. I am looking for linux binary so I could get that installed in my test environment for which I do not have root access. Is it possible that linux binary is available?

  12. williamfzc commented on May 8, 2020

    @williamfzc
    Author

    @rom1v Manually it had no issues. I was able to get it worked on macOs via Java programming. I am looking for linux binary so I could get that installed in my test environment for which I do not have root access. Is it possible that linux binary is available?

    What about docker? #94

    I implemented a fix for Windows: 28abd98

    Thanks! I will try later.

  13. rom1v commented on May 8, 2020

    @rom1v
    Collaborator

    Is it possible that linux binary is available?

    Linux binaries must be different for each distrib/version. That's why I don't publish them (but I I provide the prebuilt server, and building from linux is "easy" if you gollow the steps).

  14. LBensman commented on May 8, 2020

    @LBensman

    Is it possible that linux binary is available?

    Linux binaries must be different for each distrib/version. That's why I don't publish them (but I I provide the prebuilt server, and building from linux is "easy" if you gollow the steps).

    AFAIU, if you perform static compile, then you can have a single build that will work on various distributions/versions. It also means that any and every library that scrcpy uses (client-side, obviously) also needs to be a static library (i.e. either use static version if distribution has it, or build one from source).

  15. rom1v commented on May 8, 2020

    @rom1v
    Collaborator

    @LBensman Absolutely. A static build would be great, but is not supported for now.

    If someone want to improve the build system to optionally build sdl and ffmpeg (only the parts scrcpy is using) and link statically, please go ahead.

  16. walkthunder commented on Feb 11, 2021

    @walkthunder

    @rom1v so the static build feature is closed? Really need it.

  17. k-inoway commented on Oct 19, 2021

    @k-inoway

    I used this package to solve this problem.
    A portion of the code is also attached for reference.
    I hope this helps. :)

    https://pypi.org/project/console-ctrl/

    command = f"{SCRCPY_PATH} --serial {self.serial} --no-display --record {TMP_PATH}\\file.mp4"
    self.record_proc = subprocess.Popen(command,
                                        shell=True,
                                        creationflags=subprocess.CREATE_NEW_CONSOLE,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
    def closeEvent(self, event):
        if self.record_proc:
            if self.record_proc.poll() is None:
                console_ctrl.send_ctrl_c(self.record_proc.pid)
  18. pomidorum1989 commented on Oct 13, 2022

    @pomidorum1989

    I am looking the same solution for JVM. I want to record the video throught the java code, but killing the cmd process is only corrupting the video file. So I need to figure out how to send the finish recording event to the console throught the java code. I have also tried to kill app_process on the device but the video file is still corrupted.

  19. cjjdream commented on Feb 23, 2023

    @cjjdream

    I faced to the same question。 would you find any solutions for the issue for JVM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions