|[Home] [Credit Search] [Category Browser] [Staff Roll Call]||The LINUX.COM Article Archive|
|Originally Published: Monday, 8 October 2001||Author: Michael & Melinda Petruzziello|
|Published to: learn_articles_firststep/General||Page: 1/1 - [Std View]|
Notes from the Command-Line Commando: Multimedia
Linux.com irregulars Michael & Melinda Petruzziello return this week with another installment of Command Line Commando, your regular view of working with the Linux command line especially for newer users. This week we take a look at playing music and video on your Linux box, even streaming MP3s from, well, the command line, of course!
Multimedia is a staple of "gooey" interfaces such as RealPlayer, Windows Media Player (sorry!), Winamp, and xmms (aka x11amp). One of the most popular things to do with any computer is to use it to run your CD player, DVD player, video capture card, web cam, et cetera, et cetera, et cetera... Can the Linux command line offer the same functionality? We are here to answer this question with a resounding... "Sort of!"
(The all important questions of "Would we even want it to?" and "WHY would we want it to?" will be answered later in this article.) But first...
Before we tackle the topic of multimedia from the Linux command line, we would like to thank all of you who posted and emailed in response to our previous article on fetchmail. This was our first time publishing an article on the Web, and we enjoyed the nearly instant feedback from those who read the article and liked it (or didn't) so much that they couldn't contain themselves. Thusly, the esteemed Editor-in-Chief of Linux.com was motivated to offer us another shot at entertaining, educating, and extolling the virtues of the Linux command line. Either that, or another shot at reconciling ourselves to the Linux community (depending on your point of view).
Two questions were asked most frequently. The first question was "Why didn't you mention using fetchmail -k?" So that the millions of you who sent us this query can sleep at night, we'll answer you. We don't know. We are aware of the "-k." We frequently use the "-k" ourselves. Sometimes we even eat "Special K" for breakfast while waiting for "fetchmail -k" to download. We believe that originally we mentioned the "-k" in the article, but we suspect that unknown entities, intent on making us look like absolute fools, removed all references of the "-k" from the final copy of the article before it was submitted. For those of you who have no idea what this "-k" is and why we are raving on about it, the "-k " option tells fetchmail to leave a copy of your email on the server, which everyone knows is just about one of the most useful features any email program can have.
The other most frequently asked question was, "Why not just use a 'gooey' mail reader instead of fetchmail?" Our answer to this question is pretty simple. Why would ANYONE want to use ANYTHING that takes you away from the command line??? No, seriously, if you're just checking a single email account and you're using Netscape, Mozilla, or Opera, there really is no particular advantage to using fetchmail. (Unless, of course, you happen to like using the Linux command line as much as we do.) However, as we stated in the previous article, we use fetchmail to check one "catch-all" POP account that receives email for an entire company. We also have used fetchmail to troubleshoot email problems for our clients from our offices by typing in one line at a command prompt instead of reconfiguring an entire "gooey" email client. There are other uses for fetchmail also. It really depends on individual needs and what you want your system to do. And now, on with the show!
You may be saying to yourself right now, "So, you are about to tell me how I can watch high-quality video and listen to stereophonic sound right from my Linux command prompt, right?" You betcha. First, go to your command prompt and type:
(HA! Had you going there for a second, didn't we?)
To be perfectly honest, the "gooey" X interface provides the best means for watching video on your Linux box. RealPlayer or kwintv will do just fine. Oddly enough, however, we have discovered a way for us command-line commando types to actually view video from our beloved command lines. We recently saw posted on our local LUG mailing list a link to
"Oh, great, how cute..." you say. "Now I can make myself look like a bowl of alphabet soup. What about audio from my command line? Eh???" This brings us to the subject of mpg123. By far, this little program is our favorite command line multimedia utility. After all, it allows us to listen to John Tesh MP3s 24/7! Before we begin our discussion of mpg123, some of you may be curious about what kind of machine we have. Our computer and sound gear is a Pentium 233 with 32 MB of RAM, a 4 GB hard drive, and an SBLive! Value card running RedHat 7.1.
Mpg123 is a great utility for playing MP3 music files and streaming audio. Mpg123 supports MPEG Layer 1, 2 and 3, and will play Layer 3 in stereo. Layer 2.5 may also play, but has not been heavily tested. This program allows you to speed up or slow down your mp3s, mix down stereo streams (to use less bandwidth), and even supports playlists.
First, let's check and see if you have mpg123 installed on your system. To do this, go to your command prompt and type:
rpm -q mpg123 <Enter>
If mpg123 is installed, you should see something similar to the following:
If not, you might see:
package mpg123 is not installed
If the reply comes back "package not installed," then you will need to install it. Remember, we are using RedHat 7.1. For us, mpg123 was included on the installation CD. If you are using a different distribution, your mileage may vary. Check your CD, or take a quick look on the web by going to http://www.mpg123.de/. Our instructions should, at least, put you on the right track. ("right track," like a CD, get it? Nevermind...)
The most basic way to play an MP3 file with mpg123 is to go to your command line and type this:
mpg123 songname.mp3 <Enter>
Voila! Music! (And perhaps you thought it couldn't be done!)
Say you want to hear more than one song. To play two songs in a row, type this:
mpg123 songname1.mp3 songname2.mp3 <Enter>
Isn't this fun? If you want to hear 20 songs in a row, just type them out on your command line, every time you want to hear them! (If you think this sounds highly annoying, pay close attention to the next section.)
vi mytunes.m3u <Enter> <i> /home/username/mp3z/myfav/JohnTesh1.mp3 <Enter>
<Esc> :wq <Enter>
A few things to note: You must include the entire path when you specify files in your playlist. We chose to use the .m3u extension for our playlist file because other MP3 players such as xmms support that extension for their playlist files. (Portability is what it's all about, right?) To use your playlist, type this:
mpg123 -@ mytunes.m3u <Enter>
mpg123 will now happily play every file in your playlist until it finishes playing the last one. It is worth noting that if you start up mpg123 and you are not in the directory where you keep your playlist, you will need to specify the path to the directory on the command line, like this:
mpg123 -@ /home/username/mp3z/lists/mytunes.m3u <Enter>
Now, say you have all your MP3 files in a single directory, and you have about 300 or so of them. You're inwardly groaning at the thought of having to type out every single one of those file names into a list. Your mind is racing, trying to think whether you can get grep and awk to do all the work for you... Don't sweat it. If you want mpg123 to play every MP3 in a certain directory, just type this:
mpg123 /home/username/mp3z/*.mp3 <Enter>
Whew! Saved by a wildcard!
<Alt>and function keys to switch over to a fresh command line window and keep right on hackin'. (The fun kind, not the illegal kind!)
There are many mpg123 front-end utilities (wrappers) out there that allow you to visually manipulate your playlists and view song titles and other information about the current file being played. Visual displays, and you don't even need an X server! If you're curious and want to learn more about these wrappers, hop on over to your favorite search engine.
The most basic way to use mpg123 with an audio stream is to do this:
mpg123 http://22.214.171.124:8034 <Enter>
(This is a sample stream we pulled from http://www.shoutcast.com.) Sometimes, you may have to enter a stream address like this:
We usually pull our streams from http://www.live365.com/home/index.live or http://www.shoutcast.com. There are other sites you can get streams from as well. Initially, you will need a browser so you can find audio stream addresses. You can try using lynx (good luck decrypting the address out of that nightmarish output), but the best way to figure out what address your favorite stream is from is to use a "gooey" browser like Netscape, Mozilla, etc.
There are many other command line options available beyond those we've mentioned here. For instance, you can change your buffer size for your stream, or mix down a stereo stream to mono for better performance. You can also speed up or slow down the play rate for your mp3 files. For details on these options, and many more, type:
mpg123 --longhelp <Enter>
man mpg123 <Enter>
at the command prompt.
Well, we hope that was useful and informative; we aim to please. Wait! Harken! Never mind; that was it. If you enjoyed this article and/or found it useful, tune in next time to find out more wonderful, exciting, earth-shattering ways to make the most of your command line. No "gooey" needed!
(c) October 2001, Michael & Melinda Petruzziello email@example.com; firstname.lastname@example.org