opusenc
Encode audio files into Opus format
TLDR
Convert WAV to Opus using default options
Convert stereo audio at the highest quality level
Convert 5.1 surround sound audio at the highest quality level
Convert speech audio at the lowest quality level
SYNOPSIS
opusenc [options] input_filename output_filename
opusenc [options] --raw-input --raw-rate Hz --raw-channels N [--raw-endianness endianness] input_filename output_filename
PARAMETERS
input_filename
The path to the input audio file. Supported formats typically include WAV, AIFF, FLAC, and Ogg/Vorbis, handled via libsndfile. Use '--raw-input' for raw PCM data.
output_filename
The path where the encoded Opus audio file will be saved. The file will have an '.opus' extension by convention.
--raw-input
Treat the input file as raw (unheadered) PCM samples. Requires additional options like '--raw-rate' and '--raw-channels'.
--raw-rate Hz
When using '--raw-input', specifies the sampling rate of the raw input in Hertz (e.g., 48000).
--raw-channels N
When using '--raw-input', specifies the number of channels (1 for mono, 2 for stereo) of the raw input.
--raw-endianness endianness
When using '--raw-input', specifies the byte order of the raw input. Common values are 'little' or 'big'.
--bitrate N
Sets the target average bitrate for encoding in kilobits per second (kb/s). Valid range typically 6-510. The default is usually 64 kb/s per channel.
--vbr
Enables Variable Bit Rate (VBR) encoding. This is the default mode and aims for a consistent quality level by varying the bitrate.
--cvbr
Enables Constrained Variable Bit Rate (CVBR) encoding. Similar to VBR but with stricter bitrate limits, useful for network streams with bandwidth constraints.
--cbr
Enables Constant Bit Rate (CBR) encoding. Maintains a fixed bitrate throughout the audio, often at the cost of quality variability.
--framesize ms
Sets the frame size (packet duration) in milliseconds. Typical values are 2.5, 5, 10 (default), 20, 40, or 60. Smaller framesizes lead to lower latency but higher overhead.
--comp N
Sets the complexity level of the encoder, from 0 (lowest complexity, fastest) to 10 (highest complexity, slowest, best quality). Default is usually 10 for general audio.
--application type
Specifies the intended application type for optimization. Valid values are 'voip' (for speech), 'audio' (for general music/audio, default), or 'lowdelay' (for ultra-low latency, sacrifices some quality).
--downmix-mono
Downmixes stereo input audio to a single mono channel before encoding.
--gain dB
Adjusts the input audio gain by the specified decibel (dB) value before encoding. Can be positive or negative.
--title string
Adds a 'TITLE' comment tag to the output Opus file metadata.
--artist string
Adds an 'ARTIST' comment tag to the output Opus file metadata.
--comment tag=value
Adds a custom comment tag to the output Opus file metadata. Can be used multiple times for different tags.
DESCRIPTION
opusenc is the command-line utility for encoding audio into the highly versatile Opus interactive audio codec format. Developed by the Xiph.Org Foundation and standardized by the IETF (RFC 6716), Opus is a royalty-free, open, and extremely flexible codec capable of handling various audio types, from high-fidelity music to low-bitrate speech.
opusenc takes various input audio formats, typically through libsndfile, such as WAV, AIFF, FLAC, and Ogg/Vorbis, and converts them into Opus. Its strengths lie in providing excellent quality across a wide range of bitrates (6 kb/s to 510 kb/s), low algorithmic delay, and high resilience to packet loss, making it ideal for real-time applications like Voice over IP (VoIP), video conferencing, and live streaming, as well as general audio storage and playback. It is part of the official opus-tools package.
CAVEATS
opusenc primarily relies on libsndfile for input file format support. While common formats like WAV, AIFF, and FLAC are generally supported, less common or proprietary formats (e.g., some MP3 variants directly) might not be. For such cases, pre-conversion using tools like ffmpeg might be necessary.
When encoding, there's a fundamental trade-off between bitrate, quality, and algorithmic delay. Selecting appropriate parameters (e.g., '--bitrate', '--framesize', '--application') is crucial for achieving desired results for specific use cases.
SUPPORTED INPUT FORMATS
By default, opusenc leverages libsndfile to support a wide array of uncompressed and lossless audio formats including WAV, AIFF, AU, FLAC, and unheadered raw PCM data. Support for compressed formats like Ogg/Vorbis is also often available. For other formats (e.g., MP3, AAC), you might need to pipe output from a converter like ffmpeg.
ENCODING MODES
opusenc offers flexible encoding modes:
VBR (Variable Bit Rate): Default mode, optimizes for perceptual quality by varying bitrate. Ideal for general audio where quality is paramount.
CVBR (Constrained Variable Bit Rate): Similar to VBR but with a stricter upper bound on bitrate, suitable for bandwidth-limited streaming.
CBR (Constant Bit Rate): Maintains a fixed bitrate throughout the audio, useful for predictable bandwidth usage, though it may sacrifice quality peaks.
APPLICATION TYPES
The '--application' option fine-tunes the encoder for specific scenarios:
'voip': Optimized for speech, prioritizing clarity and robustness for communication.
'audio': Default for general audio, balanced for music and mixed content.
'lowdelay': Minimizes latency by using smaller frame sizes and simpler encoding, suitable for real-time interactive applications where delay is critical.
HISTORY
The Opus audio codec was developed collaboratively by the Xiph.Org Foundation and others, with significant contributions from Mozilla, Skype (Microsoft), and Google. It was standardized by the Internet Engineering Task Force (IETF) as RFC 6716 in September 2012, making it an open and royalty-free standard. opusenc is the official command-line encoder, part of the opus-tools package, which provides a reference implementation for encoding and decoding Opus audio. Its development closely tracks the evolution and adoption of the Opus codec itself, becoming a cornerstone for high-quality, low-latency audio in web communication, streaming, and more general audio applications.