How to encode webcam to mp4 file?

jetson linux 36.3+ORIN NX
webcam is /dev/video0 , I would like to encode webcam to mp4 file.
I follow the below link, but don’t understand the “nvarguscamerasrc” .
https://docs.nvidia.com/jetson/archives/r36.3/DeveloperGuide/SD/Multimedia/AcceleratedGstreamer.html#video-encode-examples-using-gst-launch-1-0
gst-launch-1.0 nvarguscamerasrc !
‘video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,
format=(string)NV12, framerate=(fraction)30/1’ ! nvv4l2h264enc
maxperf-enable=1 bitrate=8000000 ! h264parse ! qtmux ! filesink
location=<filename_h264.mp4> -e

Below command can preview webcam
gst-launch-1.0 v4l2src device=“/dev/video0” !
“video/x-raw, width=640, height=480, format=(string)YUY2” !
xvimagesink -e

and the follow command fail
gst-launch-1.0 v4l2src device=“/dev/video0” !
‘video/x-raw, width=(int)640, height=(int)480,
format=(string)YUY2’ ! nvv4l2h264enc
maxperf-enable=1 bitrate=8000000 ! h264parse ! qtmux ! filesink
location=test_h264.mp4 -e
WARNING: erroneous pipeline: could not link v4l2src0 to nvv4l2h264enc0, nvv4l2h264enc0 can’t handle caps video/x-raw, width=(int)640, height=(int)480, format=(string)YUY2

Hello @627263202

Well, the nvarguscamersrc element only handles the memory:NVMM format while the webcam can only dequeue video/x-raw video format. That is why you can not capture using the nvarguscamersrc element by using the webcam.

On the other side with the following pipeline:

Please take care of using quotes. Please use single quotes ' or double quotes " and do not use . Perhaps it was just a typo when posting the pipeline, but I wanted to clarify.

To get the pipeline to work, you will need to convert the format by using the nvvidconv element, for example:

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw, width=(int)640, height=(int)480, format=(string)YUY2" ! nvvidconv ! nvv4l2h264enc maxperf-enable=1 bitrate=8000000 ! h264parse ! qtmux ! filesink location=test_h264.mp4 -e

Hope this helps!

Regards!
Eduardo Salazar
Embedded SW Engineer at RidgeRun

Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com/
Website: www.ridgerun.com

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