Jetson orin nano camera to h264 encoded mp4

I’m trying to h264 encode a camera stream and record an mp4. I’ve tried a few different things. First all in gstreamer:

gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM),width=1920, height=1080, framerate=10/1, format=NV12’ ! nvvidconv ! x264enc tune=zerolatency speed-preset=ultrafast ! h264parse ! mp4mux ! filesink location=video.mp4

This produces the file and it clearly has data in it:

du -sh video.mp4
2.3M video.mp4

However, nothing is able to play it.

I also tried recording raw h264 and creating an mp4 with mmpeg:

gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM),width=1920, height=1080, framerate=10/1, format=NV12’ ! nvvidconv ! x264enc ! h264parse ! filesink location=video.h264

ffmpeg -i video.h264 video.mp4

However, ffmpeg fails with the following:

[h264 @ 0x5e797aab1380] Format h264 detected only with low score of 1, misdetection possible!
[h264 @ 0x5e797aab2140] SEI type 111 size 77 truncated at 75
[h264 @ 0x5e797aab2140] missing picture in access unit with size 1982911
[extract_extradata @ 0x5e797aac9fc0] Invalid NAL unit 0, skipping.
[extract_extradata @ 0x5e797aac9fc0] No start code is found.
[in#0/h264 @ 0x5e797aab1280] could not find codec parameters
Input #0, h264, from ‘video.h264’:
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264, none, 25 fps, 1200k tbn
File ‘video.mp4’ already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0#0:0 (h264 (native) → h264 (libx264))
Press [q] to stop, [?] for help
[h264 @ 0x5e797aab3c00] Invalid NAL unit 0, skipping.
[h264 @ 0x5e797aab3c00] No start code is found.
[h264 @ 0x5e797aab3c00] Error splitting the input into NAL units.
[vist#0:0/h264 @ 0x5e797aab5f40] Decoding error: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Error while filtering: Invalid data found when processing input
[vist#0:0/h264 @ 0x5e797aab5f40] Decode error rate 1 exceeds maximum 0.666667
[out#0/mp4 @ 0x5e797aaca040] Nothing was written into output file, because at least one of its streams received no packets.
frame= 0 fps=0.0 q=0.0 Lsize= 0kB time=N/A bitrate=N/A speed=N/A
Conversion failed!

It looks like this might be a problem with key frames or something similar. Any ideas for how I can get this to work?

Hello @nick.j.meyer,

Could you please try the following pipe:

gst-launch-1.0 -e nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1920, height=1080, format=NV12, framerate=30/1' ! nvv4l2h264enc bitrate=8000000 ! h264parse ! qtmux ! filesink location=video.mp4

We captured on a Jetson Nano, and were able to reproduce the video with VLC in our host Ubuntu machine.

Please let us know how it goes.

Also, please do not hesitate to reach out if you require further assistance, we would be glad to help.

regards,
Andrew

That worked. Thanks!

1 Like

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