Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   mjpg-streamer running on roboRIO (http://www.chiefdelphi.com/forums/showthread.php?t=135737)

taichichuan 12-03-2015 23:37

mjpg-streamer running on roboRIO
 
2 Attachment(s)
Here at the Orlando Regionals while waiting in the pits for our robot to start working, I ported mjpg-streamer to the roboRIO. It was pretty funky since the source doesn't lend itself to cross-compilation. So, the answer? Compile it on a Beaglebone Black running Angstrom and copy the files over.

Result? A working camera feed that takes only 1% of the CPU. And, with a little Javascript magic, you can have multiple cameras running at the same time. There was only one little problem in that the libjpeg code isn't available on the roboRIO. So, simply copy the libraries from the BBB and place them in /usr/lib. Open source is a wonderful thing.

Then, untar the mjpg-streamer code and run it ala the instructions.

Enjoy,

Mike

AlexanderTheOK 13-03-2015 00:38

Re: mjpg-streamer running on roboRIO
 
Multiple cameras? Last I tried to use mjpg-streamer for anything productive I found that only a select few models didn't hog the entire USB bandwidth on their own (causing a second camera to fail because there "isn't enough bandwidth" . Most cameras that are "uvc compatible" just aren't because of the underdevelopment by the companies that make them. What cameras are you using?

taichichuan 13-03-2015 06:36

Re: mjpg-streamer running on roboRIO
 
Quote:

Originally Posted by AlexanderTheOK (Post 1457161)
Multiple cameras? Last I tried to use mjpg-streamer for anything productive I found that only a select few models didn't hog the entire USB bandwidth on their own (causing a second camera to fail because there "isn't enough bandwidth" . Most cameras that are "uvc compatible" just aren't because of the underdevelopment by the companies that make them. What cameras are you using?

The Logitech C920 does hardware H.264 encoding. Mjpeg-streamer understands that and doesn't repeat the process. This significant;y lowers CPU utilization.

HTH,

Mike

virtuald 13-03-2015 11:21

Re: mjpg-streamer running on roboRIO
 
This sounds great. I've been contemplating finding something like this and compiling for the roborio (though I was considering ffmpeg et al), now I don't have to! :)

I've been nervous about running the streaming stuff in the same process as our robot code (particularly since we're in python and there are GIL contention issues), so having a standalone executable sounds great.

cbf 14-03-2015 18:01

Re: mjpg-streamer running on roboRIO
 
Have you guys run this during a competition yet? I would be concerned about the bandwidth taken by two simultaneous video streams. In the past, we've accidentally saturated the feed between our laptop and the robot with a single 640 x 480 stream.

EmileH 14-03-2015 21:19

Re: mjpg-streamer running on roboRIO
 
How do you display it on the PC, thru smartdashboard or VLC? And does the FMS allow for communications over the ports used?

taichichuan 14-03-2015 22:23

Re: mjpg-streamer running on roboRIO
 
Quote:

Originally Posted by cbf (Post 1457558)
Have you guys run this during a competition yet? I would be concerned about the bandwidth taken by two simultaneous video streams. In the past, we've accidentally saturated the feed between our laptop and the robot with a single 640 x 480 stream.

Actually, you drop a Javascript page onto the ./www directory that has a button that allows you to switch between the streams. So, you're not getting both streams simultaneously unless you want them.

HTH,

Mike

taichichuan 14-03-2015 22:27

Re: mjpg-streamer running on roboRIO
 
Quote:

Originally Posted by emileh3467 (Post 1457598)
How do you display it on the PC, thru smartdashboard or VLC? And does the FMS allow for communications over the ports used?

Actually, a simple web browser will do the display just fine. You can compile mjpg-streamer for vlc, udp, rtsp or one of several other options. However, we've just been using the output_http.so plugin and Chrome, Firefox or IE to display it on the DS. You can even make it start automatically just like the dashboard normally would if you want to.

HTH,

Mike

virtuald 15-03-2015 00:41

Re: mjpg-streamer running on roboRIO
 
We're actually doing our DS in HTML/JS, with a python interface to forward networktables to/from the HTML page, so the mjpg-streamer is exactly what we're looking for. We played with it a little bit today and it's pretty sweet, but haven't wired it into our interface yet.

