Add Streaming Video to any Bio-lab!

Posted by – October 16, 2009

Combining an inexpensive (under $15) USB webcam with free VLC media player software, it is simple to add password-protected internet streaming video for remote users to any lab.  VLC includes the ability to capture from a local webcam, transcode the video data, and stream the video over the web.  It’s available for OS/X, Unix, Linux, and Microsoft systems.

Hint: Video formats are confusing.  Even video professionals have a tricky time figuring out the standards and compatibility issues.  Today’s web browsers also have limitations in what they can display (mime types and such) — which simply means both sides need to use VLC.  Figuring all this out using the VLC documentation takes some work.  Transcoding the video is required and a proper container must be used to encapsulate both video and audio.  Once debugged, it’s good to go.

Here’s how it worked in the lab:

Webcam for Biotech Lab Automation

See the setup below to get it running.

  • First, get a USB webcam (definitely under $20), & install it on the local machine.
Low cost webcam

Webcams like this are available for under $10 online.

  • Second, install VLC software on the local machine and the remote machines.
  • Third, verify the webcam is compatible with the operating system by viewing the capture window locally in VLC: Open VLC and choose File->Open Capture Device.. Then select the USB webcam, do some fiddling around, and get a good picture.  Repeat as necessary until this is working locally (especially on Microsoft systems, usually involving repeatedly rebooting, etc).  If there are problems here, then perhaps that webcam isn’t supported yet by the operating system, so forget it; alternatively, buy an older webcam (used or dusty) since the operating system is more likely to support older equipment.
  • Now set up the webcam for streaming as follows, since the local capture is OK:

VLC is configurable via the GUI or via command line.  Using the GUI can be handy, though for quick setup, nothing beats the command prompt.  The script below will need some customization as noted, and it assumes the local machine is Microsoft Windows running cygwin.


#!/bin/sh
"/cygdrive/c/Program Files/VideoLAN/VLC/vlc" \
 dshow:// :dshow-vdev="UVC Video Camera" :dshow-size=640x480 \
 --dshow-chroma=MJPG --dshow-fps=30 \
 --dshow-caching=500 \
 :sout='#transcode{vcodec=mp2v,vb=10,fps=30,scale=1,width=640,height=480,acodec=none}:std{access=http,mux=ts,dst=0.0.0.0:8090}' \
 --sout-http-mime=application/x-vlc-plugin \
 --sout-http-user=$USER \
 --sout-http-pwd=$PASSWORD

Set the PASSWORD environment variable in the environment; this provides network security.  Replace the name of the webcam with the name displayed when viewing the camera device locally with VLC (as in the prior step above).  Change the vb= parameter, which is in kb/sec, to suit the network; I use 10 or 20, to limit the bandwidth required.  Most importantly, add the -vvv option when debugging, as this will show device errors (such as what size or framerate the device supports): the dshow parameters all refer to Microsoft’s driver framework and may need tweaking depending on the device.

The remote users run VNC, then select File -> Open Network.. with the address of the machine at port 8090, as in: http://heavybio.dyndns.org:8090

The transcode options for changing the video codec or audio codec to different combinations isn’t straightforward, as video codecs, audio codecs, and containers are a hairy business; similarly with the MIME type.  The above example doesn’t include audio yet, though this webcam has a microphone.  I have yet to hook that up.  It’s also possible (according to the docs) to connect multiple webcams into a single video stream — to create a video tiling effect — that’s something I’ll try soon as well, with multiple angles on the bio-robot.

Another option is displaying text (marquees) such as current system time, etc.  I tried a bit of that; not sure it works when streaming (the docs have conflicting information currently), although it seems the marquee would be set up as a filter, with the filter included in the transcoding options.

A cool setup for a $15 webcam!  Now I hope someone out there can suggest some simple plans for adding optics, for a streaming-webcam-microscope conversion..

2 Comments on Add Streaming Video to any Bio-lab!

  1. Awesome! I assume this really chugs your bandwidth if you get many viewers? Is it easy to rebroadcast via something like justin.tv to mitigate that? (I’m pretty newb when it comes to this stuff).

    On the microscope+webcam front: I found proof-of-concept good results by literally scotch-taping a Sony PS3 Eye onto the neck of a $50 eBay 40-400X microscope, but I agree that some intermediary optics would be ideal.

    • JonathanCline says:

      It is possible to re-broadcast to a different server; it looks something like this:

      webcam(s) --USB/VLC--> local PC --VLC--> fast network server <--VLC--> remote viewers using VLC

      The local PC sends high-res data. The fast server has different options for limiting the bandwidth, which could include transcoding for lower frame rate, smaller image size, etc. I think my example isn’t really correct for limiting the bandwidth from the video codec: it is supposed to be around 16 kB/sec and it seems higher. It is also possible to have the server embed the video as Flash or WMV in a web page, it only takes a bit of web programming.

      As for broadcasting to some video broadcasting service provider, in real-time, I’m not sure. Although frame grabs could be put up on any web host (flickr etc), and video captures could be uploaded to any video service if encoded properly (blip.tv etc). For my bio project, I am most concerned with frame rate and delay, because the robot arms are moving around and I need to see them in actual time. In other bio projects, frame rate probably doesn’t matter, and resolution is more important, so frame grabs might be the best bet there.

      My solution is really meant for viewing by 1 remote person, possibly 2 (those running the experiment).