Tải bản đầy đủ (.pdf) (14 trang)

Playing with Multimedia

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (288.83 KB, 14 trang )

Playing with Multimedia
There’s no need to go to a GUI tool, if all you need
to do is play a song or convert an image or audio
file to a different form. There are commands for
working with multimedia files (audio or images)
that are quick and efficient if you find yourself
working from the shell. And if you need to manip-
ulate batches of multimedia files, the same com-
mand you use to transform one file can be added
to a script to repeat the process on many files.
This chapter focuses on tools for working with
audio and digital image files from the shell.
Working with Audio
There are commands available for Linux systems
that can manipulate files in dozens of audio for-
mats. Commands such as
ogg123
,
mpg321
, and
play
can be used to listen to audio files. There
are commands for ripping songs from music CDs
and encoding them to store efficiently. There are
even commands to let you stream audio so any-
one on your network can listen to your playlist.
Playing Music
Depending on the audio format you want to play, you can choose from
several command line players for Linux. The
play
command (based on


the
sox
facility, described later), can play audio files in multiple, freely
available formats. You can use
ogg123
to play popular open source music
formats, including Ogg Vorbis, Free Lossless Audio Codec (FLAC), and
Speex files. The
mpg321
player, which is available via third-party RPM
repositories, is popular for playing MP3 music files.
IN THIS CHAPTER
Playing music with
play, ogg123, and
mpg321
Adjusting audio with
alsamixer and aumix
Ripping music CDs
with cdparanoia
Encoding music with
oggenc, flac, and lame
Streaming music with
icecast and ices
Converting audio files
with sox
Transforming digital
images with convert
82935c06.qxd:Toolbox 10/29/07 1:32 PM Page 109
The
play

command requires the sox package. Install it with the following command:
$ sudo apt-get install sox
Type
sox -h
to see audio formats and effects available to use with
play
:
$ sox -h
...
Supported file formats: 8svx aif aifc aiff aiffc al alsa au auto avr cdda cdr
cvs cvsd dat dvms fssd gsm hcom ima ircam la lu maud nist nul null ogg ossdsp
prc raw s3 sb sf sl smp snd sndt sou sph sw txw u3 u4 ub ul uw vms voc vorbis
vox wav wve xa
Supported effects: allpass band bandpass bandreject bass chorus compand dcshift
deemph dither earwax echo echos equalizer fade filter flanger highpass lowpass
mcompand mixer noiseprof noisered pad pan phaser pitch polyphase repeat resample
reverb reverse silence speed stat stretch swap synth treble tremolo trim vibro
vol
The
play
command uses the sox code to play sounds.
Here are some examples of playing files using
play
:
$ play inconceivable.wav Play WAV file (may be ripped from CD)
$ play *.wav Play all WAV files in directory (up to 32)
$ play hi.au vol .6 AU file, lower volume (can lower distortion)
$ play -r 14000 short.aiff AIFF, sampling rate of 14000 hertz
To play Ogg Vorbis files, install the vorbis-tools package. Here are examples for play-
ing Ogg Vorbis (

www.vorbis.com/
) files with
ogg123
:
$ ogg123 mysong.ogg Play ogg file
$ ogg123 /usr/share/example-content/ubuntu\ Sax.ogg Play example file
$ ogg123 Play web address
$ ogg123 -z *.ogg Play files in pseudo-random order
$ ogg123 /var/music/ Play songs in /var/music and sub dirs
$ ogg123 -@ myplaylist Play songs from playlist
A playlist is simply a list of directories or individual Ogg files to play. When a directory
is listed, all Ogg files are played from that directory or any of its subdirectories. When
playing multiple files, press Ctrl+c to skip to the next song. Press Ctrl+c twice to quit.
To use the
mpg321
player to play MP3 files, you need to install the mpg321 package.
Here are examples for playing MP3 audio files with
mpg321
:
$ mpg321 yoursong.mp3 Play MP3 file
$ mpg321 -@ mp3list Play songs from playlist of MP3s
$ cat mp3list | mpg321 -@ - Pipe playlist to mpg321
$ mpg321 -z *.mp3 Play files in pseudo-random order
$ mpg321 -Z *.mp3 Same as -z, but repeat forever
Chapter 6: Playing with Multimedia
110
82935c06.qxd:Toolbox 10/29/07 1:00 PM Page 110
An mpg321 playlist is simply a list of files. You can produce the list using a simple
ls
command and directing the output to a file. Use full paths to the files, unless you plan

