Video Streaming KNOW-HOW

Streaming servers and codecs GO WITH THE FLOW If you want to use to stream video over the Internet, you might have to fight your way through a jungle of codec alphabets. The available software is anything but intuitive. This article

will help you pick the options that best fit your needs. BY OLIVER FROMMEL

here are two to make a number of technical decisions, users will need to manually install any- basic ap- like which video and audio formats to thing else. Tproaches to use. Depending on the context, this can distributing video over refer to different things (although people Free, Open, Patented the Internet and also two tend to confuse them), such as the video Depending on the kind of use you have different streaming vari- and audio codecs, or possibly container in mind, licensing and legal aspects can ants. On top of these formats. Apple’s QuickTime is an exam- also be important. If you are just stream- choices, there are also ple of a container format that can con- ing a video to your buddies in your liv- video and audio for- tain different codecs, like Sorensen. The ing room from your basement, you can mats to consider. This terminology is also inconsistent between probably ignore licensing issues, but article will help you technologies. For example, MPEG refers commercial use is an entirely different decide what best suits both to the codec and the container for- thing. Even if encoders for various co- your needs. mat. I think codec is the best choice. decs are available free of charge on One video distribution ap- There are a number of important as- Linux, actually using them may be risky proach is to download the file com- pects to consider, like the target audi- from a legal standing. For example, pletely and view the local copy. The ence for you streams. If your audience MPEG technologies are all patented in other approach is to opt for streaming, mainly comprises Linux users who will some way or another. which allows users to watch something have no trouble installing MPlayer and Depending on the format, vendors as soon as the first few packets have so forth, you have a large choice of pos- need to license their encoders or decod- reached their machines. The stream can sible codecs. ers with the MPEG consortium [1], and start on demand by the client, or it can If you intend to serve Windows and because the licensing fee normally de- start at a fixed time without waiting for Mac users, both systems have a couple pends on the number of boxes a vendor the viewers (live stream). of pre-installed codecs (WMV on Win- sells, this approach is not useful for free In both cases, the stream provider has dows and QuickTime on the Mac), but software developers. The same thing ap-

WWW.LINUX - MAGAZINE.COM ISSUE 77 APRIL 2007 45 KNOW-HOW Video Streaming

