# USB Camera MJPEG to h265

**URL:** <https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178>\
**Category:** Jetson Nano\
**Created:** [September 23, 2019, 9:20pm UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178 "2019-09-23T21:20:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mckelvaney](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mckelvaney](https://forums.developer.nvidia.com/u/mckelvaney)\
**Post date:** [September 23, 2019, 9:20pm UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/1 "2019-09-23T21:20:31Z")

</div>

I am using the Jetson Nano to capture video from a UVC camera using the v4l2src plugin, but when using the pipeline below, the video is only around 700k and does not contain any video. I have read the `ACCELERATED GSTREAMER USER GUIDE`, but it does not contain much information for sending jpeg streams to omxh265enc.

Any advice would be greatly received.

```auto
gst-launch-1.0 -vvv v4l2src device=/dev/video0 do-timestamp=true ! image/jpeg, width=3264, height=2448, framerate=15/1 ! jpegparse ! nvjpegdec ! 'video/x-raw' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=I420' ! omxh265enc ! matroskamux ! filesink location=h265_example.mkv

```

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [September 24, 2019, 2:29am UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/2 "2019-09-24T02:29:57Z")

</div>

Hi,  
You may break down jpeg decoding and h265 encoding. The following pipeline can check if jpeg decoding is working:

```auto
gst-launch-1.0 -vvv v4l2src device=/dev/video0 do-timestamp=true ! image/jpeg, width=3264, height=2448, framerate=15/1 ! jpegparse ! nvjpegdec ! 'video/x-raw' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=I420,width=1920,height=1080' ! nvoverlaysink

```

---

<div class="post-metadata">

**Author:** ![mckelvaney](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mckelvaney](https://forums.developer.nvidia.com/u/mckelvaney)\
**Post date:** [September 24, 2019, 8:47am UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/3 "2019-09-24T08:47:49Z")

</div>

When running the provided command the display shows a single frame and then the terminal shows the following messages:

```auto
Additional debug info:
gstbasesink.c(2902): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstNvOverlaySink-nvoverlaysink:nvoverlaysink-nvoverlaysink0:
There may be a timestamping problem, or this computer is too slow.
WARNING: from element /GstPipeline:pipeline0/GstNvOverlaySink-nvoverlaysink:nvoverlaysink-nvoverlaysink0: A lot of buffers are being dropped.
Additional debug info:
gstbasesink.c(2902): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstNvOverlaySink-nvoverlaysink:nvoverlaysink-nvoverlaysink0:
There may be a timestamping problem, or this computer is too slow.

```

The hardware accelerated jpeg decoding cannot handle this amount of data? This seems surprising.

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 24, 2019, 9:43am UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/4 "2019-09-24T09:43:47Z")

</div>

Assuming you have no CSI camera connected, and /dev/video0 appears a few seconds after you plug your UVC camera in, check which formats your camera driver provides with:

```auto
v4l2-ctl -d /dev/video0 --list-formats-ext

```

(v4l2-ctl is available from apt package v4l-utils)

Get a supported MJPG mode, for example if seeing this:

```auto
Index : 1
	Type : Video Capture
	Pixel Format: <b>'MJPG'</b> (compressed)
	Name : Motion-JPEG
		Size: Discrete <b>640x480</b>
			Interval: Discrete 0.008s (120.000 fps)
			Interval: Discrete 0.011s (90.000 fps)
			Interval: Discrete 0.017s (60.000 fps)
			Interval: Discrete 0.033s (30.000 fps)
			Interval: Discrete 0.042s (24.000 fps)
			Interval: Discrete 0.050s (20.000 fps)
			Interval: Discrete 0.067s (15.000 fps)
			Interval: Discrete 0.100s (10.000 fps)
			Interval: Discrete 0.133s (7.500 fps)
			Interval: Discrete 0.200s <b>(5.000 fps)</b>

```

I’d suggest to first try with low resolution and framerate.

You may then try this pipeline:

```auto
gst-launch-1.0 -v v4l2src device=/dev/video0 ! 'image/jpeg, width=640, height=480, framerate=5/1, format=MJPG' ! jpegdec ! xvimagesink

```

If this doesn’t work, you may post the output of these commands for better advice, and may also try to use io-mode(=1 or 2) option of v4l2src plugin.

---

<div class="post-metadata">

**Author:** ![johlim](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@johlim](https://forums.developer.nvidia.com/u/johlim)\
**Post date:** [September 30, 2019, 9:48am UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/5 "2019-09-30T09:48:01Z")

</div>

hi everyone

I want to stream h264 with uvc camera(mjpg)

so i trying like this  
"  
nvidia@nvidia:~/source/gst-rtsp-server-1.14.5/examples$ ./test-launch “v4l2src device=/dev/video0 do-timestamp=true ! image/jpeg, width=640, height=480, framerate=30/1 ! jpegparse ! nvjpegdec ! ‘video/x-raw’ ! nvvidconv ! ‘video/x-raw(memory:NVMM),format=I420,width=640,height=480’ ! omxh265enc ! rtph265pay name=pay0 pt=96”  
stream ready at rtsp://127.0.0.1:8554/test  
No protocol specified  
nvbuf\_utils: Could not get EGL display connection

(test-launch:28114): GStreamer-CRITICAL \*\*: 18:43:18.220: gst\_element\_make\_from\_uri: assertion ‘gst\_uri\_is\_valid (uri)’ failed

(test-launch:28114): GStreamer-CRITICAL \*\*: 18:43:18.222: gst\_element\_make\_from\_uri: assertion ‘gst\_uri\_is\_valid (uri)’ failed

(test-launch:28114): GStreamer-CRITICAL \*\*: 18:43:18.228: gst\_element\_link\_pads\_filtered: assertion ‘GST\_IS\_BIN (parent)’ failed

(test-launch:28114): GStreamer-CRITICAL \*\*: 18:43:38.248: gst\_element\_make\_from\_uri: assertion ‘gst\_uri\_is\_valid (uri)’ failed

(test-launch:28114): GStreamer-CRITICAL \*\*: 18:43:38.249: gst\_element\_make\_from\_uri: assertion ‘gst\_uri\_is\_valid (uri)’ failed

(test-launch:28114): GStreamer-CRITICAL \*\*: 18:43:38.249: gst\_element\_link\_pads\_filtered: assertion ‘GST\_IS\_BIN (parent)’ failed

"

* * *

nvidia@nvidia:~/source/gst-rtsp-server-1.14.5/examples$ v4l2-ctl -d /dev/video0 --list-formats-ext  
ioctl: VIDIOC\_ENUM\_FMT  
Index : 0  
Type : Video Capture  
Pixel Format: ‘YUYV’  
Name : YUYV 4:2:2  
Size: Discrete 2592x1944  
Interval: Discrete 0.133s (7.500 fps)  
Interval: Discrete 0.267s (3.750 fps)  
Size: Discrete 1920x1080  
Interval: Discrete 0.067s (15.000 fps)  
Interval: Discrete 0.133s (7.500 fps)  
Size: Discrete 1280x960  
Interval: Discrete 0.033s (30.000 fps)  
Interval: Discrete 0.067s (15.000 fps)  
Size: Discrete 1280x720  
Interval: Discrete 0.033s (30.000 fps)  
Interval: Discrete 0.067s (15.000 fps)  
Size: Discrete 640x480  
Interval: Discrete 0.008s (120.000 fps)  
Interval: Discrete 0.011s (90.000 fps)  
Interval: Discrete 0.017s (60.000 fps)  
Interval: Discrete 0.033s (30.000 fps)  
Size: Discrete 320x240  
Interval: Discrete 0.008s (120.000 fps)  
Interval: Discrete 0.011s (90.000 fps)  
Interval: Discrete 0.017s (60.000 fps)  
Interval: Discrete 0.033s (30.000 fps)

```
    Index : 1
    Type : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name : Motion-JPEG
            Size: Discrete 1920x1080
                    Interval: Discrete 0.033s (30.000 fps)
                    Interval: Discrete 0.067s (15.000 fps)
            Size: Discrete 1280x720
                    Interval: Discrete 0.022s (45.000 fps)
                    Interval: Discrete 0.033s (30.000 fps)
                    Interval: Discrete 0.067s (15.000 fps)
            Size: Discrete 640x480
                    Interval: Discrete 0.033s (30.000 fps)
                    Interval: Discrete 0.067s (15.000 fps)

```

What should it review ?

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [September 30, 2019, 6:48pm UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/6 "2019-09-30T18:48:06Z")

</div>

You may first try to access camera before further encoding/streaming.

For YUYV422, you may try video format YUY2:

```auto
gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, framerate=30/1, format=YUY2 ! videoconvert ! xvimagesink

```

For MJPG, you would try jpeg format MJPG:

```auto
gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegdec ! xvimagesink
#if it fails try to add jpegparse
gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegparse ! jpegdec ! xvimagesink

```

Does one work ?

If it works, you would try to encode and write into file for checking that encoding works:

```auto
gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, framerate=30/1, format=YUY2 ! nvvidconv ! 'video/x-raw(memory:NVMM), format=NV12' ! omxh265enc ! matroskamux ! filesink location=test_YUY2_H265enc.mkv

```

```auto
gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegdec ! nvvidconv ! 'video/x-raw(memory:NVMM), format=NV12' ! omxh265enc ! matroskamux ! filesink location=test_MJPG_H265enc.mkv

```

If it’s fine, you would try to stream with test-launch:

```auto
test-launch "v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, framerate=30/1, format=YUY2 ! nvvidconv ! video/x-raw(memory:NVMM), format=NV12 ! omxh265enc ! rtph265pay name=pay0 pt=96 config-interval=1 "

```

```auto
test-launch "v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegdec ! nvvidconv ! video/x-raw(memory:NVMM), format=NV12 ! omxh265enc ! rtph265pay name=pay0 pt=96 config-interval=1 "

```

---

<div class="post-metadata">

**Author:** ![johlim](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@johlim](https://forums.developer.nvidia.com/u/johlim)\
**Post date:** [October 1, 2019, 6:04am UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/7 "2019-10-01T06:04:37Z")

</div>

> [@](#):
>
> You may first try to access camera before further encoding/streaming.
> 
> For YUYV422, you may try video format YUY2:
> 
> ```auto
> gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, framerate=30/1, format=YUY2 ! videoconvert ! xvimagesink
> 
> ```
> 
> For MJPG, you would try jpeg format MJPG:
> 
> ```auto
> gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegdec ! xvimagesink
> #if it fails try to add jpegparse
> gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegparse ! jpegdec ! xvimagesink
> 
> ```
> 
> Does one work ?
> 
> If it works, you would try to encode and write into file for checking that encoding works:
> 
> ```auto
> gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, framerate=30/1, format=YUY2 ! nvvidconv ! 'video/x-raw(memory:NVMM), format=NV12' ! omxh265enc ! matroskamux ! filesink location=test_YUY2_H265enc.mkv
> 
> ```
> 
> ```auto
> gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegdec ! nvvidconv ! 'video/x-raw(memory:NVMM), format=NV12' ! omxh265enc ! matroskamux ! filesink location=test_MJPG_H265enc.mkv
> 
> ```
> 
> If it’s fine, you would try to stream with test-launch:
> 
> ```auto
> test-launch "v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, framerate=30/1, format=YUY2 ! nvvidconv ! video/x-raw(memory:NVMM), format=NV12 ! omxh265enc ! rtph265pay name=pay0 pt=96 config-interval=1 "
> 
> ```
> 
> ```auto
> test-launch "v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1, format=MJPG ! jpegdec ! nvvidconv ! video/x-raw(memory:NVMM), format=NV12 ! omxh265enc ! rtph265pay name=pay0 pt=96 config-interval=1 "
> 
> ```

1.2.3.4 steps all command works !

Thanks Honey\_Patouceul

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 18, 2021, 5:45pm UTC](https://forums.developer.nvidia.com/t/usb-camera-mjpeg-to-h265/82178/8 "2021-10-18T17:45:26Z")

</div>