to use the list from a location from which relative paths make sense.
Adjusting Audio Levels
The command line audio tools you use to enable audio devices and adjust audio levels
depend on the type of audio system you use. Advanced Linux Sound Architecture
(ALSA) is the sound system used by most Linux systems these days. The Open Source
Sound System (OSS) has been around longer and is still used on older hardware. In gen-
eral, you can use
alsamixer
to adjust sound when ALSA is used and
aumix
with OSS.
ALSA is the default sound system for many Linux systems. By adding loadable
modules that enable OSS device interfaces to work as well, audio applications that
require the OSS device interface can work with ALSA as well. To see if OSS modules
are loaded, such as
snd-pcm-oss
(emulates
/dev/dsp
and
/dev/audio
),
snd-mixer-
oss
(emulates
/dev/mixer
), and
snd-seq-oss
(emulates
/dev/sequencer
), type:

# lsmod | grep snd
If the modules are loaded, you can use
alsamixer
to adjust audio levels for OSS sound
applications. Start alsamixer as follows:
$ alsamixer Show alsamixer screen with playback view
$ alsamixer -V playback Show only playback channels (default)
$ alsamixer -V all Show with playback and capture views
$ alsamixer -c 1 Use alsamixer on second (1) sound card
Volume bars appear for each volume channel. Move right and left arrow keys to
highlight different channels (Master, PCM, Headphone, and so on). Use the up and down
arrow keys to raise and lower the volume on each channel. With a channel high-
lighted, press m to mute or unmute that channel. Press the spacebar on a highlighted
input channel (Mic, Line, and so on) to assign the channel as the capture channel (to record
audio input). To quit alsamixer, press Alt+q or the Esc key. Press Tab to cycle through
settings for Playback, Capture, and All.
The
aumix
audio mixing application (for which you need to install the aumix package)
can operate in screen-oriented or plain command mode. In plain text you use options
to change or display settings. Here are examples of
aumix
command lines:
$ aumix -q Show left/right volume and type for all channels
$ aumix -l q -m q List current settings for line and mic only
$ aumix -v 80 -m 0 Set volume to 70% and microphone to 0
$ aumix -m 80 -m R -m q Set mic to 80%, set it to record, list mic
$ aumix With no options, aumix runs screen-oriented
When run screen-oriented,
aumix

displays all available audio channels. In screen-
oriented mode, use keys to highlight and change displayed audio settings. Use PageUp,
111
Chapter 6: Playing with Multimedia
82935c06.qxd:Toolbox 10/29/07 1:00 PM Page 111
PageDown, and the up arrow and down arrow keys to select channels. Use the right
or left arrow key to increase or decrease volume. Type m to mute the current channel.
Press the spacebar to select the current channel as the recording device. If a mouse is
available, you can use it to select volume levels, balance levels, or the current record-
ing channel.
Ripping CD Music
To be able to play your personal music collection from Linux, you can use tools such
as
cdparanoia
to rip tracks from music CDs to WAV files on your hard disk. The
ripped files can then be encoded to save disk space, using tools such as
oggenc
(Ogg
Vorbis),
flac
(FLAC), or
lame
(MP3).
NOTE There are some excellent graphical tools for ripping and encoding CDs,
such as
grip
and
sound-juicer
. Because they are CDDB-enabled, those tools
can also use information about the music on the CD to name the output files (artist,

album, song, and so on). This section, however, describes how to use some of the
underlying commands to rip and encode CD music manually.
Using
cdparanoia
, you can check that your CD drive is capable of ripping Compact
Disc Digital Audio (CDDA) CDs, retrieve audio tracks from your CD drive, and copy
them to hard disk. Start by inserting a music CD in your drive and typing the following:
$ cdparanoia -vsQ
...
Checking /dev/cdrom for cdrom...
Checking for SCSI emulation...
Checking for MMC style command set...
Verifying CDDA command set...
...
Table of contents (audio tracks only):
track length begin copy pre ch
===========================================================
1. 18295 [04:03.70] 0 [00:00.00] no no 2
2. 16872 [03:44.72] 18295 [04:03.70] no no 2
...
11. 17908 [03:58.58] 174587 [38:47.62] no no 2
12. 17342 [03:51.17] 192495 [42:46.45] no no 2
TOTAL 209837 [46:37.62] (audio only)
The snipped output shows
cdparanoia
checking the capabilities of
/dev/cdrom
,
looking for SCSI emulations and MMC command set support, and verifying that the
drive can handle CDDA information. Finally, it prints information about each track.

