FFmpeg - Encode Opus

From PiRho Knowledgebase
Jump to navigationJump to search

Opus is a modern, low‑latency, high‑quality audio codec designed for both speech and music. It adapts extremely well across a wide range of bitrates, and FFmpeg provides first‑class support through the **libopus** encoder.

This article covers the essential usage pattern for encoding Opus audio using FFmpeg, along with recommended settings, practical notes, and references for further reading.

Basic Usage

To encode an audio file to Opus at a transparent quality level:

ffmpeg -i <input.file> -c:a libopus -b:a 128k <output.file>

Explanation:

  • `-c:a libopus` — use the Opus audio encoder
  • `-b:a 128k` — target ~128 kbps (VBR by default)
  • Opus uses variable bitrate automatically unless explicitly forced to CBR

Why 128 kbps?

Opus is extremely efficient. According to the Xiph.Org Foundation’s recommended settings, Opus at ~128 kb/s VBR is considered "pretty much transparent" for most listeners and most material types.

This makes 128k a safe, high‑quality default for music, mixed audio, spoken word, and general-purpose encoding.

Additional Useful Options

Force Constant Bitrate (CBR)

ffmpeg -i input.wav -c:a libopus -b:a 128k -vbr off -compression_level 10 output.opus

Reduce Bitrate

ffmpeg -i input.wav -c:a libopus -b:a 64k output.opus

Preserve Metadata

ffmpeg -i input.flac -c:a libopus -b:a 128k -map_metadata 0 output.opus

Practical Notes

  • Opus prefers 48 kHz sampling internally; FFmpeg resamples automatically.
  • Opus is designed for low latency, but FFmpeg’s defaults favour quality.
  • `.opus` is the recommended container; `.ogg` also supported but less common.

References