Miguel-Dorta / rtsp-recorder

A very basic/simple RTSP recorder for Linux
MIT License
10 stars 1 forks source link

Error removing tmp extension from file #1

Open hsg120 opened 2 months ago

hsg120 commented 2 months ago

I'm running this on Arch.

The ffmpeg command that is created when the service starts is /usr/bin/ffmpeg -nostdin -rtsp_transport tcp -t 600 -i rtsp://user:password@192.168.0.219:8554/unicast -c copy /var/rec/poop/2024/04/27/2024-04-27_22-40-04

No temporary video file is created upon service start. However, if I run the ffmpeg command manually, it creates a .mkv video file from the stream without any issues.

Output from "journalctl | grep rtsp-recorder" Apr 27 23:01:22 TurboEncabulator rtsp-recorder_$i[3649944]: [2024-04-27 23:01:22.017018697] ERROR: error removing tmp extension from file '/var/rec/poop/2024/04/27/2024-04-27_23-01-20': rename /var/rec/poop/2024/04/27/2024-04-27_23-01-20.tmp.mkv /var/rec/poop/2024/04/27/2024-04-27_23-01-20.mkv: no such file or directory

I don't know if this is of any relevance, but the file in the ffmpeg command was 2024-04-27_22-40-04. Whereas the file mentioned in the journalctl error output is always 2 seconds behind, (e.g. 2024-04-27_22-40-02.mkv).

Any idea what is going on here? Thanks!!

Miguel-Dorta commented 2 months ago

I'll look into it. This project needs some improvement (I didn't knew anyone but me was using it). I'll get you back in a week or two with a version that has better debug options.

hsg120 commented 2 months ago

I would appreciate that so much!!

Your project is actually exactly what I was looking for. I have several Wyze cams whose RTSP streams I would like to save to a NAS on my LAN.

Truth be told, I wasn't counting on a reply here so I provided a pretty rough sketch of my particular issue. If you do release something with more debug options in the future I'll make sure to provide more thorough feedback.

Miguel-Dorta commented 2 months ago

I've just found I had two commits I didn't push since last August 😅 can you check if has been fixed?

hsg120 commented 2 months ago

I've just found I had two commits I didn't push since last August 😅 can you check if has been fixed?

Hey! Yes for sure! Thank you so much for looking into this!!

And apologies for the late reply. I was traveling internationally for business for the past two weeks, but I'm home now so I'll give this a shot today and let you know what I get on my end.

Cheers!

icaroerasmo commented 1 month ago

Same thing is happening to me. Also running Arch Linux. @hsg120 did you do anything else for it to work?

icaroerasmo commented 1 month ago

I got it to work with ffmpeg with following command: ffmpeg -i 'rtsp://admin:<passwd>@192.168.3.24:554/onvif1' -vcodec copy -acodec copy -map 0 -f segment -segment_time 300 "ffmpeg_capture-%03d.mkv"

I'd like to know if it is possible to make necessary changes for rtsp-recorder to work with my cameras. Or at least have some guidance so I can fork the project myself and do the changes.

hsg120 commented 1 month ago

@icaroerasmo I have not gotten it to work on my end, but I don't think it's any fault of this particular program. I'm currently stuck with a directory permission issue. I'd intended to come back with some kind of useful feedback for @Miguel-Dorta but I spent a few hours last month trying to fix my particular issue and I'm failing miserably.

I downloaded the updated version of this program and installed it. I created a service, configuration file, and moved the binary.

When I start the rtsp-recorder service it fails immediately. When I check the systemd log file it says--

error starting recorder: error creating recording parent directory '/var/rec/poop/2024/06/15': mkdir /var/rec/poop: permission denied

I'm at a loss though because my user account has read/write permission to that directory. I also tried logging in and running the service as root, but still got the same error. I'm probably doing something dumb, but the solution eludes me.

hsg120 commented 1 month ago

@icaroerasmo

I can confirm it works! I was in fact doing something stupid with the configuration and/or service files. Also, I had to take ownership of /var/rec.

Now, I'm going to further configure it to my liking, and try adding more cameras.

Thank you @Miguel-Dorta so SO much for getting this working!!!!! I am so appreciative.

Edit: Is there a way to limit the number of videos saved in order to prevent filling the hard disk?

icaroerasmo commented 1 month ago

@hsg120 it seems it is something with my cameras that stream videos in a format which is not expected by rtsp-recorder. I decided to implement a solution myself in shell script.

Miguel-Dorta commented 1 month ago

A lot of messages during the weekend! Let me reply one by one.

I can confirm it works! I was in fact doing something stupid with the configuration and/or service files. Also, I had to take ownership of /var/rec.

Now, I'm going to further configure it to my liking, and try adding more cameras.

Thank you @Miguel-Dorta so SO much for getting this working!!!!! I am so appreciative.

I'm so glad you get it working! 🎉 I will use this to update the README and include it! Thank you for your feedback! 🙂

Edit: Is there a way to limit the number of videos saved in order to prevent filling the hard disk?

I'm using a simple program I made myself for that. It limits the recordings by disk space and time. If you are interested I can publish it. It'd probably take me a few weeks tho.

I got it to work with ffmpeg with following command: ffmpeg -i 'rtsp://admin:<passwd>@192.168.3.24:554/onvif1' -vcodec copy -acodec copy -map 0 -f segment -segment_time 300 "ffmpeg_capture-%03d.mkv"

I'd like to know if it is possible to make necessary changes for rtsp-recorder to work with my cameras. Or at least have some guidance so I can fork the project myself and do the changes.

Sure! Can you investigate further what does it make your command work? My guess is the -map 0, but you need to test it with your cameras to be sure. If it's that, I can look into adding more parameters to the ffmpeg subprocess.

You can also 100% fork this repo (the freedom of open source). If you wanna some guidance, if we simplify this program, it's just the following:

while (!SIGINT) {
  exec("ffmpeg", ...)
  sleep(time)
  exitFfmpeg()

  if (reportStatus) {
    http(method, url)
  }
}

It's obviously more complex than this, because it needs to handle signals, ffmpeg hangs, report endpoint timeouts, etc. but this is the basic behaviour.

If you want to modify the ffmpeg parameters, it's here

And this is the main loop

icaroerasmo commented 4 weeks ago

What I saw is that each camera has its own output format. I had to discover mine searching on Google. I will fork the repository and try to implement a profile feature so each format will generate a specific ffmpeg command.