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

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

Closed
williamfzc opened this issue Sep 25, 2019 · 18 comments
Closed

Comments

@williamfzc
Copy link

:) 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 ~?

@rom1v
Copy link
Collaborator

rom1v commented Sep 25, 2019

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.

@williamfzc
Copy link
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!

@rom1v
Copy link
Collaborator

rom1v commented Sep 25, 2019

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.

@williamfzc
Copy link
Author

williamfzc commented Sep 26, 2019

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' ...

@rom1v
Copy link
Collaborator

rom1v commented Sep 27, 2019

You could also kill the process on the device instead:

adb shell pkill app_process

(assuming it is the only one running)

@williamfzc
Copy link
Author

williamfzc commented Feb 28, 2020

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.

@lbathina
Copy link

lbathina commented May 6, 2020

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

@rom1v
Copy link
Collaborator

rom1v commented May 6, 2020

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

@rom1v
Copy link
Collaborator

rom1v commented May 8, 2020

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

rom1v added a commit that referenced this issue May 8, 2020
By default, Ctrl+C just kills the process on Windows. This caused
corrupted video files on recording.

Handle Ctrl+C properly to clean up properly.

Fixes #818 <#818>
@lbathina
Copy link

lbathina commented May 8, 2020

@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?

@williamfzc
Copy link
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.

@rom1v
Copy link
Collaborator

rom1v commented May 8, 2020

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).

@LBensman
Copy link

LBensman commented May 8, 2020

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).

@rom1v
Copy link
Collaborator

rom1v commented May 8, 2020

@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.

@rom1v rom1v closed this as completed May 25, 2020
@rom1v rom1v mentioned this issue Jul 27, 2020
@walkthunder
Copy link

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

@k-inoway
Copy link

k-inoway commented Oct 19, 2021

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)

@Pomidorum1989
Copy link

Pomidorum1989 commented Oct 13, 2022

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.

@cjjdream
Copy link

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
Projects
None yet
Development

No branches or pull requests

8 participants