FFmpeg - Encode Vorbis

From PiRho Knowledgebase
Jump to navigationJump to search

This article explains how to encode audio using the libvorbis codec in FFmpeg. It includes the recommended command, quality settings, usable ranges, and how the Vorbis quality scale maps to approximate bitrates.

Overview

Vorbis is an open, patent‑free, lossy audio codec known for good quality at lower bitrates. FFmpeg supports Vorbis encoding through the libvorbis library. This article focuses on the **quality‑based variable bitrate (VBR)** mode, which is the recommended way to encode Vorbis audio.

Basic Encoding Command

Use the following FFmpeg command to encode an audio file to Vorbis:

ffmpeg -i <input.file> -a:c libvorbis -qscale:a 3 <output.file>
  • `-a:c libvorbis` — Selects the Vorbis encoder.
  • `-qscale:a` (or `-q:a`) — Sets audio quality (VBR mode).

Quality Scale ( -qscale:a )

Vorbis uses a **quality scale** instead of fixed bitrates.

  • **Range:** -1.0 to 10.0
  • **Default:** `-q:a 3`
  • **Higher values = higher quality and higher bitrate**

General guidance:

  • Usable range begins around **96 kbps**
  • Recommended range begins around **192 kbps**

Approximate Bitrate Formula

Vorbis does not use fixed bitrates, but the FFmpeg documentation and Vorbis encoder model provide approximate calculations.

The encoder uses the following rules internally:

  • For `q < 4`
 → **Bitrate ≈ 16 × (q + 4)** kbps  
  • For `q < 8`
 → **Bitrate ≈ 32 × q** kbps  
  • For `q ≥ 8`
 → **Bitrate ≈ 64 × (q − 4)** kbps  

Example Values

  • **q=3 →** 16×(3+4) = **112 kbps**
  • **q=5 →** 32×5 = **160 kbps**
  • **q=6 →** 32×6 = **192 kbps**
  • **q=10 →** 64×(10−4) = **384 kbps**

These values are approximations; actual bitrates vary slightly depending on content.

Recommended Settings

Most users will want:

Use Case Recommended q Approx Bitrate
Voice recordings 2–3 ~96–112 kbps
General music 4–5 ~128–160 kbps
High‑quality music 6 ~192 kbps
Archival (lossy) 8–10 ~256–384 kbps

Use `-q:a 6` as a safe high‑quality default for music.

Complete Example

Re‑encode an input file to Vorbis at quality 6:

ffmpeg -i input.wav -c:a libvorbis -q:a 6 output.ogg

Notes

  • Vorbis is intended for **VBR**, not CBR.
  • AAC and Opus tend to outperform Vorbis at low bitrates, but Vorbis remains excellent for music in the 160–192 kbps region.
  • For transparency, quality **q=5–6** is typically enough.

References