How to record playable video files in gstreamer even if recording is interrupted unexpectedly (e.g. power disconnects)?

James jam at tigger.ws
Tue Sep 14 22:42:24 UTC 2021



> On 14 Sep 2021, at 11:34 pm, Tim Müller via gstreamer-devel <gstreamer-devel at lists.freedesktop.org> wrote:
> 
> 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 <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.

Tim I have a program 'untrunc' that I use on mp4 files made by sensoray cards.
It does not work with gstreamer files and I will get round to modifying it but if you want t try you can have the C source. It usess ffmpeg libraries for avcformat etc

James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20210915/966918a8/attachment.htm>


More information about the gstreamer-devel mailing list