Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Thu Jun 06, 2013 9:51 pm

Oh dear...

Don't know I'm afraid. Unfortunately I've got some other stuff I need to do now - so you're probably on your own for the rest of the evening. Feel free to keep trying to connect to ernie if it's useful.

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Thu Jun 06, 2013 9:54 pm

This always happens to me :lol: Thanks for help. I am sure its something and nothing.. most likely will realise tomorrow.

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Fri Jun 07, 2013 8:48 am

:o :o :o :o I love mornings and fresh cup of coffee. :shock:

I compiled it from source on the Ubuntu server using this article

The configuration file is inside the .lau file - that is different than the packed up version. When I run it I get a nice colorful console and realised that folders were missing for the media- so I created them. It still does not explain why I cannot broadcast to your server??

I used that debug osmf link and - behold - Video stream in my browser. It is about 2-4 seconds delayed. But I read you can setup crtmpserver to accept UDP packets and tweak the buffering - so maybe I can decrease the delay a bit more.

So did you say you proxied that rtmp stream somehow then? (to varnish?)

I will create a domain with a webpage using osmf with the stream - Ill take my spare Pi and mount it somewhere in my attic window so we get a nice view of the nice view I have. Ducks, occasional dog walker and water. Nothing like yours :lol:

Really appreciate your help!

Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Fri Jun 07, 2013 9:27 am

ppumkin wrote::o :o :o :o I love mornings and fresh cup of coffee. :shock:
Sleep is for winners :)
ppumkin wrote:I compiled it from source on the Ubuntu server using this article

The configuration file is inside the .lau file - that is different than the packed up version. When I run it I get a nice colorful console and realised that folders were missing for the media- so I created them. It still does not explain why I cannot broadcast to your server??
Yes, that's surprising. I'll leave crtmpserver running on ernie for now - feel free to have another try any time curiosity gets the better of you. I can't guarantee that it'll be up indefinitely though - that's a scratch box and services come and go on it.
ppumkin wrote:I used that debug osmf link and - behold - Video stream in my browser. It is about 2-4 seconds delayed. But I read you can setup crtmpserver to accept UDP packets and tweak the buffering - so maybe I can decrease the delay a bit more.

So did you say you proxied that rtmp stream somehow then? (to varnish?)
No, proxying rtmp involves using a dedicated rtmp server - like crtmpserver in fact. I should draw some pictures to explain the setup - but, basically, you can configure an rtmp server (FMS, Red5 whatever) to act as a relay so instead of clients connecting directly to the server you're streaming to you'd have a bunch of front end servers connecting to that back end as clients and relaying the stream. It's semantically the same to a varnish (or pretty much any other cache) setup - but the components are different.

The fact that it needs a special rtmp specific setup is one of the things that makes it more expensive to scale up rtmp based streaming: you can only work with content delivery networks that understand rtmp and end up paying a premium for the service. Once you get the encoding and packaging working (and if you can live with the latency - which is pretty much a non issue for most live TV) http based streaming is easier and cheaper to live with because it's all just standard http.
ppumkin wrote: I will create a domain with a webpage using osmf with the stream - Ill take my spare Pi and mount it somewhere in my attic window so we get a nice view of the nice view I have. Ducks, occasional dog walker and water. Nothing like yours :lol:
Yes please - give us ducks :)
ppumkin wrote:Really appreciate your help!
And I admire your perseverance :)

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Fri Jun 07, 2013 10:22 am

:)

http://www.pku.la/

A simple html page like yours at the moment. Soon I will deploy a full MVC4 site on there with other stuff on there too. (My main goal is a weather station(using spark funs weather stuff) and now with this live feed - So in a few months it might be on my roof or somewhere on the shed outside)

Nothing interesting happening at the moment on the cam - I need to get back home and install it on a better location.

Raspberry Pi ---FLV---->> Ubuntu/crtmpserver (100mb/s) <=RTMP=> IIS8 on 50mb/20mb serving pages (home)

So essentially the Pi is dumping the payload to a nice fast server so it won't destroy my internet connection. Then I server up the webpage also from my home WS2012/IIS8 but the client requests the stream from the ubuntu RTMP server.

