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.