mpromonet
Posts: 13
Joined: Sun Sep 02, 2012 9:04 am

RTSP Streaming H264

Sun Nov 10, 2013 4:42 pm

Hi,

Searching how to stream the CSI camera board acquisition, I found first some solution involving raspivid piped to VLC, and next solutions involving a V4L2 driver for raspi-cam (http://www.linux-projects.org/uv4l/) and use VLC to read from V4L2 driver and make RTSP streaming.

The main drawback is that this V4L2 driver seems closed-source, but it open the camera stream to be accessed by many more applications.

VLC is a very powerfull application, but it is difficult to deal with different caching buffers in order to reduce the latency, so I developped a simple application that capture H264 using the V4L2 API and feed an RTSP streamer.
I post the code on github https://github.com/mpromonet/h264_v4l2_rtspserver

To register the Video4Linux driver :
[email protected] ~ $sudo uv4l --driver raspicam --auto-video_nr --sched-rr --encoding=h264
...
<notice> [core] Registering device node /dev/video0
To start the RTSP Server :
[email protected] ~ $./h264_v4l2_rtspserver /dev/video0
Create V4L2 Source.../dev/video0
driver:raspicam capabilities;5000001
/dev/video0 support read i/o
/dev/video0 support streaming i/o
fps :1/25 nbBuffer:5
Play this stream using the URL "rtsp://192.168.0.18:8554/unicast"
To receive video stream :
server ~ $vlc rtsp://192.168.0.18:8554/unicast
or
server ~ $ffplay rtsp://192.168.0.18:8554/unicast
Tests show about 700~800ms of latency for 640x480, about 1000~1100 ms for 800x600.
Not so good but better than the 3~4 seconds of some solutions.

Michel.

Since this post an official V4L2 drive for raspi-cam is available, then a video device can be creating using bcm2835-v4l2 module instead of uv4l.
Last edited by mpromonet on Mon Jan 02, 2017 3:43 pm, edited 2 times in total.

pazu_86
Posts: 7
Joined: Thu Jun 12, 2014 10:38 pm

Re: RTSP Streaming H264

Fri Jun 13, 2014 11:18 pm

Hi there,

I just wanted to pass on my thanks, your RTSP streamer is exactly what I was chasing after struggling with VLC.

I'm streaming at [email protected] happily so thank you.

One quick question, is there a 'correct' way to end the stream? If I abort the script (Ctrl+C) it doesn't release the port so I can't easily start it again without changing ports, it does seem to release them after a while though.

Cheers,
Matt

mpromonet
Posts: 13
Joined: Sun Sep 02, 2012 9:04 am

Re: RTSP Streaming H264

Thu Jun 19, 2014 5:40 pm

Hi Matt,

It is possible to avoid this activating the SO_REUSEADDR socket option (you need to build live555 with the option ALLOW_RTSP_SERVER_PORT_REUSE that is not set by default).

Cheers,

Michel.

Redi
Posts: 6
Joined: Wed Aug 21, 2013 1:46 pm

Re: RTSP Streaming H264

Sat Aug 02, 2014 8:33 pm

This sounds really interesting. :D
Just three fast questions:
1) Can it handle FullHD?
2) Will it be included in repos in the future?
3) Does this really mean that I can setup ZoneMinder to record from the RPi stream?

Thank you very much!

mpromonet
Posts: 13
Joined: Sun Sep 02, 2012 9:04 am

Re: RTSP Streaming H264

Thu Aug 07, 2014 9:26 pm

Hi Redi,

It's quite simple to buid it, there is just a few source file, but it could be interesting to see how to setup a repo.
It seems to handles 1080i 30fps, by now it use the read V4L2 api, an improvement could be to support the mmap api.
I don't know Zoneminder, it's seems nice, I will look about it. As it seems to support RTSP, it should be ok.

Regards,

Michel.

damniel
Posts: 1
Joined: Wed Apr 16, 2014 2:57 pm

Re: RTSP Streaming H264

Tue Feb 24, 2015 12:20 am

Hi:

It's a great project, it has been very useful. There is only one thing missed that I need. Is there a way to keep a constant bitrate?

mpromonet
Posts: 13
Joined: Sun Sep 02, 2012 9:04 am

Re: RTSP Streaming H264

Sat Feb 28, 2015 12:05 pm

Hi damniel,

