boonya / rtsp-video-recorder

Provides an API to record RTSP video stream to filesystem.
https://www.npmjs.com/package/rtsp-video-recorder
MIT License
33 stars 4 forks source link

Kill process avoid to set correctly the mime headers #383

Open manuelcanepa opened 1 year ago

manuelcanepa commented 1 year ago

After a few tries, i learn that the command ffmpg will stay alive saving the video file, if you kill the process, the video will be partially correct if you check the mime type with file you will get an application/octet-stream type instead of video/mp4:

$ file --mime-type -b 00.34.11.mp4
$ application/octet-stream

https://github.com/boonya/rtsp-video-recorder/blob/acc2eebe591796e4676e2cde6747b572a433c15e/src/recorder.ts#LL154C23-L154C23

manuelcanepa commented 1 year ago

Maybe a fix will be replace the kill with a stdin.write("q\n") and wait to the process to close itself:

- this.process.kill();
+ this.process.stdin.write("q\n");
boonya commented 1 year ago

Cool. Thank you for your input here. I will take a look as soon as possible and let you know. I hope I will have a time this weekend.

boonya commented 1 year ago

I quickly investigated the issue and can say that the root cause of wrong mime tipe is not that you've mentioned.

I have ran ffmpeg process directly and killed it by ctrl+c for the first time. And soft quit from it for the second.

The result is below:

➜ file --mime-type -b  Balkon-2023.05.19/15.09.15.mp4
application/octet-stream
➜ file --mime-type -b  Balkon-2023.05.19/15.10.08.mp4
application/octet-stream

I am going to continue work on that issue as soon as I have time.