rtang
Posts: 49
Joined: Mon Oct 08, 2012 6:27 am

RTSP Streaming

Thu Aug 01, 2013 3:34 am

I've implemented a simple RTSP server that forwards RTP packetized H264 packets:
http://www.youtube.com/watch?v=1Egj1TjfHPc
http://www.youtube.com/watch?v=XBaWepyeoq4

Source code: https://github.com/codemonkeyricky/pi_streamer

I received some questions regarding my implementation, so I figured I might as well make a post here.

I was was asked how does my implementation compares to motion. I haven't really looked at motion before, so I don't really know. I took a quick look just now and it seems like there's no native Pi support yet, so I believe you can only get HD with a USB cam (correct me if I'm wrong) that supports h264 encode. In addition, I think it also supports HTTP streaming.

I was also asked if I do plan on releasing it to the Pi store. I do, in fact I already have a proof of concept version on there. I will get to it when time permits.

My implementation currently is a bare bone RTSP server; I hard-coded a bunch of stuff and didn't implement a bunch of stuff (eg. RTCP). But it does use the H264 output of the Pi directly, translate directly to RTP, and fires it off to the endpoint. It uses very little CPU (5~10%ish) due to its native implementation.

I've attached the binary I used in the video (if any of you feel adventurous). Assuming the camera is installed and enabled, simply launching the app with "./app > /dev/null" should do (run at your own risk!). Then you should be able to RTSP to it:
rtsp://192.168.1.50:8554/pi_encode.h264
And of course, replace 192.168.1.50 with your IP address.
Attachments
app.zip
(16.67 KiB) Downloaded 6259 times
Last edited by rtang on Sat Jan 04, 2014 10:53 pm, edited 1 time in total.

Toups
Posts: 2
Joined: Thu Aug 01, 2013 5:07 am

Re: RTSP Streaming

Thu Aug 01, 2013 4:56 pm

Would you mind sharing the stream parameters you utilized when creating this application i.e. resolution, FPS, bitrate...?
I have a project which I am starting to work on using a slimmed down (ports/connectors removed) to build a number of RTSP streaming cameras and this application appears as though it will be a much better fit versus VLC

User avatar
jbeale
Posts: 3500
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RTSP Streaming

Thu Aug 01, 2013 7:09 pm

Nice work! I like the drink cup as a camera enclosure, also :-).

Regarding 'motion', there is a version, motion-mmal http://www.raspberrypi.org/phpBB3/viewt ... 43&t=44966 that runs with the Pi camera. It works OK to capture motion and save stills and low-framerate video offline, but if you want to stream live images from its built-in HTTP webserver at port 8081 you only get separate frames at a very low framerate (eg. 1 fps).

rtang
Posts: 49
Joined: Mon Oct 08, 2012 6:27 am

Re: RTSP Streaming

Fri Aug 02, 2013 12:19 am

Toups wrote:Would you mind sharing the stream parameters you utilized when creating this application i.e. resolution, FPS, bitrate...?
I have a project which I am starting to work on using a slimmed down (ports/connectors removed) to build a number of RTSP streaming cameras and this application appears as though it will be a much better fit versus VLC
Here are the parameters I used:
state->width = 1280;
state->height = 720;
state->bitrate = 1000000;
state->framerate = 30;
state->intraperiod = 0; // Not set
state->demoMode = 0;
state->demoInterval = 250; // ms
state->immutableInput = 1;

rtang
Posts: 49
Joined: Mon Oct 08, 2012 6:27 am

Re: RTSP Streaming

Fri Aug 02, 2013 12:21 am

Toups wrote:Would you mind sharing the stream parameters you utilized when creating this application i.e. resolution, FPS, bitrate...?
I have a project which I am starting to work on using a slimmed down (ports/connectors removed) to build a number of RTSP streaming cameras and this application appears as though it will be a much better fit versus VLC
In fact, do you have a link describing what you are doing? I'm curious on the details.

Toups
Posts: 2
Joined: Thu Aug 01, 2013 5:07 am

Re: RTSP Streaming

Fri Aug 02, 2013 3:59 am

I do not have a public facing write-up of the project, as I am still trying to lock down the finalized v.1 requirements; however I will attempt to expand on my original posting.

