1

I have been recording video streams on my Jetson Xavier NX using a simple gstreamer pipeline such as this

gst-launch-1.0 -v \
nvarguscamerasrc sensor-id=0 ! \
'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1' ! \
nvv4l2h265enc ! 'video/x-h265, stream-format=(string)byte-stream' ! \
h265parse ! 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.

Otter_warrior
  • 193
  • 1
  • 12
  • 1
    You could try other "container" formats like **AVI**, **FLV** or possibly **MKV**. I would try **FLV** first since it was intended for streaming and so it builds the video in frame by frame packets (where if power cuts then you'll have an FLV that plays until the most recent frame / packet written before power problem occurs)... Experiment with it. I don't use GStreamer so not sure if it's designed to also write frame-by-frame or it waits until all data available to make output FLV. FFmpeg will write frame by frame to FLV. Set the FLV to contain H264 (same video codec as MP4) ... – VC.One Sep 16 '21 at 18:06
  • 1
    Thank you! In fact what I did in the end and worked for me was to use `matroskamux` instead of `qtmux` and saving to mkv files. I don't know how to save to flv with gstreamer at the moment since I'm a beginnner but I will look again into it if I need it again – Otter_warrior Sep 29 '21 at 15:04

1 Answers1

1

Check the qtmux/mp4mux element property moov-recovery-file:

moov-recovery-file  : File to be used to store data for moov atom making movie file recovery possible in case of a crash during muxing. Null for disabled. (Experimental)
                      flags: readable, writable
                      String. Default: null

Belonging to that is the qtmoovrecover element. If you have saved the recovery file with your original pipeline and want to recover a broken file you should be able to do it by creating a basic pipeline with just that element. It takes a broken input file, a recovery file and an output file as parameters and hopefully repairs your recording.

Note though that this feature is marked as experimental.

Florian Zwoch
  • 6,764
  • 2
  • 12
  • 21
  • Thank you much, this was very helpful! In the end what worked for me was using `matroskamux` and saving to mkv files, but I will keep this in mind if I need it for mp4 – Otter_warrior Sep 29 '21 at 15:02