Really exciting stuff. I have been waiting to this for almost a year now 8-)

Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Fri Jun 07, 2013 10:28 am

Nice! When do we get ducks? :P

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Fri Jun 07, 2013 5:54 pm

I tweaked the position. A man fishing... a tent and ... the ducks flew away :P

Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Fri Jun 07, 2013 7:36 pm

Oh, that's lovely!

Beats downtown Clapham Junction every time :)

BPK
Posts: 30
Joined: Mon Jun 04, 2012 10:12 am
Location: Bristol, United Kingdom
Contact: Website

Re: Live streaming from PiCam

Sat Jun 08, 2013 9:21 am

That's odd... I've got a nice HLS stream going that is available on IOS (as expected) and I subsequently expected it to not work on my android as the original one http://newstream.hexten.net/picaster/ posted by Andy did not work. However, it did... and worked reliably. I have a Samsung Galaxy S3 Android 4.01.

I originally thought it was because I had updated the raspberry pi firmware but I went back to the original firmware and it still worked.

It's not yet connected to any internet facing server like Andy's so I can't share but would be interested if anyone else's android device worked with the one provided by Andy.

I know ppumpkin's stream at http://www.pku.la/ is using rtmp (lovely view by the way!). This one did not work on my android either
Barnaby Kent
http://www.pi-cars.com
Control your radio controlled car through your Raspberry Pi

aaronr79
Posts: 3
Joined: Tue Jun 11, 2013 9:22 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:07 am

Thanks, Andy, for your work on this and sharing the psips filter. I've got everything setup almost exactly as you (raspivid > psips > ffmpeg > nginx > safari) and it's all working hunky dory on my local network. I've noticed your cam in the link you've provided seems to be on permanently, but my setup seems to stop recording after 5-6 hours. I'm not sure why, I wonder if you've done anything else to prevent it falling over, or are you automatically restarting the schell script if the process does die?

I'm using the unpatched version of raspivid, but I'm assuming I should still be able to get 24 hours out of that?

The Pi seems to be consuming ever increasing amounts of memory as the process runs. Is it possible that the Pi is just running out of memory after a few hours which is causing the process to be killed? I'm using a Model B Pi, so if this is a memory issue, is it safe to assume that this technique of live streaming may be a bit of a stretch for the Model A Pi?

The "live" folder fills up with with several gigabytes of .ts files, pretty quickly - if the process hadn't died anyway, it would of only been a few more hours before the HD card was full. What are you doing to circumvent this? Is it safe to periodically delete older .ts files to clear space?

Thanks again for you work on this and any help you can provide getting my setup a bit more stable and permanent. :)

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:17 am

If you compile nginx with the rtmp-module you don't need to use the psips.I did that and will publish a guide shortly on the entire setup and walkthrough. It works very well if you are going to use it for 1 or 2 users max. the nginx rtmp module also has built in native (does not need ffmpeg) HLS repackaging and other awesome features I am still learning about. It also support pulling feeds from other servers and even pushing your feed to an external server if you want to cache/load balance it.

I noticed that my Pi crashed regularly but I also realised that I was running firmware from last year. So i downloaded the raspi-update and let that do its thing. It has been stable since then (i also did the network patch just in case)

I also run it headless so I gave the gpu 64mb ram and overclocked it to medium using raspi-config. The cpu usage avg is about 9% and RAM is various but it does not fill up.

Which folder is filling up? exact location- I have not noticed anything like that happening at all. I got a 4GB card and it has been running a few days now.

Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:23 am

aaronr79 wrote:Thanks, Andy, for your work on this and sharing the psips filter. I've got everything setup almost exactly as you (raspivid > psips > ffmpeg > nginx > safari) and it's all working hunky dory on my local network. I've noticed your cam in the link you've provided seems to be on permanently, but my setup seems to stop recording after 5-6 hours. I'm not sure why, I wonder if you've done anything else to prevent it falling over, or are you automatically restarting the schell script if the process does die?

I'm using the unpatched version of raspivid, but I'm assuming I should still be able to get 24 hours out of that?
Yeah, I'd have thought so - in fact I did before I patched it... The timeout is in milliseconds - so you need 86400000 for 24 hours. The first time I tried it I assumed it was seconds.

