ONLamp.com    
 Published on ONLamp.com (http://www.onlamp.com/)
 See this if you're having trouble printing code examples


FreeBSD Basics Playing Audio and Video Files with FreeBSD

by Dru Lavigne
10/17/2002

In the last few articles, I've concentrated on configuring a FreeBSD system and various applications suited for multimedia. I'll wrap up that series today by tweaking a browser's plug-in support and installing some applications which can be either called by a browser or used on their own.

One of the first things you'll notice if you're new to surfing the web from a Unix system is the lack of "automagic" support for the various audio and video formats splattered throughout the pages of Cyberspace. Do keep in mind that Unix is designed for the roll-your-own crowd who like to do their own customizations. Over time, I've configured my browser to display just about anything I come across on the Net. I've even learned a few things about multimedia and MIME types along the way.

If, like myself, you're using Mozilla as your browser, follow along as I demonstrate the configurations. If you're using Netscape, I recommend the XSwallow site as a good starting point for your own customizations. xswallow is designed to augment Netscape's plug-in support. It may also be found in the www section of the ports collection.

Also in FreeBSD Basics:

Fun with Xorg

Sharing Internet Connections

Building a Desktop Firewall

Using DesktopBSD

Using PC-BSD

In a previous article,Turn FreeBSD into a Multimedia Workstation, I installed the plugger port which integrates plug-in support into the Mozilla browser. In practice, I've found that this allows Mozilla to play just about every audio format I've come across on the Web: mid, midi, mod, mp2, mp3, mpa, sid, au, snd, and wav. It also adds support for text formats, meaning I can display pdf, rtf, and doc files, which is very handy as I do a lot of research on the Internet and constantly come across tech papers in these formats.

The plugger port also supports several audio/video formats, but not all of them. This is where things get a little more interesting. Many of these formats are proprietary and the codes (and even the extensions for the files) tend to change every time the vendor releases a new, improved player.

For example, here are some popular formats and the extensions you could expect to find with each:

An interesting oddity is the avi extension which is shared by three different formats. An avi file might be a Quicktime video or a DivX video. While both of these formats deliver high quality video, they use very different and proprietary compression methods. It's also possible that an avi file might simply be a lower quality video using the Microsoft avi standard. In the case of avi, it isn't the extension that is important, but rather what the file purports to be. If it is Quicktime, it will say so and will require a viewer capable of playing the Quicktime standard. If it is DivX, it will say so and will require a viewer capable of playing the DivX standard.

The Windows media formats are yet another exercise in fun. As Microsoft improves on its video technologies, it releases new compression methods using new file extensions. New file formats require new versions of a proprietary player which understands those new formats.

Confused yet? Let's see if we can find some players for your FreeBSD system that can play all of the formats you're likely to run across on the Internet. It's always nice to have a testing site when experimenting with players. This Microsoft site even includes explanations of the various file types.

To augment plugger's audio/video support, I'll install three more applications from the ports collection: realplayer, divxplayer, and netshow. Each of these applications can be used as stand-alone players. They can also be called by Mozilla to play files directly from the browser.

The following chart shows which extensions I've successfully been able to play through Mozilla and which application provided the necessary support:

program	      mov  avi  mp4  rm  ram  mpg  mp3  m3u  asf  asx  wma  wmv

plugger        X    X                  X    X    X 
realplayer                   X    C         X    C 
divxPlayer     X    X   X 
netshow                                               ?         ?     ?

The C means choppy; I found that realplayer spent a lot of time buffering RAM and m3u files when played directly over the Internet. Your mileage will probably vary depending upon the speed of your Internet connection. However, plugger seemed to buffer m3u files nicely and played without choppiness. If I downloaded a RAM file and then played it through realplayer, it played without choppiness. I'll explain the ? in the chart when I describe the netshow port.

Let's start with the realplayer port. In order to install this port, you must first verify that your system is running Linux emulation:

$ pkg_info | grep linux
linux_base-7.1_1    The base set of packages needed in Linux mode

If you don't receive this output, install the Linux base:

$ cd /usr/ports/emulators/linux_base
$ make install clean

If you're running an older version of the Linux base, remove the old version before installing the latest version:

$ pkg_delete linux_base-"yournumber"

Replace "yournumber" with whatever version you received when you ran the above pkg_info command. Better yet, if you have learned how to use cvsup and portupgrade, let portupgrade upgrade the port for you.

Once you have the latest Linux base, you can install realplayer. This utility does have license restrictions, so first visit the Real.com website. You'll be prompted to fill in a short registration form. When you choose your OS, select Linux 2.x(libc6 i386) RPM and save your download to: /usr/ports/distfiles/rp8_linux20_libc6_i386_cs2_rpm. Then:

$ cd /usr/ports/audio/linux-realplayer
$ make install clean

Once you've installed the port, exit the superuser account and as your regular user:

$ cd /usr/local/lib/RealPlayer8
$ ./mimeinstall.sh
$ ./pluginstall.sh

The executable will be installed to /usr/local/bin/realplay. If you already have a Window Manager open when you install realplayer, close it and restart it before using the program for the first time.

This utility can be used as a stand-alone player that supports several file formats: rm, ram, mp3, and m3u. If you've never used it before, the Real.com channel list is a good place to start your experimentations.

If you have a fast Internet connection, you can play files directly over the Internet. Otherwise, save the file to disk and then use realplayer to play it.

Next, I'll install the DivX player. Again, note that this port requires the latest Linux base in order to install.

$ /usr/ports/graphics/linux-divxplayer 
$ make install clean

The executable will be installed to /usr/X11R6/bin/divxPlayer. The "P" in the filename is case-sensitive. This player can be used as a stand-alone player for movies that you have downloaded and saved to disk. When downloading the movie, it may have an avi, mov, or mp4 extension. Make sure that it was advertised as a DivX movie as this player will hang if you try to use it to play a Quicktime movie. On my system, I've made separate directories called DivX and Quicktime, so I remember which movies are which.

To get you started on DivX movies, try these sites:

http://www.divx.com/movies/
http://www.divxmovies.com/trailers/

If you're using the plugger port, it also plays DivX movies. This means if you click on a movie link, the movie will play in your browser. If you want to instead download the movie to play it later with divxPlayer, right click on the link and choose "Save link target as." Remember to save it to remember that it is a DivX movie.

Sometimes you'll come across zipped movies. For example, all of the trailers at divxmovies.com are zipped. You won't be able to play a zipped movie directly from the browser, and you'll have to unzip it before you can play it with divxPlayer. Even though the movies will have a zip extension, you can still unzip it from your FreeBSD system using the unzip utility. You may already have this utility if you've installed a port that uses it. To see if you do, use this command:

$ pkg_info | grep unzip
unzip-5.50          List, test and extract compressed files in a ZIP archive

If you don't get any results back, install the utility like so:

$ /usr/ports/archivers/unzip
$ make install clean

Now, whenever you need to unzip a file with a zip extension, simply do this:

$ unzip name_of_file.zip

Finally, the netshow port:

$ cd /usr/ports/graphics/netshow
$ make install clean

The executable will be installed to /usr/X11R6/bin/netshow. This player is intended to play Windows media file formats. Now, why did I put question marks in my chart? I think I didn't have any problems playing these files as netshow didn't complain. It told me it was buffering, and the little slider bar dutifully informed me how much of the file it was playing. However, the video consisted of a line about 1 mm wide. I assume that line should have been a larger screen displaying the video. And there was no audio. Now, this is the same computer that mplayer didn't like, so perhaps your mileage will vary. I'd be interested in hearing your experiences with this application.

Now, let's take a look at MIME types. In order to configure any browser to call another application to play a file, you need to know which MIME type is associated with which file extension. This chart shows both for the formats realplay and netshow are capable of playing:

MIME type		  File Extension	Application to use

audio/x-pn-realaudio	  ram			/usr/local/bin/realplay
video/x-ms-asf		  asf			/usr/X11R6/bin/netshow
video/x-ms-wmv		  wmv			/usr/X11R6/bin/netshow

To configure Mozilla, go to the Edit menu->Preferences->Helper Applications, then click on the "New Type" button. In my case, I'll create three new types, one for each line in the above chart.

When creating your own types, choose a description that is useful to you, then fill in the remaining fields using the information from the above chart. By default, Mozilla will prompt to open using your specified application whenever you encounter an associated file type. If you don't want to receive that prompt, highlight your type, then go into Edit and uncheck the "ask me before opening" option.

A couple of notes before leaving the Mozilla browser. The plugger application will play both Quicktime and DivX movies. Between plugger and divxPlayer, I've never had any problems playing a DivX movie. However, I've had mixed success with Quicktime movies. plugger supports the older mov and qt formats, but not the new Quicktime avi format. Most of the Quicktime trailers on the Internet, and everything at Apple's Quicktime site uses the new format. As of this writing, there aren't any workable ports in the ports collection that will play the latest Quicktime format.

I'd like to end this article with one of my favorite applications from the ports collection. I always build this one on my workstations:

$ cd /usr/ports/graphics/chbg
$ make install clean

The executable will be installed to /usr/X11R6/bin/chbg. Information on chbg, including screenshots of all of the configuration screens, can be found at the ChBg home page.

I have a very large collection of favorite pictures that I've collected over the years, and it still never ceases to amuse me whenever I walk by one of my computers and notice that chbg is displaying my collection as an ever-changing slideshow.

I tend to use chbg as a screensaver though it supports several other modes in its Mode tab. Once you've chosen a mode, click on the Picture list tab-> Append pictures button. In my case, I've made a subdirectory in my home directory to store my pictures. Once I've chosen this directory, I can then click on the Select All button.

In the Setup tab, you can choose whether or not to randomize the picture order and can select the speed at which the picture change will occur. To set how often the pictures will change, input a time interval in the Properties tab. This tab also lets you decide whether to tile or to center the picture.

My favorite tab is the Effects tab as chbg supports many effects. The easiest way to test an effect is to select screensaver mode then click the button "run with actual settings." You can quickly scroll through the various effects and see which ones appeal to your taste. If you'd like randomized effects or can't make up your mind on which effect to use, use the Random effects tab to select the effects that interest you.

Once you've customized your settings, you can save these as a scenario by clicking on the save scenario button. You can give your scenario whatever name you like and open it at any time using the open scenario button. You can also use this method to save as many scenarios as you like.

I hope you have enjoyed the multimedia series. The next few articles will cover the subject of VPNs. This topic comes up often on the mailing lists and is probably the most commonly asked question I get asked in private emails. The next article will cover the basic cryptographic terms you need to be familiar with in order to understand how a VPN operates. Then I'll move on to demonstrating some of the applications which can provide VPN support between FreeBSD systems and other systems.

Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.


Read more FreeBSD Basics columns.

Return to the BSD DevCenter.


Copyright © 2009 O'Reilly Media, Inc.