scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

stop recording option is not available in scrcpy

Open jhachandan1994 opened this issue 5 years ago • 37 comments

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

jhachandan1994 avatar Dec 20 '19 14:12 jhachandan1994

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

rom1v avatar Dec 20 '19 14:12 rom1v

Thanks for the response. I am looking to do this in windows is there any way to do this in windows.

jhachandan1994 avatar Dec 20 '19 16:12 jhachandan1994

I don't know, probably not.

rom1v avatar Dec 20 '19 16:12 rom1v

(ah, yes, open it in MINGW and use a bash script, maybe?)

rom1v avatar Dec 20 '19 16:12 rom1v

okay, thanks buddy

jhachandan1994 avatar Dec 20 '19 16:12 jhachandan1994

You can use pskill from SysInternals to perform forced termination of the process in Windows, similar to how kill works in bash.

LBensman avatar Dec 20 '19 18:12 LBensman

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.

rom1v avatar Dec 20 '19 18:12 rom1v

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

jhachandan1994 avatar Dec 20 '19 18:12 jhachandan1994

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.

rom1v avatar Dec 20 '19 18:12 rom1v

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.

jhachandan1994 avatar Dec 20 '19 19:12 jhachandan1994

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

LBensman avatar Dec 20 '19 21:12 LBensman

thanks for the idea Lbensman. but i am unable to find any such process running on the device to kill that.

jhachandan1994 avatar Dec 20 '19 21:12 jhachandan1994

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

jhachandan1994 avatar Dec 20 '19 21:12 jhachandan1994

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 avatar Dec 20 '19 22:12 rom1v

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.

rom1v avatar Dec 20 '19 22:12 rom1v

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.

LBensman avatar Dec 20 '19 22:12 LBensman

https://github.com/jhachandan1994/scrcpy/blob/83504c0107787eab6502a5d0f278668836031269/app/src/main.c#L32

jhachandan1994 avatar Dec 20 '19 22:12 jhachandan1994

You should do that after SDL initialization:

https://github.com/Genymobile/scrcpy/blob/31bd95022bc525be42ca273d59a3211d964d278b/app/src/scrcpy.c#L52

rom1v avatar Dec 21 '19 10:12 rom1v

Hello, Is there a possibility to stop recording the screen on windows? Currently, I have to unplug the device.

Maciejszuchta avatar Apr 06 '20 07:04 Maciejszuchta

@Maciejszuchta Or close the window.

(Unfortunately, on Windows, Ctrl+C just kills the process, and the recording is corrupted.)

rom1v avatar Apr 06 '20 07:04 rom1v

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 :(

Maciejszuchta avatar Apr 06 '20 07:04 Maciejszuchta

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?

rom1v avatar Apr 06 '20 07:04 rom1v

https://github.com/Genymobile/scrcpy/issues/818#issuecomment-535931801

rom1v avatar Apr 06 '20 07:04 rom1v

scrcpy 1.12.1 dependencies:

  • SDL 2.0.10
  • libavcodec 58.54.100
  • libavformat 58.29.100
  • libavutil 56.31.100

Maciejszuchta avatar Apr 06 '20 07:04 Maciejszuchta

I open 'cmd' window in scrcpy folder and execute the commands from cmd

Maciejszuchta avatar Apr 06 '20 07:04 Maciejszuchta

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.

rom1v avatar Apr 06 '20 08:04 rom1v

scrcpy -Nr file.mp4 - since i dont want to display srcpy window

Maciejszuchta avatar Apr 06 '20 08:04 Maciejszuchta

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.

rom1v avatar Apr 06 '20 08:04 rom1v

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?

Maciejszuchta avatar Apr 06 '20 09:04 Maciejszuchta

See #818 (comment) for a workaround.

What is app_process ??

Maciejszuchta avatar Apr 06 '20 09:04 Maciejszuchta