Mine's been running continuously for over a week without any attention.
aaronr79 wrote:The Pi seems to be consuming ever increasing amounts of memory as the process runs. Is it possible that the Pi is just running out of memory after a few hours which is causing the process to be killed? I'm using a Model B Pi, so if this is a memory issue, is it safe to assume that this technique of live streaming may be a bit of a stretch for the Model A Pi?
I'm not seeing any memory leakage - nothing's using more than a few MB. It should be absolutely fine on a Model A.

It's worth finding out which process is leaking. htop is a nice way of seeing what's going on:

Code: Select all

$ sudo apt-get install htop
$ htop
If you hit f6 you can configure it to sort on memory usage. On mine Apache's using the most memory - but nothing excessive, ~2%.
aaronr79 wrote:The "live" folder fills up with with several gigabytes of .ts files, pretty quickly - if the process hadn't died anyway, it would of only been a few more hours before the HD card was full. What are you doing to circumvent this? Is it safe to periodically delete older .ts files to clear space?
Yes, anything that's fallen outside the availability window in the m3u8 (which is two hours in the scripts I posted) can be deleted. That's what this bit

Code: Select all

# cleanup
{
  while sleep 60; do
    find "$session" -type f -name '*.ts' -mmin +240 -print0 | xargs -r -0 rm
  done
} &
does in hls-low.sh.
aaronr79 wrote:Thanks again for you work on this and any help you can provide getting my setup a bit more stable and permanent. :)
Yup - first thing is to figure out what's leaking memory. I think once that's fixed and you have the patched raspivid and disk cleanup working you should be able to stream for ever :)
Last edited by Andy Armstrong on Tue Jun 11, 2013 10:26 am, edited 2 times in total.

Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:24 am

ppumkin wrote:If you compile nginx with the rtmp-module you don't need to use the psips.I did that and will publish a guide shortly on the entire setup and walkthrough. It works very well if you are going to use it for 1 or 2 users max. the nginx rtmp module also has built in native (does not need ffmpeg) HLS repackaging and other awesome features I am still learning about. It also support pulling feeds from other servers and even pushing your feed to an external server if you want to cache/load balance it.
I'm really looking forward to your writeup - having a robust solution that can support both HLS and RTMP is very appealing. Not rushing you or anything... :)

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:28 am

Its drafted in my blog I just need to make sure that pushing streams work and confirm that HLS also works when going to the Pi with my iPhone.
The nginx compilation needs allot configuration settings to work properly - it took me a day to get it just right. I really want to publish it quick so that other can use it asap too :) I just don't want a guide that is half working. POssibly this evening I will publish it. You can try it out and let me know :)

PS- What folder is filling up?

Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:30 am

Thanks! :)

Here's a sneak preview of one of the places mine might end up:

Image

Image

Image
Last edited by Andy Armstrong on Tue Jun 11, 2013 10:35 am, edited 1 time in total.

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:34 am

OMG!!! :o :o :o :o Did you assemble it yourself? I also wanted to use the Pi to stream. Unfortunately HSL will not be good as it is inherently delayed. But I got a 0.5seconds delayed feed using a player that Andy suggested but it needs flash.. there is not other way at the moment.

How does it handle? What PCB are you using to stabilize and drive. I seriously thinking of getting a big one like that. I got a small one for training only at the moment :)

Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 10:40 am

It's an X650-V4 frame from Cool Components.

I've got most of the bits here - just waiting for some wire and connectors. The initial setup will involve an Ardupilot with GPS to control it and some kind of home brewed (probably) gimbal. It has plenty of payload to carry another Pi to handle higher level navigation - so I may do that.

I'm planning to stream from it over wifi. Not sure how well that will work in practice.

aaronr79
Posts: 3
Joined: Tue Jun 11, 2013 9:22 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 12:24 pm

I hadn't noticed the 'hls-low.sh' script - I was using the example on the psips github readme. As far as I can see, there are a couple of differences: raspivid was encoding at 1.8Mb/s (as opposed to 900Kb/s); and ffmpeg was adding a blank audio channel in. I'm guessing that may account for the difference in memory usage?

I'm now using a setup closer to hls-low.sh and it seems to be ticking along without the gradual increase in memory consumption. I'll leave it ticking over all day and keep an eye on it.

