Save IP camera rtsp stream to mp4 file

Hi, I have an Hikvision IP camera and want to record mp4 videos with hardware acceleration on Jetson Nano or TX2.

I have tried gstreamer and got some errors, the saved video file can not be opened.

gst-launch-1.0 -e rtspsrc location=rtsp://admin:xxxxxx@ protocols=tcp ! rtph264depay ! h264parse ! mp4mux ! filesink location=~/camera.mp4

For saving to a mp4 file, you would need to send EoS(End of Stream) before closing the pipeline. This seems impossible in RTSP. Suggest you use matroskamux ! filesink location=a.mkv

Thanks @DaneLLL

I change my command to:
gst-launch-1.0 -e rtspsrc location=rtsp://admin:xxxxxx@ protocols=tcp ! rtph264depay ! h264parse ! matroskamux ! filesink location=a.mkv

And got this:

We are able to run matroskamux ! filesink location=a.mkv successfully.
Maybe you can try mpegtsmux ! filesink location=a.ts

Thanks, mpegtsmux works successfully.

But both mp4mux and matroskamux can run for a few seconds but will cause those errors above.

Did I miss something?

Not sure but it might be specific to the RTSP source. Probably it does not give certain information such as timestamp.

I changed to other RTSP sources and got same problem.

The resolusion of IP camera is 4000x3000, I got 15 fps when using mpegtsmux to save video on Xavier NX or Nano.

I’m not sure if it was accerated by hardware, how can it be possible to save 25 fps with 4000x3000 resolution on jetson platform?

The plugins in the pipeline are all native gstreamer plugins. Don’t have NVIDIA plugins. Suggest you go to gstreamer forum to get further help.

Thanks, I’m still wondering what’s the best way to recording with hardware acceleration on jetson platform? Could you give me some references?

We have gstreamer and jetson_multimedia_api. Please look at documents:

I just found that when I disable electronic image stabilization in IP camera setting, everything works perfectly, including mp4mux and matroskamux.

That’s wired.