regular bold extrabold

Gizmo As A Streaming Video Server

gizmoadmin
gizmoadmin
Site Orchestrator
Types:
Skill Level:
Components:

Overview

How to set up video streaming with a webcam and a Gizmo board. Goes over details of transcoding/encoding. Uses Video4Linux and VLC from Videoland, and accomplishes streaming on Chrome.

Instructions

I’ve been wanting to see how well the Gizmo board would perform as a streaming video server as I have some plans to set one up streaming video of itself to the website here.

I first scrounged up an old webcam that I had lying around. This was a camera that I bought for about $7 or so about four years ago. It is a JC-AM100 manufactured by J-WIN, but I think that just about any camera would do.

I tried to locate Linux drivers for my Ubuntu installation and could not find any anywhere. What I did find is Video4Linux (V4L). I checked carefully through the list of supported devices and didn’t see my device listed. I figured I would probably have to get another camera, but I figured “why not just give it a try and see what happens?” So I plugged it into one of the available USB ports (I’ve got a keyboard/mouse plugged in through a USB splitter and the hard disk plugged into the USB header, so I still had two ports available on the Gizmo board).

I installed a webcam application just to test out the camera and see if I could get an image. From the command line I typed:

sudo apt-get install cheese

After the install completed I started up the cheese application and was pleasantly surprised to see that it immediately recognized my camera and displayed the live video image. Only thing was, the image was upside-down. I tried to use the flip effect in cheese to invert the image but without success. So, while my camera was supported to some extent, the support is limited. Quick solution- turn my camera over. Problem solved!

After playing with the webcam and cheese for a little while, I was ready to move onto the next step. I am going to use VLC from VideoLAN to transcode and stream the video, so the next step was to install VLC.

sudo apt-get install vlc browser-plugin-vlc

Next, I will describe how to get VLC configured correctly to take the camera image as input and stream the video to the network.

I experimented with many different codecs and muxes and was successful in displaying video into a Chrome browser, but I never did get it to display correctly into Firefox. I struggled with it for many hours and did lots of web research and came up short.

Anyway, what was lost in accomplishment was gained in education. I now know a lot more about video streams than I ever thought I wanted to.

A quick summary: Video is transcoded into a binary stream of data through a program called a codec. Each codec encodes the stream differently. Think of it like translating a lecture into different languages. Each language will look and sound completely different, yet each will carry the same content. Some common codecs are mpeg1, mpeg2, mpeg4, h.264, divx, wmv, and the list goes on. Each was created for a particular purpose. Some are better than others for streaming. The important consideration when streaming is bit rate. The wires can only carry so much bandwidth. So streaming video needs to be highly compressed in order to carry a high quality image while consuming the least amount of bandwidth. H.264 and MPEG4 are both well suited for streaming.

The next consideration when transcoding video is what is called the mux, which refers to the wrapper or container in which the encoded video stream will be packaged. If we go back to the language analogy above, the mux would refer to a book, an audio cassette, a CD or a text file. All of these can contain language and (just about) any language can be put into any container. The thing is, you have to know what kind of container your audience knows how to process before you decide on how to package your speech. An audience that can’t read will have no use for a book. An audience that can’t hear will not be able to decipher an audio recording.

So, when encoding video to broadcast to the web, it is important to choose both an encoder and a mux that are supported by the most browsers. This is where I ran into trouble. I was able to get Chrome to understand some transcoder/mux combinations, but I could not find any that worked really well in Firefox.

I have been using the command-line to issue my VLC run commands as I do not need a GUI or a video display running on my Gizmo. I want to let the board put all of its effort into keeping up with the video transcode. VLC comes with a command-line interface called ‘cvlc’. It is invoked by typing the following command at the command prompt:

cvlc video_source_info –sout='’#transcode{transcode_information}:standard{output_information}' [options]

Where: video_source_info specifies where the video input is coming from. In my case, the input video is coming from my webcam, which is using the v4l2 (video4linux) driver and is connected to the device /dev/video0. So the video_source_info for my setup is:

v4l2:// :v4l2-vdev="/dev/video0" :v4l2-size="640×480"

transcode_information specifies what video and audio codec to use to encode the video. The one that I found that works best (at least for Chrome) is theora. The command line configuration for setting up the theora codec is:

vcodec=theo,vb=4096,width=320,height=240

output_information refers to the mux container that will carry the video stream as well as the transfer protocol and port information for streaming onto the internet. For the theora codec, I found that the mux that works best for Chrome was ogg. Since I’m sending the video to a web browser, I want to send it using http protocol. (Note that if you are not interested in playing the video stream in a browser, it is quite simple to set up a VLC client to receive a video stream from a VLC server and you could probably choose whichever codec and mux gives you the highest quality video and it will just work. I had mine running VLC->VLC in literally a few minutes. It was getting it to run VLC->Firefox that cost me hours and hours). So my output_info looks like:

mux=ogg,access=http,dst=192.168.0.17:8080/test.ogg

The dst specifies where the output stream should be directed. My Gizmo’s IP on my local network is 192.168.0.17 and I am going to use port 8080 for the streaming video. The filename “test.ogg” is really a named pipe, not a real file.

So, putting it all together, the command line for streaming theora encoded video from my webcam is:

cvlc v4l2:// :v4l2-vdev="/dev/video0" :v4l2-size="640×480" –sout='#transcode{vcodec=theo,vb=4096,width=320,height=240}:standard{mux=ogg,access=http, dst=192.168.0.17:8080/test.ogg}' –brightness 1.8 –contrast 1.2 –no-sout-audio –rt-priority

The options at the end of the command control some of the settings of my webcam. The ‘rt-priority’ stands for “real-time priority” and it tells VLC to run with as little interruption as possible.

To connect to the video stream, I can type the following address into my Chrome browser address bar:

http://192.168.0.17:8080/test.ogg

Comments

No comments yet

Comments

No comments yet. Start it off.
Join the Conversation