Reputation: 11
I'm rigging up some additional security cameras for my home office, and while I have battery backup in case of power loss, and auto startup for the code I developed, I would like the video files to be more robust in case of power loss or camera sabotage.
In the case of unexpected termination, for example if power were lost or a cable were sabotaged, it is important to save what's there, especially for security cameras. I've heard mkv files will save what is there if a recording is interrupted, but in practice, I have not experienced success. h264 encoding is not necessarily important to me. I can always change the encoding later.
The question is this: which file format and encoding format is preferred to preserve video data if recording is interrupted? Additionally, is there something else which I might need to know that I'm not considering?
I wrote a bash script using libcamera to autostart as soon as the desktop loads via systemd. It works fine, but if I do not terminate systemd, the file does not finalize, and the data is gibberish. I don't want to have to plug in an HDMI cable and keyboard to stop systemd every time I want to save a file and restart. I want to just have the file. I'm leaving a lot out here, but it records like so:
libcamera-vid --timeout 0000 --width 1920 --height 1080 --framerate 10 --codec h264 --profile high --intra 5 --listen -o $date.out.mkv
In any case, if I were to lose power unexpectedly, how might I ensure that the video data is saved?
Upvotes: 1
Views: 85
Reputation: 11
If power is lost unexpectedly, the corrupted file is recoverable by ffmpeg, so it's not that big of a deal. For example,
ffmpeg -i test.mkv -c:v libx264 test.mp4
will discard the corrupted frame(s). This might be the best result I could hope for, so I'm answering my own question. I was going out on a limb asking around, in any case.
Upvotes: 0