plies to almost any usable codec; a live encoder that purchasing a commercial encoder reads analog video software from MainConcept [2], for from V4L devices example, at least keeps you on the safe and creates side. MPEG-4 output. Real Networks [3] is the veteran in the This still does not streaming industry. Real sells encoders, give you an easy players, and streaming software, but it solution for han- has also developed its own codecs. As dling DV video. you might expect from a codec that has been under development for ten years, Flumotion the Real codecs provide excellent video There is also the and audio quality in comparison to the free Flumotion bandwidth needed. The server and en- server [5] by Flu- coder tools are mature and fairly stable. endo, a company On the downside, the technology is pro- that has been try- Figure 1: The free Flumotion server uses the format for prietary throughout, and you need the ing to earn money streaming and supports both analog and digital video. Real Player client-side. Although Real with Linux in the has placed some its software under a multimedia industry for quite some time. you are looking for a free solution. Both free license – following the open source Some of the Fluendo team are the core codecs are from the Xiph Foundation [7], trend – this does not include the proprie- developers on the GStreamer project, which aims to implement free alterna- tary codecs. which provides the multimedia infra- tives for today’s patented codecs. Xiph’s Real implements the SMIL standard, structure for GNOME. Fluendo also codec for audio achieves a similar which is useful for rich media presenta- works on licensed technologies, like quality and encoding efficiency to MP3. tions because it can handle streams with DVB and MPEG, and there are plans to You may be more familiar with Vorbis different media types by keeping text as release commercial plugins for the Flu- under its container name, . text and not converting it to video, for motion server in the future. The Xiph developers rely on a gift example. The RealProducer encoder will The free variant still has much to offer from On2 for the video codec. On2 read various video formats and produce for non-trivial streaming projects. Flu- granted Xiph an irrevocable right of use, Real files from them for different band- motion will handle both V4L and DV which covers any and all patent rights. widths. For live streaming, RealProducer input, thus covering most devices. Un- The product of this union is Theora, reads analog video from V4L devices, fortunately, the server is difficult to in- which doesn’t quite achieve the same but it does not support digital DV over stall, with dependencies that include the quality as MPEG4 or H.264, but it can FireWire. GStreamer, GStreamer Python, python- still produce acceptable results at low bi- If you would like to try out Real prod- , and twisted packages in a combina- trates, comparable with Divx 3. Because ucts, you can download the free vari- tion of versions that many distributions you can just ignore the legal issues here, ants, all of which have some restrictions. will not have by default. almost every distribution will include For example, the free Helix server only Flumotion itself comprises the Worker both codecs. supports 20 simultaneous streams. and Manager components as well as an The Windows and Mac platforms can Apple has taken a similar approach administrative front end (Figure 1) along cause headaches, as neither includes the as Real, publishing a free variant of the with a setup wizard. The Worker han- codecs. There is a Directshow implemen- Apple QuickTime streaming server dles encoding and sends video and tation of the Xiph codec for Windows, under the name of Darwin streaming audio data to the Manager component, and the codec will integrate with the server [4]. Darwin does not have the which in turn provides connection han- Windows codec infrastructure [8]. After QuickTime components, but this does dling and streaming services. Unfortu- the install, the codec is available to all not mean the product is entirely useless; nately, the Manager needs a different Window video applications. There is a after all, it can still stream MPEG-4, a port for each stream, which means that QuickTime component [9] for the Mac. codec that achieves good results. the port number will always change de- Fluendo’s Cortado applet, a Java- In contrast to Real, Apple does not pending on the number of streams the based decoder for Vorbis and Theora, have a portfolio of commercial products server is currently broadcasting. Flumo- is a good way to avoid most client-side for Linux or even an encoder. The stan- tion developer, Andy Wingo, has some codec issues. The applet works amaz- dard approach to streaming with the tips in his blog for live streaming, cover- ingly well, bringing smooth streaming Darwin server is to use the MPEG4IP ing everything from the camera to the to less powerful systems (with the ex- suite – written by developers at Cisco – software [6]. ception of the Mac, where it looked more for encoding. Using MPEG4IP or the like slow motion). other popular encoders for Linux (MEn- Theora coder, Transcode, FFmpeg or VLC) helps The free Flumotion product only sup- Icecast you easily create MPEG-4 files from a va- ports a single codec family; on the other As my own streaming solution, I finally riety of video formats. MPEG4IP also has hand, this is your only option anyway if decided on the Icecast server [10]. Ver-

46 ISSUE 77 APRIL 2007 WWW.LINUX - MAGAZINE.COM Video Streaming KNOW-HOW

