How to capture an h264 camera, convert it to RAW format, and stream it to a virtual camera device using gstreamer

Please tell me how to capture an h264 camera, convert it to RAW format, and stream it to a virtual camera device using gstreamer.

Environment:

  • Jetpack: 4.6.3
  • ubuntu: 18.04

I use below usb camera(/dev/video1).

user@user-desktop:~$ v4l2-ctl -d /dev/video1 --all
Driver Info (not using libv4l2):
	Driver name   : uvcvideo
	Card type     : H264 USB Camera
	Bus info      : usb-3610000.xhci-2.3.2
	Driver version: 4.9.255
	Capabilities  : 0x84200001
		Video Capture
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps   : 0x04200001
		Video Capture
		Streaming
		Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
	Width/Height      : 1920/1080
	Pixel Format      : 'H264'
	Field             : None
	Bytes per Line    : 3840
	Size Image        : 0
	Colorspace        : sRGB
	Transfer Function : Default (maps to sRGB)
	YCbCr/HSV Encoding: Default (maps to ITU-R 601)
	Quantization      : Default (maps to Full Range)
	Flags             :
Crop Capability Video Capture:
	Bounds      : Left 0, Top 0, Width 1920, Height 1080
	Default     : Left 0, Top 0, Width 1920, Height 1080
	Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 1920, Height 1080
Selection: crop_bounds, Left 0, Top 0, Width 1920, Height 1080
Streaming Parameters Video Capture:
	Capabilities     : timeperframe
	Frames per second: invalid (1/0)
	Read buffers     : 0
                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=64 step=1 default=32 value=32
                     saturation 0x00980902 (int)    : min=0 max=128 step=1 default=56 value=56
                            hue 0x00980903 (int)    : min=-40 max=40 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=72 max=500 step=1 default=100 value=100
                           gain 0x00980913 (int)    : min=0 max=100 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=6 step=1 default=3 value=3
         backlight_compensation 0x0098091c (int)    : min=0 max=2 step=1 default=1 value=1
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
              exposure_absolute 0x009a0902 (int)    : min=1 max=5000 step=1 default=156 value=156 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=0

I tried following command, but I have error.
/dev/video1 means above usb camera. /dev/video40 means virtual camera device.

user@user-desktop:~$ gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-h264,width=1920,height=1080,framerate=15/1 ! h264parse ! video/x-h264,stream-format=byte-stream,alignment=au ! nvv4l2decoder ! nvvidconv ! video/x-raw,format=NV12 ! v4l2sink device=/dev/video40 sync=false
Setting pipeline to PAUSED ...
Failed to open /dev/video4: No such file or directory
Failed to open /dev/video5: No such file or directory
Failed to open /dev/video6: No such file or directory
Failed to open /dev/video7: No such file or directory
Failed to open /dev/video8: No such file or directory
Failed to open /dev/video9: No such file or directory
Failed to open /dev/video10: No such file or directory
Failed to open /dev/video11: No such file or directory
Failed to open /dev/video12: No such file or directory
Failed to open /dev/video13: No such file or directory
Failed to open /dev/video14: No such file or directory
Failed to open /dev/video15: No such file or directory
Failed to open /dev/video16: No such file or directory
Failed to open /dev/video17: No such file or directory
Failed to open /dev/video18: No such file or directory
Failed to open /dev/video19: No such file or directory
Failed to open /dev/video20: No such file or directory
Failed to open /dev/video21: No such file or directory
Failed to open /dev/video22: No such file or directory
Failed to open /dev/video23: No such file or directory
Failed to open /dev/video24: No such file or directory
Failed to open /dev/video25: No such file or directory
Failed to open /dev/video26: No such file or directory
Failed to open /dev/video27: No such file or directory
Failed to open /dev/video28: No such file or directory
Failed to open /dev/video29: No such file or directory
Failed to open /dev/video30: No such file or directory
Failed to open /dev/video31: No such file or directory
Failed to open /dev/video32: No such file or directory
Failed to open /dev/video33: No such file or directory
Failed to open /dev/video34: No such file or directory
Failed to open /dev/video35: No such file or directory
Failed to open /dev/video36: No such file or directory
Failed to open /dev/video37: No such file or directory
Failed to open /dev/video38: No such file or directory
Failed to open /dev/video39: No such file or directory
Opening in BLOCKING MODE
ArgusV4L2_Open failed: No such file or directory
Opening in BLOCKING MODE
Opening in BLOCKING MODE
Pipeline is live and does not need PREROLL ...

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.979: gst_mini_object_copy: assertion 'mini_object != NULL' failed
Setting pipeline to PLAYING ...

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.980: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed
New clock: GstSystemClock

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.980: gst_structure_copy: assertion 'structure != NULL' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.981: gst_caps_append_structure_full: assertion 'GST_IS_CAPS (caps)' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.982: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.982: gst_structure_copy: assertion 'structure != NULL' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.983: gst_caps_append_structure_full: assertion 'GST_IS_CAPS (caps)' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.983: gst_mini_object_unref: assertion 'mini_object != NULL' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.983: gst_mini_object_ref: assertion 'mini_object != NULL' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.984: gst_caps_intersect_full: assertion 'GST_IS_CAPS (caps1)' failed

(gst-launch-1.0:31627): GStreamer-CRITICAL **: 16:19:25.984: gst_mini_object_unref: assertion 'mini_object != NULL' failed
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261

hello hiroki.iwasaki.j6c,

why you need raw data by using an USB Camera?

Thank you.

This is because our component design is intended to stream to a raw camera.

hello hiroki.iwasaki.j6c,

this can’t be done. or, let’s say it’s meaningless by convert the YUV content (USB cam output) as bayer Raw.
please try with bayer sensors, to dump the raw files by v4l standard controls.
you may see-also Applications Using V4L2 IOCTL Directly.

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