【HELP】The mp4 file recorded through scrcpy cannot be opened, the file is corrupted. (original) (raw)

I use the following Python script to start screen recording:

process = subprocess.Popen(['scrcpy', '-s', 'a3c1fab5', '--no-display', '-b', '300000', '--record', '/tmp/20240814141706907.mp4', '--max-size', '1280'],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   encoding="utf-8",
                                   shell=False)

And then use the following Python script to stop screen recording:

process.terminate()
try:
    process.wait(timeout=30)
except subprocess.TimeoutExpired:
    logger.warning("Scrcpy process did not terminate within timeout period.")

It always throws subprocess.TimeoutExpired error, It seems that the resources of scrcpy are not being released, causing a timeout.

and then the file /tmp/20240814141706907.mp4 cannot be opened.

Is there an issue with the way I am closing the scrcpy process? Looking forward to your reply.


p.s. I directly execute the command scrcpy -s a3c1fab5 --no-display -b 300000 --record /tmp/20240814141706907.mp4 --max-size 1280 through the command line. After pressing Ctrl+C, the file can be opened.