mpromonet / v4l2rtspserver

RTSP Server for V4L2 device capture supporting HEVC/H264/JPEG/VP8/VP9
The Unlicense
1.83k stars 423 forks source link

Jetson Nano, how to convert MJPG to H264 -- where is v4l2compress_h264? #226

Closed ksaye closed 3 years ago

ksaye commented 3 years ago

I have a RTSP client that only supports H264, yet some of my cameras only seem to support MJPG, as shown below:

root@jetson:~# v4l2rtspserver
log level:500

[NOTICE] /home/ksaye/v4l2rtspserver/main.cpp:385
        Version: 0.2.1-14-g22a9577 live555 version:2021.01.20
[NOTICE] /home/ksaye/v4l2rtspserver/main.cpp:426
        Create V4L2 Source.../dev/video0
[NOTICE] /home/ksaye/v4l2rtspserver/v4l2wrapper/src/V4l2Device.cpp:133
        driver:uvcvideo capabilities:84200001 mandatory:4000001
[NOTICE] /home/ksaye/v4l2rtspserver/v4l2wrapper/src/V4l2Device.cpp:136
        /dev/video0 support capture
[NOTICE] /home/ksaye/v4l2rtspserver/v4l2wrapper/src/V4l2Device.cpp:139
        /dev/video0 support streaming
[ERROR] /home/ksaye/v4l2rtspserver/v4l2wrapper/src/V4l2Device.cpp:202
        Cannot set pixelformat to:H264 format is:MJPG

I see the documentation stating:

/dev/video0 (camera device)-> v4l2compress_h264 -> /dev/video10 (v4l2loopback device) -> v4l2rtspserver

Yet I can't find the 'v4l2compress_h264' command. On Ubuntu 18.04.5 LTS on the Jetson Nano, after running:

apt install v4l2loopback-utils
snap install v4l2loopback

I only see:

root@jetson:~# ls -all /usr/bin/v4*
-rwxr-xr-x 1 root root 289384 Feb 10  2018 /usr/bin/v4l2-compliance
-rwxr-xr-x 1 root root 312872 Feb 10  2018 /usr/bin/v4l2-ctl
-rwxr-xr-x 1 root root   4216 Dec  2  2016 /usr/bin/v4l2loopback-ctl
-rwxr-xr-x 1 root root  14336 Feb 10  2018 /usr/bin/v4l2-sysfs-path
root@jetson:~# ls -all /snap/bin/v4*
lrwxrwxrwx 1 root root 13 Jan 21 16:14 /snap/bin/v4l2tools.v4l2compress -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jan 21 16:14 /snap/bin/v4l2tools.v4l2copy -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jan 21 16:14 /snap/bin/v4l2tools.v4l2source-yuv -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jan 21 16:14 /snap/bin/v4l2tools.v4l2uncompress-jpeg -> /usr/bin/snap

Any suggestion where I can find: v4l2compress_h264?

ksaye commented 3 years ago

Never mind, found it.

for others, here is what I run on my Jetson Nano:

# install the needed items
apt install v4l2loopback-utils
snap install v4l2loopback

# note, I have a /dev/video0 and /dev/video1 I want to convert to h264
modprobe v4l2loopback video_nr=10,11
v4l2tools.v4l2compress -f H264 /dev/video0 /dev/video10 & 
v4l2tools.v4l2compress -f H264 /dev/video1 /dev/video11 &
v4l2rtspserver /dev/video10 /dev/video11 &

It take the format from:

MJPG

To:

n264

As you can see below, it really does consume some CPU:

CPU