"Diet Raspberry Pi"
The composite video, audio, USB and GPIO connection points will be desoldered and removed from the RPi as they are not required for this project and the completed unit (RPi + camera module) will be built into a custom molded composite enclosure. Removing these components will assist in minimizing the case dimensions, design complexity and provide additional air volume internally to dissipate heat while minimizes airflow restrictions. As I begin removing components, I will document the process with photographs and a detailed write-up; a representative image can be scene at http://i1.wp.com/www.crazy-audio.com/wp ... G_6809.jpg, although the GPIO connectors are still shown in this photo.

The camera module will be connected via a customized ribbon cable approximately 5cm in length which will be routed toward the power connector, the camera module will be attached to a 90-180 degree pivot which and when not extended should reside within the footprint of the RPi circuit board. (I have not yet tested placement of the camera in this area while the RPi is running for EMI; final placement may be adjusted accordingly to compensate)

Power will be provided via the existing micro-USB connector, although I may build in a 802.3af (mode B) compliant PoE adapter in the future.

Network connectivity will utilize the existing ethernet port, should WiFi be included, it would be soldered directly to the RPi via the USB solder points.

A microSD adapter will be soldered to the backside of the existing SD card holder or a commercially available adapter such as the AdaFruit https://www.adafruit.com/products/966 low-profile MicroSD card adapter for Raspberry Pi.

***Software has yet to be determined; I am testing various configurations but have not found the ideal package just yet. Ideally the software should be standards based RTSP or HTTP tunneled RTSP H.264. The issues I have encountered thus far have been in regards to latency (both transmit and receive buffers), application stability, standards compliance (does not require a custom receiving software package) and lack of build-in HTTP/HTTPS restrictions and controls (as found in most enterprise grade IP cameras). The primary receiving engine will be IP security software package such as Milestone, BlueIris, Smartvue, Nuuo… or a mobile device such as a laptop or tablet with VLC, IPCamViewer or similar application.

AshP
Posts: 10
Joined: Mon Oct 22, 2012 10:38 pm

Re: RTSP Streaming

Sun Aug 04, 2013 8:36 am

This looks to be working really well.

Will you be releasing source? I need to do a vertical flip (vflip).

haakoo
Posts: 1
Joined: Fri Aug 16, 2013 11:55 am

Re: RTSP Streaming

Thu Aug 22, 2013 6:23 am

rtang wrote:I've implemented a simple RTSP server that forwards RTP packetized H264 packets:

I received some questions regarding my implementation, so I figured I might as well make a post here.

I was also asked if I do plan on releasing it to the Pi store. I do, in fact I already have a proof of concept version on there. I will get to it when time permits.

My implementation currently is a bare bone RTSP server; I hard-coded a bunch of stuff and didn't implement a bunch of stuff (eg. RTCP). But it does use the H264 output of the Pi directly, translate directly to RTP, and fires it off to the endpoint. It uses very little CPU (5~10%ish) due to its native implementation.
You wouldn't be interested in releasing your source code? I'm working on a project where I'm planing to use a RPi+Cam as camera in an unmanned system and a RTSP-server would be very useful.

DaniProl
Posts: 5
Joined: Mon Jun 03, 2013 3:18 pm

Re: RTSP Streaming

Fri Aug 23, 2013 11:42 am

I'm also interested in source code in order to reduce width and height. Maybe some command parameters could do my work. Any plans to release a version with customized params?

constanza
Posts: 1
Joined: Sat Aug 24, 2013 9:03 pm

Re: RTSP Streaming

Sat Aug 24, 2013 9:15 pm

Hi rtang, it would be really nice if you can drop the source code of your litte app here :D

hat
Posts: 2
Joined: Sun Aug 25, 2013 7:10 am
Contact: ICQ

Re: RTSP Streaming

Sun Aug 25, 2013 9:12 am

What does this error mean?

[email protected] ~ $ ./app > /dev/null
app: ./src/sx_mgmt_rtsp.c:520: tcp_listener_thread: Assertion `rc == 0' failed.

a view secounds before the app run verry well

michael

mamai
Posts: 1
Joined: Wed Aug 28, 2013 8:17 pm

Re: RTSP Streaming

Thu Aug 29, 2013 9:34 pm

hat wrote:What does this error mean?

[email protected] ~ $ ./app > /dev/null
app: ./src/sx_mgmt_rtsp.c:520: tcp_listener_thread: Assertion `rc == 0' failed.

