Making a RTSP Server out of a Raspberry PI in 15 minutes or less

Recently, I was performing some video analytics against a new Reolink PoE camera.  Nice new camera, BUT it struggled with OpenCV, namely, I was getting the following type of errors:

[h264 @ 0xafb9ec0] left block unavailable for requested intra4x4 mode -1
[h264 @ 0xafb9ec0] error while decoding MB 0 28, bytestream 11378
[h264 @ 0xafb9500] error while decoding MB 38 19, bytestream -26
[h264 @ 0xafb9500] left block unavailable for requested intra4x4 mode -1
[h264 @ 0xafb9500] error while decoding MB 0 28, bytestream 694
[h264 @ 0xafb9500] error while decoding MB 15 22, bytestream -18
[h264 @ 0xafb9ec0] error while decoding MB 30 19, bytestream -10
[h264 @ 0xafb9500] error while decoding MB 48 19, bytestream -26
[h264 @ 0xafb9080] error while decoding MB 10 20, bytestream -10
[h264 @ 0xafb9a00] left block unavailable for requested intra4x4 mode -1
[h264 @ 0xafb9a00] error while decoding MB 0 24, bytestream 842
[h264 @ 0xafb9ec0] error while decoding MB 59 29, bytestream -20
[h264 @ 0xafb9ec0] left block unavailable for requested intra4x4 mode -1
[h264 @ 0xafb9ec0] error while decoding MB 0 26, bytestream 620
[h264 @ 0xafb9a00] error while decoding MB 42 23, bytestream -22
[h264 @ 0xafb9ec0] error while decoding MB 46 21, bytestream -32
[h264 @ 0xafb9080] left block unavailable for requested intra4x4 mode -1
[h264 @ 0xafb9080] error while decoding MB 0 20, bytestream 902
[h264 @ 0xafb9500] left block unavailable for requested intra4x4 mode -1
[h264 @ 0xafb9500] error while decoding MB 0 22, bytestream 608
[h264 @ 0xafb9500] error while decoding MB 38 19, bytestream -28

Because the processing I needed to do was sub second, I could not rely on the sporadic errors and as such had to find a different solution.  [Note, the RTSP server on Pi still produces some error, but no where near as many as the Reolink did.  Also, I did open a ticket with Reolink and they could not solve the issue.  :(]

I set out to see if I could easily convert a raspberry pi + camera to do the job.

While I could have used most any USB camera, I chose to use the Pi camera, just because I already had it (and no use for it).

Install Process:

  1. install Raspbian Stretch on the device (~6 minutes using Raspbian Lite)

2. log into the system and switch user to root

su root

3. update the system and install git and cmake

apt update && apt install git cmake

4. download the source for v412rtspserver

git clone https://github.com/mpromonet/v4l2rtspserver.git

5. make and install the code (~5 minutes)

cd v4l2rtspserver && cmake . && make && make install

6. add the following command to your /etc/rc.local

v4l2rtspserver /dev/video0 &

7. in VLC, open network stream to:  rtsp://{IPAddressOfYourPI}:8554/unicast

You should see something similar to below:

image

From a performance perspective, there is very little CPU or memory used, as shown below, meaning this could easily run on a PI Zero:

proc

Note, not all cameras support the H264, as discussed here: https://github.com/mpromonet/v4l2rtspserver/issues/88

 

 

14 thoughts on “Making a RTSP Server out of a Raspberry PI in 15 minutes or less

  1. If any of You have problem to install v4l2rtspserver only with command:
    pi:raspberry: sudo cmake . && make && make install
    Then become root:
    pi:raspberry: su
    enter password and then install that how I made it work for me gl 🙂

    Like

  2. I can’t seem to make this work. It really looks like it could be a solution I am looking for. After pasting in your commands when i do TOP the v4l2 server isn’t running. I also rebooted. What do I need to do ?

    Like

      1. Yes I have the V2 camera. I went with a fresh install and copied your procedures, but what I get is…NOTICE] /home/pi/v4l2rtspserver/src/main.cpp:599
        VIDIOC_STREAMOFF: Bad file descriptor
        VIDIOC_REQBUFS: Bad file descriptor
        Create V4L2 Source…/dev/video0

        When I run the top command I do not see any v4l2 server running. Am i missing something?
        I appreciate your help.

        Like

  3. Are you still able to assist ksaye? I’d really like to get this running. IS there an opportunity to download an image of an SD that works so I can look at it??

    Like

  4. Just an update, as I finally got back to this. It works! Thanks so much. I know with raspivid and such you can flip the video and etc..can you do that with this? Also cange bitrate and resolution? Thank you.

    Like

  5. Do you have any idea how to decrease the cache with the V4l2 server. The stream that I am receiving is quite delayed (upwards of 2 to 3 seconds) and I was hoping that decreasing a cache value would decrease the delay.

    Like

  6. Does your software use a Docker container?
    Can it be set up as a service to run automatically at startup – even when nobody is logged in?

    After a reboot it is not active for me. I have to log in and manually start at command line.

    Regards,
    Mike

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s