Here are examples of
cdparanoia
command lines for ripping a CD to a hard drive:
$ cdparanoia -B Rip tracks as WAV files by track name
$ cdparanoia -B -- “5-7” Rip tracks 5-7 into separate files
$ cdparanoia -- “3-8” abc.wav Rip tracks 3-8 to one file (abc.wav)
112
Chapter 6: Playing with Multimedia
82935c06.qxd:Toolbox 10/29/07 1:00 PM Page 112
$ cdparanoia -- “1:[40]-” Rip tracks 1 from 40 secs in to end of the CD
$ cdparanoia -f -- “3” Rip track 3 and save to AIFF format
$ cdparanoia -a -- “5” Rip track 5 and save to AIFC format
$ cdparanoia -w -- “1” my.wav Rip track 1 and name it my.wav
Encoding Music
After a music file is ripped from CD, encoding that file to save disk space is usually
the next step. Popular encoders include
oggenc
,
flac
, and
lame
, for encoding to Ogg
Vorbis, FLAC, and MP3 formats, respectively.
With
oggenc
, you can start with audio files or streams in WAV, AIFF, FLAC, or raw
format and convert them to Ogg Vorbis format. Although Ogg Vorbis is a lossy for-
mat, the default encoding from WAV files still produces very good quality audio and
can result in a file that’s about one-tenth the size. Here are some examples of
oggenc

:
$ oggenc ab.wav Encodes WAV to Ogg (ab.ogg)
$ oggenc ab.flac -o new.ogg Encodes FLAC to Ogg (new.ogg)
$ oggenc ab.wav -q 9 Raises encoding quality to 9
By default, the quality (
-q
) of the
oggenc
output is set to 3. You can set the quality to
any number from -1 to 10 (including fractions such as 5.5).
$ oggenc NewSong.wav -o NewSong.ogg \
-a Bernstein -G Classical \
-d 06/15/1972 -t “Simple Song” \
-l “Bernsteins Mass” \
-c info=”From Kennedy Center”
The command just shown converts
MySong.wav
to
MySong.ogg
. The artist name is
Bernstein and the music type is Classical. The date is June 15, 1972, the song title is
Simple Song and the album name is Bernsteins Mass. A comment is From Kennedy
Center. The backslashes aren’t needed if you just keep typing the whole command on
one line. However, if you do add backslashes, make sure there are no spaces after the
backslash.
The preceding example adds information to the header of the resulting Ogg file. You
can see the header information, with other information about the file, using
ogginfo
:
$ ogginfo NewSong.ogg

Processing file “NewSong.ogg”...
...
Channels: 2
Rate: 44100
Nominal bitrate: 112.000000 kb/s
User comments section follows...
info=From Kennedy Center
title=Simple Song
113
Chapter 6: Playing with Multimedia
82935c06.qxd:Toolbox 10/29/07 1:00 PM Page 113

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×