a view secounds before the app run verry well

michael
I have got this error too, after about 20min of streaming, after cool down (I guess) about 1-2 hours error gone (no reboot or power cycle occured). For now I have stream for 2 hours, and counting.. temperature of CPU raised from 40C to 60C

jorgegilmoreira
Posts: 1
Joined: Fri Sep 06, 2013 11:27 am

Re: RTSP Streaming

Fri Sep 06, 2013 11:31 am

Hi,
For me it is working great!
But for internet streaming this resolution is too high.
Can you modify your code to read a configuration file so anyone can put the desired resolution /or framerate for each .
Or insted put this setting by arguments when executing the program like ./app 640 480 15 (means 640x480 resolution and 15 frames).
You have done a great job!! Many thanks!

Best Regards,
Jorge Moreira

rtang
Posts: 49
Joined: Mon Oct 08, 2012 6:27 am

Re: RTSP Streaming

Sun Sep 08, 2013 6:37 am

Thanks for the feedback guys. I'll incorporate the feedback into the app when time permits (currently I'm trying to enable Miracast on the Pi: http://www.youtube.com/watch?v=4t83VMfb ... I8YvOiHBEg), probably a simple command line or config file interface.

jorgegilmoreira: I believe the encoder allows me to specify bit rate associated along with the resolution, though I'm not sure if it imposes any artificial lower bound.

