scrcpy
scrcpy copied to clipboard
stop recording option is not available in scrcpy
I am trying to build a script that can automatically get video from scrcpy without opening the scrcpy application is there any way i can do this. is there any way so that scrapy can record video for some specific time lets say 5 - 10 seconds and then automatically exit the program. or atleast any command that can close the recording without manual intervention
There is currently no option to stop automatically (recording or mirroring).
As a workaround, in bash (typically on linux), you could do that with a small script:
#!/bin/bash
scrcpy -Nr file.mkv &
pid=$!
sleep 10
kill $pid
Thanks for the response. I am looking to do this in windows is there any way to do this in windows.
I don't know, probably not.
(ah, yes, open it in MINGW and use a bash script, maybe?)
okay, thanks buddy
You can use pskill
from SysInternals to perform forced termination of the process in Windows, similar to how kill works in bash.
But if you kill the process (or if you Ctrl+C in the cmd console), the program has no change to clean up properly (in this case, to finish the recording and write the trailer), contrary to what happens on Linux.
yeah i already tried that taskkill in windows but i am not getting proper results. i was just wondering if i can change the source file to close scrcpy after some interval and then build scrcpy for windows. like we are manually closing scrcpy window so instead i can make scrcpy to close automatically after running for a particular time. can someone help me in that
i was just wondering if i can change the source file to close scrcpy after some interval
Yes. You could add a command-line option --stop-after
(for example).
You could register a timer (SDL_AddTimer
) and send a custom event to the event loop (here), where you could do almost the same as SQL_QUIT
.
Hi thanks for the reply. can you explain further where can i register the timer do i need to modify only scrcpy.c file or i need to change some other files as well.
Oh, is that b/c on Linux build, client installs some sort of signal handler that it lets it finish and write out properly all the buffers? Sorry, I didn't look at that code closely before recommending. Also, not sure what format scrcpy writes for captures, but if it is H.264 like what its server sends, then technically you should be able to kill mid stream without corrupting anything written thus far - but yeah, that's not very noble solution :).
B/w another way of doing it without code changes would be to kill scrcpy's server process on the device, assuming client would properly see socket close and terminate nicely. Process kill on the device can be done with adb without any modification or cooperation from scrcpy. Just throwing out ideas - no warranty on their goodness ;).
thanks for the idea Lbensman. but i am unable to find any such process running on the device to kill that.
rom1v i have added SDL_AddTimer and hardcoded the same for 5 seconds timer it is working properly in linux and closing after 5 seconds but when bult using makefile it is not working on windows. do i need to do any additional changes for windows built
B/w another way of doing it without code changes would be to kill scrcpy's server process on the device
Oh, that's true! https://github.com/Genymobile/scrcpy/issues/818#issuecomment-535931801
rom1v i have added SDL_AddTimer and hardcoded the same for 5 seconds timer it is working properly in linux and closing after 5 seconds but when bult using makefile it is not working on windows. do i need to do any additional changes for windows built
Show the diff.
thanks for the idea Lbensman. but i am unable to find any such process running on the device to kill that.
As @rom1v linked, the name of process is app_process
and link will work if it's the only one in the process list (if not, it'll kill other, unrelated, processes started with the same method). You can get a bit fancier and do some combination of ps
, grep
on CLI arguments for scrcpy server to get PID, and then kill
by PID, rather than pkill
, for a more targeted and safer operation.
https://github.com/jhachandan1994/scrcpy/blob/83504c0107787eab6502a5d0f278668836031269/app/src/main.c#L32
You should do that after SDL initialization:
https://github.com/Genymobile/scrcpy/blob/31bd95022bc525be42ca273d59a3211d964d278b/app/src/scrcpy.c#L52
Hello, Is there a possibility to stop recording the screen on windows? Currently, I have to unplug the device.
@Maciejszuchta Or close the window.
(Unfortunately, on Windows, Ctrl+C just kills the process, and the recording is corrupted.)
Closing the window also produces a corrupted file. Is there a plan on fixing this issue? Unplugging the device restrains me from using this wonderful library :(
Oh, that's not expected at all. (The scrcpy window, not the console window.)
Which version of scrcpy?
Is there any error message in the console when you close the scrcpy window?
https://github.com/Genymobile/scrcpy/issues/818#issuecomment-535931801
scrcpy 1.12.1 dependencies:
- SDL 2.0.10
- libavcodec 58.54.100
- libavformat 58.29.100
- libavutil 56.31.100
I open 'cmd' window in scrcpy folder and execute the commands from cmd
What command do you execute exactly?
I just tested with v1.12.1. I executed:
scrcpy -r file.mkv
and
scrcpy -r file.mp4
I closed the scrcpy window (not the console window), the resulting file is correct in both cases.
scrcpy -Nr file.mp4
- since i dont want to display srcpy window
Ah ok, that's expected then, you close the console, not the scrcpy window :)
See https://github.com/Genymobile/scrcpy/issues/818#issuecomment-535931801 for a workaround.
Another question is
I closed the scrcpy window (not the console window), the resulting file is correct in both cases.
How do you run the commands? Do you open cmd and run srccpy
? Or you do it differently?
See #818 (comment) for a workaround.
What is app_process ??