With the patched raspivid, was does the new -g option (intra period) actually do? What practical difference does it make?
Last edited by aaronr79 on Tue Jun 11, 2013 12:39 pm, edited 1 time in total.

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Tue Jun 11, 2013 12:29 pm

aaronr79 wrote: With the patched raspivid, was does the new -g option (intra period) actually do? What practical difference does it make?
Andy answered that for me earlier..

http://www.raspberrypi.org/phpBB3/viewt ... 98#p364398

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Tue Jun 11, 2013 1:10 pm

Andy.

I tried to mulitcast the stream and the outcome is a bit rubbish :(

What I have now is nginx with the rtmp-module installed on the Pi. I can stream to localhost without psips and I can view the feed almost live using strobe media playback from osmf. Its really good!

OK- so the rtmp module has a simple command "push" and I set my external rtmp server in there. When I now look at the feed on the external page I get allot of artefacts and jittering. Internal is OK though.

I also tried your tee method for ffmpeg.. that is even worse- both feeds stutter and it just not good.

Then I switched back to the psips method I used to publish RTMP to the external server and its fine. Really good picture , fast response and no jitter.

Not sure what causes this but just wanted to let you know I tried that and the results are OKish if you use nginx-rtmp-module.

I suppose people can either choose internal or external from personal preference. But I think most people will use the compiled nginx-rtmp-module because it is just blazing fast and has a ton of features!

Tutorial almost on its way...

aaronr79
Posts: 3
Joined: Tue Jun 11, 2013 9:22 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 1:14 pm

ppumkin wrote: Andy answered that for me earlier..

http://www.raspberrypi.org/phpBB3/viewt ... 98#p364398
Ah yes, thank you.

So if I understand that correctly, the intra period setting is useful for if we're serving multiple bitrate streams simultaneously. Does it have any impact if we're not, and just serving one bitrate? I ask because I'm using the unpatched raspivid and I it seems to be working fine. Would there be a noticeable difference if I used the patched raspivid?

I have another question... :)

With the usecase of a CCTV system, we might want to archive the video for a period of time - so instead of deleting the old .ts files, lets assume I store them on a NAS device. Is it possible to somehow playback those .ts files, if say an incident happened at a particular time and I found the relevant chunks of video? If so, hows it done (this bit obviously doesn't need to be done through a browser)?

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Tue Jun 11, 2013 1:18 pm

aaronr79 wrote:
ppumkin wrote: With the usecase of a CCTV system, we might want to archive the video for a period of time - so instead of deleting the old .ts files, lets assume I store them on a NAS device. Is it possible to somehow playback those .ts files, if say an incident happened at a particular time and I found the relevant chunks of video? If so, hows it done (this bit obviously doesn't need to be done through a browser)?
You can just open the saved files on the NAS using VLC. But the rtmp-module also has a play-back feature that can enumerate files in a certain directory, display a playlist and play the files back to you :) And it super simple 1 line setup required in the config file :)

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Tue Jun 11, 2013 2:49 pm


Andy Armstrong
Posts: 57
Joined: Sat Dec 03, 2011 10:10 am

Re: Live streaming from PiCam

Tue Jun 11, 2013 4:31 pm

That looks excellent, thanks! I'll have a go at it tonight or tomorrow.

Thank you!

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Live streaming from PiCam

Thu Jun 13, 2013 11:45 am

Thank you Andy for getting me on the right track with this!

I have been streaming now for 2 or 3 days constant. Pi did not crash and the stream is good. One problem though is pushing RTMP stream to an external server seems to be worse quality and does not always work... Not sure why - I contacted the application developer; he had a look some extensive logs and everything seems fine.

So my only tip is to decide if you want to view it locally on LAN or on a remote server and setup ffmpeg to pipe to either or. That gives the best stability and quality.

I used the osmf you suggested and it is really nice that player! Thanks :) Fully customizable and for free. I eventually figured out to turn of buffering and quite literally the feed does not lag any more than 0.8s ... I wonder what could be done to reduce that even further(some settings on the Pi?) if it was about 0.3~0.5 that could be pretty good for use in like a quadcopter (I mean for WIFI/LAN latencies not Internet) :ugeek: :)

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 9 guests