How to record playable video files in gstreamer even if recording is interrupted unexpectedly (e.g. power disconnects)?
Tim Müller
tim at centricular.com
Tue Sep 14 15:34:09 UTC 2021
Hi Letty,
> I have been recording video streams on my Jetson Xavier NX using a
> simple gstreamer pipeline such as this
>
> gst-launch-1.0 -v ... ! qtmux ! filesink location=video.mp4 -e
>
> All is working if the recording is interrupted by keyboard interrupt
> Ctrl + C, but if the recording is interrupted unexpectedly (e.g.
> power gets disconnected) the resulting file has no playable stream,
> even if the file size is correct.
>
> I know that mp4 recording needs to be stopped properly otherwise it
> won't have the necessary information at the end of the file, but I
> was wondering if there was any other gstreamer pipelines or final
> file formats that would allow for an H265 encoded video file to be
> playable even if the recording is ended unexpectedly.
>
> It would be good even if the recorded file needed to be converted
> before being playable (e.g. with ffmpeg), as long as the information
> can be recovered without having to go through non-free mp4 recovery
> tools.
There are a couple of options here.
One is to use the "moov-recovery-file" property, then in case of a
crash or power cut you can later recover the data and reconstruct the
file using the (free) qtmoovrecover element.
If you have an idea of the maximum duration of your files there's also
the "Robust muxing" mode which basically reserves space for two sets of
headers and then periodically switches between them, so in case of a
powercut you'd only lose the last few seconds (however much time
elapsed since the last switchover). See
https://gstreamer.freedesktop.org/documentation/isomp4/qtmux.html
for more details.
Yet another possibility is to output a fragmented mp4 file, but your
mileage with that may vary and it will depend a bit on the GStreamer
version how well that works.
Cheers
Tim
More information about the gstreamer-devel
mailing list