The encoder bitrate is not set by the application h264_v4l2_rtspserver. I did not investigate too mush, but I am not sure a standard way exists to set the encoder parameters.

However you can configure it :
* if you are using uv4l driver setting the --bitrate argument (see documentation http://www.linux-projects.org/modules/s ... e&artid=15)
* if you are using the official v4l2 driver using v4l2-ctl tool

Code: Select all

v4l2-ctl -c video_bitrate=25000000
In order to control a V4L2 device you can try this project https://github.com/mpromonet/v4l2web that expose V4L2 controls through a web server.

Regards,

Michel.

Tooj
Posts: 1
Joined: Thu Jun 04, 2015 4:00 am

Re: RTSP Streaming H264

Thu Jun 04, 2015 4:05 am

Hello.

I am beginner in raspberry pi. I using raspberry pi b+ and logictech webcam.
Where is my start point? I need a first guide about transmit streaming from raspberry pi between another Computer.

Thank you.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20930
Joined: Sat Jul 30, 2011 7:41 pm

Re: RTSP Streaming H264

Thu Jun 04, 2015 8:13 am

Tooj wrote:Hello.

I am beginner in raspberry pi. I using raspberry pi b+ and logictech webcam.
Where is my start point? I need a first guide about transmit streaming from raspberry pi between another Computer.

Thank you.
This part of the forum is for the Raspi camera board - please post in the beginners or general section for webcam help.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

roxane_11
Posts: 2
Joined: Sat Dec 31, 2016 5:32 am

Re: RTSP Streaming H264

Sun Jan 01, 2017 7:27 am

The steps to build project is not very clear. It would be great if you can provide them a bit more clearly on github site.

pootle
Posts: 282
Joined: Wed Sep 04, 2013 10:20 am
Location: Staffordshire
Contact: Website

Re: RTSP Streaming H264

Sun Jan 01, 2017 5:37 pm

In the meantime UV4L makes this much easier to set up - see http://www.linux-projects.org/uv4l/installation/.

I'm running 720P at 5 fps from a pi zero with a raspberry pi camera V2 just now - it uses < 10% cpu most of the time.

You need to explicitly ask for H264 or change the defaults (it defaults to mjpeg)

mpromonet
Posts: 13
Joined: Sun Sep 02, 2012 9:04 am

Re: RTSP Streaming H264

Mon Jan 02, 2017 3:27 pm

pootle wrote:In the meantime UV4L makes this much easier to set up - see http://www.linux-projects.org/uv4l/installation/.

I'm running 720P at 5 fps from a pi zero with a raspberry pi camera V2 just now - it uses < 10% cpu most of the time.

You need to explicitly ask for H264 or change the defaults (it defaults to mjpeg)
Hi pootle,

You are right uv4l is a nice tool (especially the webrtc feature), however it is closed source and doesn't provide an RTSP server.

Best Regards,
Michel.

mpromonet
Posts: 13
Joined: Sun Sep 02, 2012 9:04 am

Re: RTSP Streaming H264

Mon Jan 02, 2017 3:30 pm

roxane_11 wrote:The steps to build project is not very clear. It would be great if you can provide them a bit more clearly on github site.
Hi Roxane_11,
Maybe descriprion from github of different build scenarii (install, package, building live555) is confusing, for a simple build you just need to run :

Code: Select all

cmake . && make
If you would like to install it you need a additionnal

Code: Select all

sudo make install
Best Regards,
Michel.

Gassel
Posts: 1
Joined: Wed Sep 20, 2017 7:45 pm

Re: RTSP Streaming H264

Wed Sep 20, 2017 8:08 pm

Hi,

I'm sort of a newbie and lost.

What am I trying to achieve:
- I have a Dahua ip-cam system with a nvr; this server produces rtsp video streams (h.264), e.g. rtsp://user:[email protected]:554/cam/realmonitor?channel=1&subtype=0
- I want a small, cheap solution to view these streams on another tv (than the one attached to the nvr).

What have I tried:
1. After searching the web, I installed https://doc.kerberos.io/2.0/installation/Raspbian machinery and web, but had multiple errors and was not able get the streams to work.
2. Next, I rolled back to Raspbian Jessy and installed uv4l and tried several of the http://www.linux-projects.org/uv4l/tutorials/. No luck either.

Now what?
I've been struggling for several days now. This shouldn't be so hard to accomplish, should it? I would really appreciate some tips and tricks. Thanks in advance.

TheWaterbug
Posts: 73
Joined: Fri Feb 05, 2016 12:35 am
Location: Los Angeles, CA, USA, Earth

Re: RTSP Streaming H264

Mon Feb 26, 2018 11:11 pm

Hi! I'm running the PHP/Bootstrap Web Interface for the Pi Camera project, which uses this RTSP server project, to run my Swarm Trap Camera.

For some reason the h.264 stream dies from time to time. Sometimes it will run for (literally) days, and sometimes it will die after an hour or less. I've made no changes to the setup that I can correlate with the variability in lifetime; it appears somewhat random.

So I put a watchdog timer on it, and when it dies, sudo systemctl status RTSP-Server.service returns:

Code: Select all

v4l2rtspserver[1071]: 2018-02-26 12:19:29,007 [NOTICE] - /home/pi/v4l2rtspserver/src/V4l2DeviceSource.cpp:131
v4l2rtspserver[1071]: V4L2DeviceSource::doStopGettingFrames
v4l2rtspserver[1071]: 2018-02-26 14:06:38,244 [NOTICE] - /home/pi/v4l2rtspserver/src/V4l2DeviceSource.cpp:131
v4l2rtspserver[1071]: V4L2DeviceSource::doStopGettingFrames
v4l2rtspserver[1071]: 2018-02-26 14:06:38,249 [NOTICE] - /home/pi/v4l2rtspserver/src/V4l2DeviceSource.cpp:131
v4l2rtspserver[1071]: V4L2DeviceSource::doStopGettingFrames
v4l2rtspserver[1071]: 2018-02-26 14:07:48,310 [NOTICE] - /home/pi/v4l2rtspserver/src/V4l2DeviceSource.cpp:131
v4l2rtspserver[1071]: V4L2DeviceSource::doStopGettingFrames
v4l2rtspserver[1071]: 2018-02-26 14:07:48,315 [NOTICE] - /home/pi/v4l2rtspserver/src/V4l2DeviceSource.cpp:131
v4l2rtspserver[1071]: V4L2DeviceSource::doStopGettingFrames
Couple of questions:
  • Where does the log for v4l2rtspserver live? I looked in /var/log, but I don't see anything that matches. Then again the project that I downloaded as a disk image may be redirecting the log to somewhere else, or even nowhere.
  • Is there a string in "status" that means "yes, everything's working properly"? that I can grep for? Right now my watchdog timer is watching the YouTube stream's status, and that only updates every 5 minutes.
  • Has anyone else seen this this error and found/fixed the root cause?

TheWaterbug
Posts: 73
Joined: Fri Feb 05, 2016 12:35 am
Location: Los Angeles, CA, USA, Earth

Re: RTSP Streaming H264

Fri Mar 09, 2018 5:18 pm

Well, the bad news is that it still goes down from time to time. The good news is that I have 2 watchdog timers going--one on the ffmpeg relay station (on another Pi, because I can't get ffmpeg compiled on this one, due to a /tmp that's too small, and my lack of knowledge on how to resize that), and one here on the camera itself.

Since I don't know what statuses to look for on the RTSP-Server and/or the uv4l_raspicam, I'm monitoring the YouTube streaming status via a YouTube API. Unfortunately that takes about 5 minutes to update when a stream goes down. But I am watching it every 5 minutes, and when it goes down I restart uv4l_raspicam and RTSP-Server, in that order. Or I restart the ffmpeg service on the ffmpeg relay station.

So the good news is that the stream has been running continuously, with no more than a 5 minutes gap at any one time, for more than 5 days now.

TheWaterbug
Posts: 73
Joined: Fri Feb 05, 2016 12:35 am
Location: Los Angeles, CA, USA, Earth

Re: RTSP Streaming H264

Wed Apr 25, 2018 2:55 am

Gassel wrote:
Wed Sep 20, 2017 8:08 pm
What am I trying to achieve:
- I have a Dahua ip-cam system with a nvr; this server produces rtsp video streams (h.264), e.g. rtsp://user:[email protected]:554/cam/realmonitor?channel=1&subtype=0
- I want a small, cheap solution to view these streams on another tv (than the one attached to the nvr).
Another option is to run ffmpeg on a Pi and relay that stream to your YouTube channel via Stream Now. Then it'll be viewable anywhere. That's what I'm doing with my BeeCam.

Return to “Camera board”