11

There are gazillions of forums and threads about getting rid of a 5 second latency when using a Pi together with a PI-Cam as a surveillance camera. Many tutorials show how to use vlc to encode and stream the images using the RTP protocol which results in a ~5 second lag.

According to me, the reason is that raspivid is encoding the stream to H264, while VLC has to decode it again and re-encode it to whatever RTP is. The commandline looks like this:

raspivid -w 640 -h 480 -o - -t 0 |cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

The first part tells raspivid to stream video to the standard output:

raspivid -w 640 -h 480 -o - -t 0 

The part after the pipe, tells VLC to pick it up, and decode it using h264:

cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

This mux-ing and demux-ing is quite a waist of resources!

I found the sources of raspicam at github, and I think something can be done in the encoder_buffer_callback method (currently at line 848) to skip the encoding. However I'm not good at c, and not familiar with video encoding at all, so I don't have a clue where to begin.

On Github I can see 330 forks, but they don't seem to be specifically for raspicam (rather for the whole userland project). I got lost trying to find a fork that removed encoding or implemented something simpler like mjpeg.

Could someone with c and video codec knowledge help me and the other gazillion users to get rid of the latency? Probably the solution is already out there in one of those forks, but I've spent hours searching for it without any luck.

p.s. I'm not looking for a browser solution, but I ultimately want to stream it to a Synology, preferably using mjpeg streaming (but not via a webpage, rather a standard mjpeg stream that comes built into most commercial ip-cams). First step is gettig rid of h264.

Louis Somers
  • 283
  • 1
  • 3
  • 10

2 Answers2

5

That's probably not what you are wanting from answers, but I do not recommend VLC streaming at all..

For a school project, I tried some streaming options (on RPi too!) :

  • VLC
  • MJPEG
  • GStreamer

Using VLC and MJPEG (and some other less known), I had latency between 3 and 5 seconds..
Using GStreamer, NO LATENCY and with a best resolution (and lots of more options) !
If you are interested, you can check it out here.

And if you'll use it, here is my pipeline :

raspivid -t 0 -w 640 -h 480 -fps 25 -b 1200000 -p 0,0,640,480 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=YOUR_IP port=YOUR_PORT
Val
  • 77
  • 6
0

Some folks have been working hard on this since I first asked this question, and by this time there are a few options (strange that no-one has responded to this question yet). I have tried RaspberrIPCam and had some success, however it seems like the rtsp packets had an extremely short TTL or something. Having the Pi hooked up directly to a router next to my PC it would work perfectly. But as soon as I installed the cam where I wanted it, and tried to access the stream with two routers between, no image would arrive. I checked the source-code and found the TTL set to maximum. I never figured it out completely.

Currently I would recommend RaspberryIPCamera wich has a nice user interface (see screenshots) and there even is a ready-made SD-card image for it. I have tried the SD-card, but reverted to doing a manual install as described here with great success (my current setup). Instructions for hooking it up to a Synology DiskStation are also available and are working perfectly on my system. The problem with the SD card image was that I was unable to expand the filesystem to the full extent of the SD card (I also want to run some other stuff on it to control some relays via the GPIO pins).

The above solution uses components of the UV4L project. The documentation of the UV4L project on this page also mentions:

Among the other things, it offers a Web interface from which it’s possible to see the video stream in various ways and a Control Page allowing to fully control the camera settings while streaming with any Video4Linux application.

I have not yet tried it lake that yet though (since I don't want to mess up my current set-up).

Louis Somers
  • 283
  • 1
  • 3
  • 10