A library and application for lossless, format-preserving, two-pass optimization and repair of Vorbis data, reducing its size without altering any audio information.
# π Overview
OptiVorbis does lossless optimizations and repairs of complete, seekable Vorbis I audio streams, usually contained in Ogg Vorbis (`.ogg`) files, as defined in the [Vorbis I specification](https://xiph.org/vorbis/doc/Vorbis_I_spec.pdf).
The optimization is _lossless_: streams processed by this library are guaranteed to be decoded to the same audio samples as before by any sane decoder. The internal file structure may differ substantially, but these differences are transparent for end-users, as the resulting streams still conform to the specification.
In addition, OptiVorbis' understanding of the Vorbis format and container encapsulations, combined with the somewhat more lenient, purpose-built parsers it uses, provide it with some repair capabilities. It also tends to output more detailed and actionable error information on failure than other tools, rendering it suitable for sanity-checking Vorbis streams.
Currently, OptiVorbis optimizes Ogg Vorbis streams in the following ways, leveraging the great flexibility provided by the Vorbis I specification. Some of these require doing two passes over the entire Vorbis stream:
- It determines the usage frequency of the symbols defined for each codebook and computes a mathematically optimal codeword assignment for them, minimizing the expected bit cost per symbol by using the Huffman algorithm described in [this paper](https://dl.acm.org/doi/10.1145/3342555).
- It encapsulates Vorbis packets into Ogg pages as tightly as possible. Conventional encoders better support network live-streaming scenarios by stuffing fewer packets per page, but this is not an issue with files.
- It removes all padding at the end of Vorbis packets and after Ogg pages: the reference encoder may pad audio packets with extra bytes when under extreme pressure to meet a minimum bitrate and using its bitrate management engine.
- It strips out non-Vorbis logical bitstreams, such as Ogg skeleton metadata. Depending on the options selected, it may strip the vendor string and user comments in the Vorbis comment header.
- It drops audio packets that should be discarded (i.e., zero-sized).
- At the user's discretion, it may shorten or clear out Vorbis header metadata that is not relevant to audio playback. This metadata is composed of the encoder vendor string and user comment fields.
# π₯ Installation
OptiVorbis is officially distributed in three ways:
- Within the project demo web page.
- As a command-line interface (CLI) application that both savvy end-users and other applications can use.
- As a Rust library that other Rust packages may use.
If you are an end-user looking to optimize files, either the demo web page or the CLI application is all you need. On the other hand, if you are a developer, you should look into the CLI or the Rust library.
In addition to these official distribution channels, OptiVorbis is kindly packaged for Arch Linux by [@Chocobo1](https://github.com/Chocobo1). Feel free to check out the [`optivorbis` package on AUR](https://aur.archlinux.org/packages/optivorbis) if you are using Arch Linux.
## Demo web page
Just [visit the website](https://optivorbis.github.io/OptiVorbis): no installation required! Only a modern web browser that supports the required technologies is needed. Notably, Internet Explorer is not supported, but [you should no longer be using it](https://docs.microsoft.com/en-us/lifecycle/announcements/internet-explorer-11-end-of-support).
## CLI
Download the appropriate CLI executable from [GitHub Releases](https://github.com/OptiVorbis/OptiVorbis/releases), according to your operating system and CPU architecture. The executables are statically linked, so they are entirely self-contained and do not require any system configuration to run.
If you are using a Unix-like OS (Linux, macOS), remember that the executable must have the execute permission to work. This permission may be granted with the `chmod` command: `chmod +x optivorbis`.
If you want to go bleeding edge and try out code that was not yet released, you can get the latest CLI executables from the [GitHub Actions CI workflow](https://github.com/OptiVorbis/OptiVorbis/actions/workflows/ci.yml). No guarantees are made about the stability of these builds.
## Rust library
Like any other dependency, add it to the `Cargo.toml` manifest of your project, and start calling its API as you like. Check out its page at [`crates.io`](https://crates.io/crates/optivorbis) and the API docs at [`docs.rs`](https://docs.rs/optivorbis) to get started.
The minimum supported Rust version (MSRV) for every package in this repository is 1.65. Bumping this version is not considered a breaking change for semantic versioning purposes. We will try to do it only when we estimate that such a bump would not cause widespread inconvenience or breakage.
# π Usage
By now, it should be obvious how to use the demo web page or Rust library. The CLI arguments follow a well-defined syntax. Several options are accepted to customize the optimization process and affect the output and operation of the CLI. The most important one to get started is `--help`, which shows the following usage help:
```
Usage:
optivorbis [OPTION]...