hat & mamai: When you terminate the app, the socket is still bound to the app for a period of time before released by the system (I'm not sure why, just an observation I made). The error simply says it fails to bind to the address. Usually I just wait for a couple minutes before re-launching the app.

motocoder
Posts: 29
Joined: Fri Sep 06, 2013 4:13 pm

Re: RTSP Streaming

Sun Sep 08, 2013 8:26 pm

On my Pi/Camera, it streams back a bunch of static / distorted image.

tiger79
Posts: 15
Joined: Mon Sep 09, 2013 8:49 am

Re: RTSP Streaming

Tue Sep 10, 2013 1:18 pm

It might be me but the result is pretty consistent with the standard rtsp streaming capabilities of raspivid ?!
Also I cannot see any difference in "lag" inbetween those two versions... So I was wondering : did u mean to cut the lag as well with this implementation ?

r42998
Posts: 2
Joined: Thu Nov 07, 2013 2:53 pm

Re: RTSP Streaming

Thu Nov 07, 2013 3:04 pm

Any update on the feedback implementation?

As the previous post mentioned, I guess that you can get similar functionality with raspivid and cvlc using the following line:

Code: Select all

raspivid -o - -t 0 -w 1280 -h 720  -fps 25 -b 1000000 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
Cpu usage is 4-5% for cvlc and 1% for raspivid.

However, with the vlc/raspivid approach, we are limited to a single steam. This could be really too restrictive for video surveillance application for instance where you want to use a low resolution stream for motion detection and a high resolution high bit rate for recording. Due to latency issue, this is not possible to switch back and forth.

Does the architecture of you tool could support two different streams (low/high res.) to two different ports?

rtang
Posts: 49
Joined: Mon Oct 08, 2012 6:27 am

Re: RTSP Streaming

Fri Nov 22, 2013 3:45 pm

r42998 wrote:Any update on the feedback implementation?

As the previous post mentioned, I guess that you can get similar functionality with raspivid and cvlc using the following line:

Code: Select all

raspivid -o - -t 0 -w 1280 -h 720  -fps 25 -b 1000000 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
Cpu usage is 4-5% for cvlc and 1% for raspivid.

However, with the vlc/raspivid approach, we are limited to a single steam. This could be really too restrictive for video surveillance application for instance where you want to use a low resolution stream for motion detection and a high resolution high bit rate for recording. Due to latency issue, this is not possible to switch back and forth.

Does the architecture of you tool could support two different streams (low/high res.) to two different ports?
Sorry, no update yet. I've been busy with the Miracast on Pi project lately (http://www.raspberrypi.org/phpBB3/viewt ... 41#p452141).

But getting back to your question, so yes, it sounds like raspivid and cvlc do accomplish what my application does. In regards to high and low resolution, I think that's theoretically possible (depending on the resolution), though I don't know if this is something the MMAL API supports (I have not looked into this yet). If MMAL API does support this, then there's no reason why my app can't forward a another stream to a different port.

That being said, are you also expecting the application to perform the record and motion detection? I'm not sure if the Pi has enough horse power to perform motion detection as well as recording at the same time. Or are you suggesting these are done on the receiver end?

r42998
Posts: 2
Joined: Thu Nov 07, 2013 2:53 pm

Re: RTSP Streaming

Fri Nov 22, 2013 4:24 pm

rtang wrote: That being said, are you also expecting the application to perform the record and motion detection? I'm not sure if the Pi has enough horse power to perform motion detection as well as recording at the same time. Or are you suggesting these are done on the receiver end?
I have a Synology NAS and I streamed the PI video to the NAS which does the motion detection. It works pretty well even if I was not able to push the resolution higher than 800x600.

But I am looking at doing the motion detection on the PI which seems possible using this python script:
http://www.raspberrypi.org/phpBB3/viewtopic.php?t=45235

at 1fps only 12% cpu is needed.

The motion detection would be done on a low resolution, low frame rate and once triggered, the high resolution stream would be captured. If the delay to switch back and forth between the streams is low, a single stream is also acceptable.

kowetas
Posts: 6
Joined: Mon Dec 02, 2013 11:43 am

Re: RTSP Streaming

Mon Dec 02, 2013 11:56 am

Hi, this looks like it works really well, do you think it is possible to then pull the RTSP stream into something like Quartz Composer or Pure Data on the receiving computer to then manipulate the video doing like chroma keying or something? Currently I use MJpeg streamer to stream video across, but trying to get the resulting stream into anything other than VLC is difficult.

rtang
Posts: 49
Joined: Mon Oct 08, 2012 6:27 am

Re: RTSP Streaming

Tue Dec 03, 2013 3:59 pm

kowetas wrote:Hi, this looks like it works really well, do you think it is possible to then pull the RTSP stream into something like Quartz Composer or Pure Data on the receiving computer to then manipulate the video doing like chroma keying or something? Currently I use MJpeg streamer to stream video across, but trying to get the resulting stream into anything other than VLC is difficult.
The application simply repackages native h264 stream with RTP headers. What do Quartz Composer or Pure Data expect from the source stream? Native h264, RTP packets, or?

txt3rob
Posts: 365
Joined: Sat Aug 11, 2012 3:45 pm
Contact: Website

Re: RTSP Streaming

Fri Dec 06, 2013 11:11 am

this is great this little app.

it works wonders over lan but over internet / vpn it does fail but that could by my crappy upload speeds.

going to try it using openvpn to a vps and then stream from the web.
The Raspberry Pi Hell Guy - Random Ramblings to assist me and others.
http://raspberrypihell.blogspot.com
My Github - http:/www.github.com/random-robbie/
http://www.smspi.co.uk - send free uk sms via your raspberry pi from here

kowetas
Posts: 6
Joined: Mon Dec 02, 2013 11:43 am

Re: RTSP Streaming

Fri Dec 06, 2013 1:11 pm

rtang wrote: The application simply repackages native h264 stream with RTP headers. What do Quartz Composer or Pure Data expect from the source stream? Native h264, RTP packets, or?
Not entirely sure, I thought that Quartz Composer would want h264s, but it doesn't seem to like streams - I read somewhere that it can deal with whatever Quicktime could, but something seems to suggest that it has to be streamed .mov files which is not ideal, and is a little strange.

midnight1111
Posts: 20
Joined: Sun Apr 07, 2013 4:13 am

Re: RTSP Streaming

Sat Dec 14, 2013 6:49 pm

Have you tried streaming multicast UDP and playing the stream with vlc?
Thanks,
M

rtang
Posts: 49
Joined: Mon Oct 08, 2012 6:27 am

Re: RTSP Streaming

Sat Jan 04, 2014 10:55 pm

DaniProl wrote:I'm also interested in source code in order to reduce width and height. Maybe some command parameters could do my work. Any plans to release a version with customized params?
Code now open sourced under GPL.

Return to “Camera board”