[klug] Interesting project

2 views
Skip to first unread message

Bret McHone

unread,
Sep 3, 2014, 8:40:35 AM9/3/14
to Knoxville Linux User Group
I have had very little experience in my I.T. career in working with streaming video as I've always been more infrastructure and very little multimedia. Recently we broke ground on a new building and the powers that be wanted it to be streamed for public viewing so that those who donate money to us can see where the money is going and watch the progress.

Well, the camera that is mounted was put up by a security company and was being recorded 1fps continuously for the next two years. The problem that I had was that it only supported an RTSP stream and we were trying to figure out a way to stream that to the web. I ran across FFMPEG/AVCONV and was able to throw something together to stream it up to youtube. In order for it to work I had to insert a silent audio stream into the video feed for youtube to accept it. As it would run I kept finding that the program would continue to increase resource utilization and was maxing out the CPU constantly until all resources were used and the process would crash.

As a workaround I ended up butchering someone else's script to run the command and monitor it so that if it stopped it would wait a length of time and restart the command. This worked for a few days but eventually the server would vomit all over itself and crash. This was using both pre-compiled versions from repositories on Ubuntu 14.04 as well as downloading the snapshots and compiling the application myself. Every way I found using current versions seemed to have the same memory leak.

The final fix came from actually using an OLDER version of Linux Mint that had a binary version of an older form of FFMPEG/AVCONV available. Using the EXACT same command it has worked flawlessly without a single increment in memory utilization and CPU usage is sitting around 2% instead of 120%.... it's been an interesting project to say the least as I've only hit the highlights.

If you want to see our new construction project then feel free to check out our feed at: https://www.youtube.com/watch?v=QhkWtnsRpQY

It's interesting how many people I see go down a 1-way road the WRONG way...

Take care,
Bret

Michael Peek

unread,
Sep 3, 2014, 11:07:54 AM9/3/14
to kl...@eecs.utk.edu
I think that is very cool!  What kind of camera?


Two years ago I came across this on hackaday:

Birdwatching Meets a Computer-Controlled Water Cannon, Awesomeness Ensues
http://hackaday.com/2012/03/20/birdwatching-meets-a-computer-controlled-water-cannon-awesomeness-ensues/


IMHO it was an awesome talk.  This is what prompted me to try my own solution when we installed security cameras here.  I spent an afternoon butchering an example python script that sat on top of the opencv library.  It only takes a picture whenever it detects motion.  It works surprisingly well for a total hack.  The only downside is the cameras I bought -- they sometimes freeze and need a power cycle, which involves getting out the ladder.

Michael Peek
_______________________________________________
KLUG mailing list
KL...@eecs.utk.edu
http://www.KnoxLUG.org

Bret McHone

unread,
Sep 3, 2014, 11:37:51 AM9/3/14
to Knoxville Linux User Group
It's a Sarix camera by Pelco. Not sure which model exactly. It's mounted on an arm on top of one of our buildings overlooking the site. The great thing is that it's PoE, so if it did need to be reset I can just shell into the switch, kill the port and re-enable the port and it'll boot right back up. Though our other PoE cameras haven't had any issues, so it should be fine.

I've been monitoring our server resource utilization that's running FFMPEG and it's working beautifully with no increase in resource usage!

one thing to note is that I couldn't get FFMPEG to resize the video in-stream, so the source resolution has to be something youtube likes. So take that into account if anyone looks to do something similar.

-B

Brian Zachary

unread,
Sep 3, 2014, 12:26:26 PM9/3/14
to Knoxville Linux User Group
Bret,
That's super cool, thanks for taking the time to write up your experience. I love seeing a hack gone right :) For curiosity's sake, any chance you could be persuaded to post the script you're using to run and monitor the streaming process, versions of Mint and FFMPEG/AVCONV, and the process involved to set up a live stream to YouTube? I know I've seen streamed events on YouTube before, but I didn't realize it was something just "anybody" could set up. Very cool.

Thanks,
Brian


Bret McHone

unread,
Sep 3, 2014, 1:01:21 PM9/3/14
to Knoxville Linux User Group

It's no problem. All I did was butcher the work of others. :)

I honestly didn't realize youtube supported live streaming either until I started this project and kept trying to find a way to enable streaming of live video. It turn out that it is a PITA unless you basically have a purpose built system or software to fill in the gaps. YouTube just happened to be the path of least resistance since our web guy is still trying to figure out live streaming on the Adobe Media Server and it provided support for pretty much all platforms out of the gate.

I pulled the code to make the script from this article from stackoverflow.com: http://stackoverflow.com/questions/7708715/check-if-program-is-running-with-bash-shell-script

The command I used to take an RTSP video input with no audio, insert silent audio, and transmit it via RTMP to youtube was also butchered from other examples I found and it is the following command:

avconv -f rtsp -i rtsp://%URL_TO_CAMERA_STREAM% -f s16le -ar 44100 -ac 2 -i /dev/zero -shortest -c:v copy -c:a aac -f flv -strict experimental rtmp://%PATH_TO_YOUTUBE_FEED%

I am using Linux Mint 16 MATE and it has an FFMPEG package you can load from a repository right through the software manager that works beautifully. My testing was done running it on a VM on my desktop and now I set it up within a virtual infrastructure and it does nothing more than send the feed up to youtube.

Yes, I also realize the % is a windows variable designation instead of the typical $ for linux. I just though enclosing the fields that I sterilized in % would stand out a bit more.

-Bret

Bret McHone

unread,
Sep 5, 2014, 9:50:35 AM9/5/14
to Knoxville Linux User Group
well, I got cocky and didn't run my script because I thought I had the process stable and running for a couple days with no problem and BAM... it bit me. My encoder stopped and caused youtube to shutdown the live event.

I'm testing again with my stream but it looks if it goes down for more than a minute or so then youtube shuts down the event. So now I'm going ot have to add a little more to the script and let it send an email notification when it has to restart the service. Maybe even see if it can append info to a log so I can see errors or something. We'll have to see. That's what I get for doing something halfway.

Here's the current link if anyone was watching the construction or traffic on Cumberland Ave.. https://www.youtube.com/watch?v=m9KVUipzLCg   NOTE that the url will change if I can keep it online for more than a few dayy at a time because we'll switch back to the "official" account instead of my test account.

-B

Reed Wade

unread,
Sep 5, 2014, 9:42:42 PM9/5/14
to Knoxville Linux User Group
it works!

that's pretty slick

-reed



Bret McHone

unread,
Sep 12, 2014, 8:41:51 AM9/12/14
to Knoxville Linux User Group

The new "official" stream is back live instead of running from my test account. You can see it on our site at the URL:

http://www.etch.com/ways_to_give/expansion_project.aspx

 

or the Youtube direct link: https://www.youtube.com/watch?v=ddGmgIRaX0I


-B

Reply all
Reply to author
Forward
0 new messages