sion 2 can handle Theora streams. One documentation on the web is now obso- for a while, but don’t hold your breath reason that I made this decision was Ice- lete. for results. cast’s ability to accept encoder streams The same thing can be said of VLC, a at mount points that are accessible via tool described by many as superior to Fun for the Family the same host and port, which is prefera- anything else on Linux. The former vlc- Are Linux users ultimately spoiled for ble to the tangle of ports that the Flumo- server – which many websites still refer choice? Not if you insist on a free tion solution requires. to – has now been ousted by the VLC cli- streaming solution. Your only option for The kind of wizardry that Wingo [6] ent’s streaming option. video streaming is the free Theora codec talks about was unnecessary; a single The VLC client’s GUI is not much in combination with Flumotion or Ice- modification to the Icecast configuration help, and even simple command lines cast, plus ffmpeg2theora. If patents are was all it took to prepare the server for can take up multiple lines, not to men- of no concern, but interoperability is, Theora streaming. Setting up the Flumo- tion the syntax, with its mix of brackets, you might like to investigate the Darwin tion package posed far greater problems, braces, and parentheses. Consider Streaming Server, which can handle live despite (and in part, because of) the ad- whether you prefer an out-of-the-box ap- streams via MPEG4Live. If money is not ministrative GUI. proach that works or would rather have an issue, you might find the perfect ffmpeg2theora [11] is a good choice of hours of fun tinkering with a solution streaming server in the Real product encoder for Icecast. It can create Theora that, in the end, might not turn out to portfolio, and at least there are free (as files from any format that can be superior after all. in beer, if not free as in freedom) clients read. If you write the files to sdout, the for any platform you care to name. ogg_fwd tool can pick them up and send Protocols Check out Table 1 called “Features” for them to the server. Besides using different codecs, the an overview. ■ To read live video from a DV camera, I streaming solutions covered in this arti- used the dvgrab command line tool. This cle use different network protocols. INFO tool provided me with a command line- Thanks to its many years of experience, [1] MPEG License Association: based, but also understandable encoding Real once more has the biggest selection. http:// www. mpegla. com pipeline: The server supports multiple protocols, [2] MainConcept: as do the Real clients, so they should http:// www. mainconcept. com U dvgrab --format raw - | have no trouble talking. By default, Real [3] Real: http:// www. real. com ffmpeg2theora -V 150 -f U components use the proprietary RDT [4] Darwin Streaming Server: -x 320 -y 240 -o U protocol, although the clients also speak http:// developer. apple. com/ darwin/ U /dev/stdout - | oggfwd the RTSP (Real Time Streaming Protocol) projects/ streaming IP address port U standard protocol or RTP (Real Time [5] Flumotion: http:// www. flumotion. net password Protocol), which is particularly useful [6] Andy Wingo, “So you want to stream Mountpoint.ogg for multimedia data. a conference”: http:// wingolog. org/ Of all the servers covered here, the archives/ 2006/ 07/ 07/ While sad-looking icons in the Flumo- Darwin Streaming Server is the only so-you-want-to-stream-a-conference tion interface show that a component is one to support RTP/ RTSP, whereas all [7] Xiph: http:// www. xiph. org not working (and who knows why not), the others rely on HTTP. Unfortunately, [8] Theora Directshow codec: users at least get immediate and intelligi- HTTP is not ideal for streaming; if a gap http:// www. illiminable. com/ ogg ble feedback using this approach. Most occurs due to packet loss, the effect is [9] Theora QuickTime components: issues are caused by incorrect permis- amplified by the fact that lost packets http:// xiph. org/ sion settings for the video device or by are retransmitted. [10] Icecast: http:// www. icecast. org server authentication. It would be preferable to simply ignore Other Linux tools support similar ap- the losses and carry on at the best-possi- [11] ffmpeg2theora: proaches. For example, most transcod- ble speeds. To transmit Ogg/ Theora in http:// www. v2v. cc/ ~j/ ffmpeg2theora ers, like Mencoder, Ffmpeg or Transcode, RTP packets, there is no need for the are capable of sending data to stdout. server to implement RTP; although you For several years Ffmpeg can even handle streaming itself, do need to consider how to encapsulate Oliver was a sysop and programmer at although 20 pages of command line help Ogg in RTP packets. Developers have Ars Electronica Cen- can be daunting, and much of the online been working on a payload specification ter in Linz/Austria. After finishing his Table 1: Features studies in Philoso- Darwin Flumotion Icecast2 Real phy, Linguistics and Codec free? Open, but patented yes yes no Computer Science he became an editor for the Bavarian Broadcasting

Firewire/ DV no yes yes no THEAUTHOR Corporation. Today he is head of the V4L yes yes possible yes Editorial Competence Center for RTP/ RTSP yes no no yes Software and Programming at Linux HTTP yes yes yes yes New Media AG.

WWW.LINUX - MAGAZINE.COM ISSUE 77 APRIL 2007 47