I'm curious, what javascript magic do you need to do to switch streams? Is there a delay? We setup two servers, and were able to stream two cameras that way. Didn't try the JS magic yet.

virtuald 15-03-2015 00:43

Re: mjpg-streamer running on roboRIO
 
Quote:

Originally Posted by AlexanderTheOK (Post 1457161)
Multiple cameras? Last I tried to use mjpg-streamer for anything productive I found that only a select few models didn't hog the entire USB bandwidth on their own (causing a second camera to fail because there "isn't enough bandwidth" . Most cameras that are "uvc compatible" just aren't because of the underdevelopment by the companies that make them. What cameras are you using?

We tested two Lifecam 3000 cameras this afternoon running two servers, and at 160x120 were at about 5% CPU usage. 320x160 was roughly the same. Haven't tried measuring the network bandwidth yet.

cbf 22-03-2015 13:54

Re: mjpg-streamer running on roboRIO
 
I'm trying to set this to test. Where did you guys install the ./www pages on the roboRIO?

Easiest thing that I can see is just to put everything under /var/local/natinst/www, since that would avoid having to edit the web config file (which seems to be at /etc/natinst/NISystemWebServer.conf).

The other alternative would be to add a second document root, but while that NISystemWebServer.conf bears resemblances to Apache .conf files (perhaps version 1.X?), it pretty clearly has proprietary NI directives in it, and I'm hesitate to make changes without real documentation (which I suppose I could hunt for on NI's site).

Also, did anyone notice the mjpeg-stream stuff at /usr/camera_server/mjpg-streamer-r63? It appears that's where the NI-IMAQdx routines get their USB webcam support from. It seems to be an older(?) version of the same MJPEG streaming libraries you guys are playing with.

cbf 22-03-2015 14:38

Re: mjpg-streamer running on roboRIO
 
When I try to run this, I'm getting an error opening the /dev/video0 device. I have a Logitech P930e plugged in, which should certainly support the requested mode.

Code:

admin@roboRIO-2877:/var/local/natinst/www/mjpg# source start.sh
MJPG Streamer Version: svn rev:
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 5
 i: Format............: MJPEG
Unable to set format: 1196444237 res: 640x480
 Init v4L2 failed !! exit fatal
 i: init_VideoIn failed

admin@roboRIO-2877:/var/local/natinst/www/mjpg# ls -l /dev/video0
crw-rw-rw-    1 admin    ni        81,  0 Dec 31  1969 /dev/video0


virtuald 22-03-2015 20:06

Re: mjpg-streamer running on roboRIO
 
What you want to execute is something like this:

Code:

LD_LIBRARY_PATH=`pwd` ./mjpg_streamer -i  "./input_uvc.so --device /dev/video0 -f 10 -r 160x120" -o "./output_http.so --port 5800 -w www"
Of course, you're going to want to write scripts and such to make it easy to run, and more importantly start on robot boot. I did all of this already, so I put install instructions + the scripts I created into a gist, you can access it at https://gist.github.com/virtuald/c8835244759e53314211

Feedback/comments welcome!

cbf 22-03-2015 21:36

Re: mjpg-streamer running on roboRIO
 
Actually, it turns out the default shell script was working for me. I had forgotten to shut down FRCProgram, which also opened the camera!

But your scripts for starting, etc. will be helpful if we decide to go this route.
Right now at 640 x 480, a stream from my Logitech P930e is taking 2.8Mbps, which is higher than the stream from our robot program, which uses the NI MAXQdx libraries to send a 640 x 360 stream at 24fps and onlyh takes 2.0 mbps. I'm still leery of how this will perform through the FMS.

But you said something about doing an entire Dashboard in JavaScript. That really intrigues me. And a Python implementation of NetworkTables. Is that running server side or client side?

virtuald 22-03-2015 21:39

Re: mjpg-streamer running on roboRIO
 
Quote:

Originally Posted by cbf (Post 1460800)
But you said something about doing an entire Dashboard in JavaScript. That really intrigues me. And a Python implementation of NetworkTables. Is that running server side or client side?

Check out the latest RobotPy project, pynetworktables2js. It forwards networktables traffic to/from an HTML page via a websocket. It hasn't really had a proper release announcement, but we'll be using it in our dashboard at our comp next week.

We run it on the driver station.


All times are GMT -5. The time now is 08:45.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi