encoding a usb webcam video using gstreamer with small video size(mb)

I need to record a video using my usb webcam in jetson nano. I found gstreamer with h264 encoding for lower the cpu percentage. But i am new to gstreamer so i had errors when running some gstreamer command. So, can any one tell me how to do that and give me proper command for gstreamer using gpu with encoding .

My strip camera working fine using the below command:

gst-launch-1.0 nvarguscamerasrc num-buffers=200 ! 'video/x-raw(memory:NVMM),width=1920, height=1080, framerate=30/1, format=NV12' ! omxh264enc ! qtmux ! filesink location=test.mp4 -e

When i using my usb camera with the below command, command exit with warning message :

gst-launch-1.0 -v v4l2src device=/dev/video2 ! 'video/x-raw,width=640, height=480, framerate=30/1, format=YUY2' ! omxh264enc ! qtmux ! filesink location=test.mp4 -e

WARNING: erroneous pipeline: could not link v4l2src0 to omxh264enc-omxh264enc0, omxh264enc-omxh264enc0 can’t handle caps video/x-raw, width=(int)640, height=(int)480, framerate=(fraction)30/1, format=(string)YUY2

Camera spec:

  • camera name: 3.0 USB Camera(Gearway Electronics (Dong Guan) Co., Ltd)
  • pixel_format: YUYV422 (30fps), MJPG (compressed) (60fps)
  • driver_support: uvcvide0
  • resolution_format: 640x480 , 1920x1080
  • Camera details from v4l2:

    v4l2-ctl --info -d /dev/video2 --list-formats

    Driver Info (not using libv4l2):

    Driver name : uvcvideo

    Card type : 3.0 USB Camera

    Bus info : usb-70090000.xusb-1.2

    Driver version: 4.9.140

    Capabilities : 0x84200001

    Video Capture
    
    Streaming
    
    Extended Pix Format
    

    Device Capabilities

    Device Caps : 0x04200001

    Video Capture
    
    Streaming
    
    Extended Pix Format
    

    ioctl: VIDIOC_ENUM_FMT

    Index : 0

    Type : Video Capture

    Pixel Format: ‘MJPG’ (compressed)

    Name : Motion-JPEG

    Index : 1

    Type : Video Capture

    Pixel Format: ‘YUYV’

    Name : YUYV 4:2:2

    If you look at omxh264enc supported input formats (SINK), you’ll see it only supports I420 or NV12:

    gst-inspect-1.0 omxh264enc
    ...
    Pad Templates:
      SINK template: 'sink'
        Availability: Always
        Capabilities:
          video/x-raw(memory:NVMM)
                     format: { I420, NV12 }
                      width: [ 1, 2147483647 ]
                     height: [ 1, 2147483647 ]
                  framerate: [ 0/1, 2147483647/1 ]
          video/x-raw
                     format: { I420, NV12 }
                      width: [ 1, 2147483647 ]
                     height: [ 1, 2147483647 ]
                  framerate: [ 0/1, 2147483647/1 ]
    

    Since your USB camera doesn’t provide any of these, you have to insert a conversion plugin. Fortunately, HW accelerated conversion is possible with nvvidconv, supporting YUY2 as input and providing I420 or NV12 as output (SRC). nvvidconv expects at least its input or output to be in NVMM (contiguous) memory, and that will be better for performance and omxh264enc supports it as well.

    So you would change your pipeline to:

    gst-launch-1.0 -v v4l2src device=/dev/video2 ! 'video/x-raw,width=640, height=480, framerate=30/1, format=YUY2' ! <b>nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12'</b> ! omxh264enc ! qtmux ! filesink location=test.mp4 -e
    

    For a camera of “pixel_format: YUYV422 (30fps), MJPG (compressed) (60fps)” spec, what would be the right encoder to use?

    @n.rajasiddharthan

    If your camera provides YUYV422, the pipeline above should work.
    You may have to adjust resolution and framerate from one listed by:

    v4l2-ctl -d /dev/video1 --list-formats-ext
    

    (assuming your camera has video node /dev/video1, you would adjust for your case).

    Did you got the solution for this issue ?

    Further replied in this topic.