LinuxCommandLibrary

mpg321

Play audio files from the command line

TLDR

Play an audio source exactly n times (0 means forever)

$ mpg321 [[-l|--loop]] [n] [path/to/file_a|URL path/to/file_b|URL ...]
copy

Play a directory recursively
$ mpg321 -B [path/to/directory]
copy

Enable Basic Keys ( * or / - Increase or decrease volume, n - Skip song, m - Mute/unmute.) while playing
$ mpg321 -K [path/to/file_a|URL path/to/file_b|URL ...]
copy

Play files randomly until interrupted
$ mpg321 [[-Z|--random]] [path/to/file_a|URL path/to/file_b|URL ...]
copy

Shuffle the files before playing them once
$ mpg321 [[-z|--shuffle]] [path/to/file_a|URL path/to/file_b|URL ...]
copy

Play all files in the current directory and subdirectories, randomly (until interrupted), with Basic Keys enabled
$ mpg321 -B [[-Z|--random]] -K .
copy

SYNOPSIS

mpg321 [OPTIONS] <file(s) | URL(s)>
mpg321 [OPTIONS] -C
mpg321 [OPTIONS] -L <playlist_file>

PARAMETERS

-h, --help
    Displays a help message and exits.

-q, --quiet
    Suppresses most messages during playback.

-v, --verbose
    Increases verbosity, printing more information.

-g <gain>, --gain <gain>
    Sets the audio gain factor (e.g., 50 for 50%).

-s, --stdout
    Writes raw PCM audio output to standard output.

-w <file>, --wav <file>
    Writes the decoded audio to a specified WAV file instead of playing it.

-o <driver>, --output <driver>
    Specifies the audio output driver (e.g., alsa, oss, pulse).

-a <device>, --audiodevice <device>
    Specifies the audio device to use (e.g., hw:0,0 for ALSA).

-Z, --shuffle
    Shuffles the order of files when playing multiple inputs.

-C, --control
    Enables interactive control mode via keyboard input during playback.

-L <file>, --list <file>
    Plays files listed in the specified playlist file.

-l <count>, --loop <count>
    Loops the playback for the specified number of times (0 for infinite).

DESCRIPTION

mpg321 is a lightweight, command-line MP3 player for Unix-like operating systems. It was initially developed as a free and open-source alternative to the popular mpg123 player during a period when mpg123 faced patent licensing issues related to MP3 decoding. Built for efficiency and simplicity, mpg321 allows users to play MP3 audio files directly from the terminal, making it ideal for servers, embedded systems, or scripts where a graphical interface is not available or desired.

It supports playing single files, multiple files, directories, or playlists, and can output audio through various drivers like ALSA, OSS, or PulseAudio, depending on its compilation. While mpg321 served a vital role in the free software community, mpg123 has since become free itself, leading to mpg321 often being a symbolic link or a slightly modified wrapper around mpg123 on modern systems.

CAVEATS

On many modern Linux distributions, mpg321 is often a symbolic link to mpg123 or a wrapper around it, meaning their behavior and options can be identical. Its interactive control features are minimal compared to GUI players. Proper audio driver configuration is essential for playback.

INTERACTIVE PLAYBACK CONTROL

When running mpg321 in control mode (e.g., with the -C option), it provides interactive keyboard controls. Users can typically pause/resume ('p'), stop ('s'), seek forward/backward, and adjust volume ('+'/'-') directly from the terminal during playback.

AUDIO OUTPUT DRIVERS

mpg321 supports various audio output drivers, such as ALSA (Advanced Linux Sound Architecture), OSS (Open Sound System), and PulseAudio. The desired driver can often be specified using the -o or --output option, allowing flexibility in audio routing based on system configuration and installed libraries.

HISTORY

mpg321 emerged as a significant project within the free software community, specifically created as a direct response to patent licensing restrictions that affected the original mpg123 player. During the era when MP3 decoding patents were actively enforced, mpg123 was distributed under a restrictive license. mpg321 offered a crucial, fully open-source alternative, ensuring users could play MP3s without legal encumbrances.

With the expiration of the key MP3 patents, mpg123 was subsequently re-licensed under the LGPL, becoming free itself. Consequently, the distinct need for mpg321 diminished, and on many contemporary Linux distributions, mpg321 is often installed as a symbolic link to mpg123 or as a minimal wrapper, reflecting its historical significance and current integration.

SEE ALSO

mpg123(1), mplayer(1), aplay(1), sox(1)

Copied to clipboard