Gstreamer video file corrupted after shutdown Jetson Nano

Hi, I’m currently saving the stream of 4 IP camera with this command :

gst-launch-1.0 nvcompositor -e background-w=2560 background-h=1440 name=mix     sink_0::xpos=0 sink_0::ypos=0 sink_0::width=1280 sink_0::height=720 sink_1::xpos=1280 sink_1::ypos=0 sink_1::width=1280 sink_1::height=720 sink_2::xpos=0 sink_2::ypos=720 sink_2::width=1280 sink_2::height=720 sink_3::xpos=1280 sink_3::ypos=720 sink_3::width=1280 sink_3::height=720        ! 'video/x-raw(memory:NVMM),format=RGBA,width=2560,height=1440' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvv4l2h264enc insert-vui=1 profile=2     ! h264parse ! video/x-h264,width=2560,height=1440,framerate=5/1 ! matroskamux  ! multifilesink location=/home/xavier/Documents/data/mosaic/2022-03-31_18:07:54%d.mp4 next-file=4 max-file-size=200000000 sync=false      rtspsrc location=rtsp://192.168.1.201:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,pixel-aspect-ratio=1/1' ! queue ! mix.sink_0 rtspsrc location=rtsp://192.168.1.202:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,pixel-aspect-ratio=1/1' ! queue ! mix.sink_1 rtspsrc location=rtsp://192.168.1.203:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,pixel-aspect-ratio=1/1' ! queue ! mix.sink_2 rtspsrc location=rtsp://192.168.1.204:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,pixel-aspect-ratio=1/1' ! queue ! mix.sink_3   

The file can be read normally if I exit with Ctrl+C but my problem is that when my Jetson shutdown (in my case I need it to happen) the video file is corrupted. The file has a size of 0 byte.

Is there a way to properly save the file when the jetson shutdown ?
Thanks

how exactly are you shutting down the Nano?

@user87221
There is a relay that controls the power supply to the jetson.
I cut the relay simply.

See 2.5.2 Power Down of the datsheet:

In a shutdown event the Jetson module asserts SHUTDOWN_REQ*. The SHUTDOWN_REQ* must be serviced by the carrier
board to toggle POWER_EN from high to low, even in cases of sudden power loss. The Jetson module starts the power off
sequence when POWER_EN is deasserted; SYS_RESET* is asserted by the Jetson module, allowing the carrier board to put
any components into a known state and power down.

not sure that that is the issue. but it is my first thought

So your idea is to detect when the shutdown event is detected to cancel the gstreamer properly ?

well that sounds like a good idea. but my idea originally was to handle the shutdown process properly. That is assuming that you are using a custom carrier board though. Are you using a custom carrier board, or are you using the devkit?

I’m using the dev kit, how to you handle the shutdown properly with the relay ?

i’m sure the dev kit handles it properly. My question was assuming you were using a custom carrier board. sorry, disregard

Hi,
Please use splitmuxsink:
splitmuxsink

And set matroskamux. Besides, it is better to insert SPS/PPS at IDR frames, and set IDR interval to a small value like 30 or 15.

Thanks for your answer.
I did like this but it doesn’t work :

gst-launch-1.0 nvcompositor -e background-w=2560 background-h=1440 name=mix sink_0::xpos=0 sink_0::ypos=0 sink_0::width=1280 sink_0::height=720 sink_1::xpos=1280 sink_1::ypos=0 sink_1::width=1280 sink_1::height=720 sink_2::xpos=0 sink_2::ypos=720 sink_2::width=1280 sink_2::height=720 sink_3::xpos=1280 sink_3::ypos=720 sink_3::width=1280 sink_3::height=720 ! ‘video/x-raw(memory:NVMM),format=RGBA,width=2560,height=1440’ ! nvvidconv ! ‘video/x-raw(memory:NVMM),format=NV12’ ! nvv4l2h264enc insert-vui=1 profile=2 ! h264parse ! video/x-h264,width=2560,height=1440,framerate=5/1 ! splitmuxsink muxer=matroskamux location=/home/xavier/Documents/data/mosaic/2022-04-01_11:05:16.mp4 max-size-time=30000000000 sync=false

Is it like this or there is another way to do it ?

Hi,
Please enable SPS/PPS at IDR frames and set small IDR interval. If it still does not work, may try to save to single file:

... ! matroskamux ! filesink location=a.mkv

I have already tried at the beginning this command
! matroskamux ! filesink location=a.mkv
but it didn’t work.
I don’t understand when you say to enable SPS/PPS. Can you give me example to do it ?
Thanks !

@DaneLLL
At the end, my command where I record into multiples files doesn’t work either. (in my first post)
The first file is correct but the the others don’t have a fix duration. The header is not correct I think.

And do you have an idea to correctly save the video file when the jetson is suddenly shutdown ?
Thanks !

Hi
Please set the properties:

... ! nvv4l2h264enc insert-sps-pps=1 idrinterval=15 ! ...
1 Like

Thanks a lot it works !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.