Coder Social home page Coder Social logo

optivorbis / optivorbis Goto Github PK

View Code? Open in Web Editor NEW
83.0 83.0 5.0 43.2 MB

πŸ—œοΈ Library and application for lossless, format-preserving, two-pass optimization and repair of Vorbis data, reducing its size without altering any audio information.

Home Page: https://optivorbis.github.io/OptiVorbis

License: GNU Affero General Public License v3.0

Rust 90.09% Shell 0.58% JavaScript 0.75% CSS 0.20% HTML 5.51% TypeScript 2.67% Dockerfile 0.18%
audio-compression bandwidth-saver cli file-optimization hacktoberfest lossless-compression ogg-vorbis optimization-tools repair-tool rust rust-application rust-library vorbis

optivorbis's Introduction

OptiVorbis logo

OptiVorbis

A library and application for lossless, format-preserving, two-pass optimization and repair of Vorbis data, reducing its size without altering any audio information.

CI workflow status crates.io latest version docs.rs status

crates.io downloads GitHub Releases downloads

πŸ” 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.

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.
  • 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. Feel free to check out the optivorbis package on AUR if you are using Arch Linux.

Demo web page

Just visit the website: 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.

CLI

Download the appropriate CLI executable from GitHub 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. 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 and the API docs at docs.rs to get started.

The minimum supported Rust version (MSRV) for every package in this repository is 1.73. 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]... <input file> <output file or ->

Options:
    -h, --help          Prints information about the accepted command line
                        arguments and exits.
        --version       Prints version and copyright information, then exits.
    -q, --quiet         When enabled, the program will only print error
                        messages, unless -h is specified.
    -v, --verbose       Increases the verbosity of the messages. Can be
                        repeated several times.
    -r, --remuxer REMUXER
                        The remuxer to use for managing the encapsulation of
                        Vorbis streams in a container. If not specified, it
                        will be automatically deduced from the extension of
                        the output file.
                        Available remuxers: ogg2ogg
        --vendor_string_action VENDOR-STRING-ACTION
                        Changes how the vendor string contained in the Vorbis
                        identification header will be dealt with.
                        Available actions: copy, replace, appendTag,
                        appendShortTag, empty
        --comment_fields_action COMMENT-FIELDS-ACTION
                        Changes how the user comment fields contained in the
                        Vorbis comment header will be dealt with.
                        Available actions: copy, delete
        --remuxer_option OPTION=VALUE
                        Sets a remuxer-specific option to a value.
                        -----------------------
                        ogg2ogg remuxer options
                        -----------------------
                        - randomize_stream_serials=BOOLEAN
                        If set to true, the stream serials will be randomized,
                        following the intent of the Ogg specification. Set to
                        false to disable this behavior and have more control
                        over the serials. The default value is true.
                        - first_stream_serial_offset=INTEGER
                        A zero or positive integer that sets the offset that
                        will be added to the serial of the first stream. When
                        not randomizing stream serials, the offset matches the
                        serial that will be used for the first stream. The
                        default value is 0.
                        - ignore_start_sample_offset=BOOLEAN
                        Sets whether a non-zero calculated granule position
                        for the first audio sample will be honored when
                        recomputing granule positions in the generated Ogg
                        file or not. This usually is a good thing, but for
                        increased compatibility with some players or dedicated
                        purposes it may be advised to ignore this offset. The
                        default value is false.
                        - error_on_no_vorbis_streams=BOOLEAN
                        Sets whether not finding any Vorbis stream within the
                        Ogg container will be considered an error condition.
                        The default value is true, which means that not
                        finding any Vorbis stream will be considered an error.
                        This usually is the most desirable behavior.

πŸ“Š Testing and results

OptiVorbis has been developed as a part of a master's thesis at the University of Vigo and extensively tested before its public release with a dataset of 1783 randomly selected, valid Ogg Vorbis files downloaded from Freesound, totaling 164 hours and 16.58 GiB of sound data. OptiVorbis passed all the defined unit, integration, and system tests, achieving a size reduction for every analyzed file without altering the audio samples as decoded by oggdec (from the Debian vorbis-tools package, version 1.4.2). The only exceptions were four files that had their granule position data corruption fixed by OptiVorbis. The dataset comprised all kinds of Ogg Vorbis files containing mono, stereo, and surround sounds at varying sampling rates, generated by a wide variety of encoders. It was optimized in about half an hour, parallelizing the work across six CPU cores.

The following boxplot represents the distribution of relative per-file size reductions achieved by OptiVorbis.

Even though the optimization potential may vary substantially, every file had its size reduced. The achieved reduction was significantly better than using generic compression tools on the Ogg Vorbis files, such as xz. Interestingly, the file size reduction distribution is slightly skewed towards higher reduction rates, as evidenced by the average (11.35%) being slightly higher than the median (9.62%). Half of the analyzed files had their size reduced between 4.91% and 13.44%.

Notably, the testing techniques included fuzzing, employing the AFL++ fuzzer. With the help of AFL++, the optimization of 600 million mutated Ogg Vorbis files was tested, discovering tens of failing runtime assertions that were fixed.

βš–οΈ License

The OptiVorbis library is licensed under either of

at your option. The OptiVorbis CLI is licensed under the GNU Affero General Public License, Version 3 only. Other components (the web demo, etc.) are licensed according to the license files present in their root directory and their package metadata, if any.

✨ Contributing

Pull requests are accepted. Feel free to contribute if you can improve some aspect of the OptiVorbis project!

Contributions include, but are not limited to:

  • Writing good bug reports or feature requests
  • Sending a PR with code changes that implement an improvement or fix an issue
  • Recommending OptiVorbis to others and engaging with the community
  • Economically supporting the project (check out the "Sponsor" button in the GitHub page)

Code contributions must pass CI checks and be deemed of enough quality by a repository maintainer to be merged. OptiVorbis is structured as a standard Cargo workspace with several packages:

  • packages/optivorbis: the OptiVorbis Rust library.
  • packages/optivorbis_afl_fuzz_target: an AFL++ target for fuzzing OptiVorbis. See also the related scripts/afl-fuzz.sh script.
  • packages/optivorbis_cli: the OptiVorbis CLI.
  • packages/vorbis_bitpack: an implementation of bitwise reading and writing operations according to the Vorbis bitpacking convention.

The website (web) is a standard npm project that uses WebPack and the OptiVorbis library WASM target JS bindings, built with wasm-pack.

🀝 Contact

We welcome friendly talk about the project, including questions, congratulations, and suggestions. Head to the GitHub Discussions page to interact with fellow users, contributors and developers.

πŸ§‘β€πŸ€β€πŸ§‘ Contributors

Thanks goes to these wonderful people (emoji key):

Alejandro GonzΓ‘lez
Alejandro GonzΓ‘lez

πŸ’» πŸ“– 🎨 πŸ€” 🚧 πŸ“† πŸ”£ πŸ–‹ πŸ”¬ πŸš‡
victorlf4
victorlf4

πŸ€”
Chocobo1
Chocobo1

πŸ“¦
Miguel
Miguel

🎨
sya-ri
sya-ri

πŸ€” πŸš‡

This project follows the all-contributors specification. Contributions of any kind welcome!

➑️ Related software

If you found OptiVorbis useful, you may be interested in programs such as:

  • rogg: a small library for manipulating Ogg Vorbis files, which offers advanced and unusual features such as adjusting granule positions, replacing stream serial numbers, and recomputing the CRC of every Ogg page.
  • oggz: a library and set of command-line tools for low-level inspection and manipulation of Ogg Vorbis files.
  • revorb: a command-line tool for recomputing granule positions of Ogg Vorbis files. OptiVorbis does such recomputation automatically, too.
  • rehuff: a proprietary, proof of concept program for optimizing Vorbis streams from 2002, written by Segher Boessenkool. OptiVorbis expands upon the optimization techniques said to be implemented in rehuff, offering a much more finished, reliable solution that is open-source.

β›” Known limitations

As a concession to implementation simplicity, Vorbis streams that use the floor signal component format of type 0 are not supported. According to the Vorbis I specification, this format is "of limited modern use" and has been effectively deprecated by every known Vorbis encoder for more than 20 years, so streams with this floor type should be extremely rare to find. Pull requests that address this limitation are welcome.

Due to the two-pass optimization algorithm described above, OptiVorbis is not readily applicable for live-streaming use cases.

The Vorbis I setup header codebook format is vulnerable to denial of service attacks, as extremely dense prefix code trees, which take a significantly long time to parse, are valid according to the specification. OptiVorbis does not impose a depth or density limit in such trees, which guarantees its interoperability, but renders it vulnerable to specially-crafted files. This may be addressed in the future as information about the interoperability and mitigation impact of limiting the tree depth is gathered. In the meantime, applications dealing with untrusted files should be aware of this and resort to using OS features to bound resource consumption when applicable.

optivorbis's People

Contributors

alextmjugador avatar kianmeng avatar renovate[bot] avatar sya-ri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

optivorbis's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Package lookup failures

Pending Branch Automerge

These updates await pending status checks before automerging. Click on a checkbox to abort the branch automerge, and create a PR instead.

  • fix(deps): update rust crate thiserror to v1.0.61

Warning

Renovate failed to look up the following dependencies: Failed to look up npm package optivorbis.

Files affected: web/package.json


Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • chore(deps): update mcr.microsoft.com/vscode/devcontainers/rust docker tag to v1

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

cargo
Cargo.toml
  • log 0.4.21
packages/optivorbis/Cargo.toml
  • ogg 0.9.1
  • indexmap 2.2.6
  • bumpalo 3.16.0
  • tinyvec 1.6.0
  • getrandom 0.2.14
  • rand_xoshiro 0.6.0
  • thiserror 1.0.59
  • ouroboros 0.18.3
  • slice-group-by 0.3.1
  • wasm-bindgen 0.2.92
  • console_log 1.0.0
  • console_error_panic_hook 0.1.7
  • pretty_env_logger 0.5.0
  • oggvorbismeta 0.1.0
packages/optivorbis_afl_fuzz_target/Cargo.toml
  • afl 0.15.5
packages/optivorbis_cli/Cargo.toml
  • getopts 0.2.21
  • stderrlog 0.6.0
packages/vorbis_bitpack/Cargo.toml
  • acid_io 0.1.0
  • libm 0.2.8
dockerfile
.devcontainer/Dockerfile
  • mcr.microsoft.com/vscode/devcontainers/rust 0-buster
github-actions
.github/workflows/ci.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • dtolnay/rust-toolchain v1@1482605bfc5719782e1267fd0c0cc350fe7646b8
  • Swatinem/rust-cache v2@23bce251a8cd2ffc3c1075eaa2367cf899916d84
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • dtolnay/rust-toolchain nightly
  • Swatinem/rust-cache v2@23bce251a8cd2ffc3c1075eaa2367cf899916d84
  • giraffate/clippy-action v1@13b9d32482f25d29ead141b79e7e04e7900281e0
  • EmbarkStudios/cargo-deny-action v1@3f4a782664881cf5725d0ffd23969fcce89fd868
  • actions/upload-artifact v4@65462800fd760344b1a7b4382951275a0abb4808
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • dtolnay/rust-toolchain nightly
  • actions/setup-node v4@60edb5dd545a775178f52524783378180af0d1f8
  • Swatinem/rust-cache v2@23bce251a8cd2ffc3c1075eaa2367cf899916d84
  • peaceiris/actions-gh-pages v4@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e
  • ubuntu 22.04
  • ubuntu 22.04
npm
web/package.json
  • core-js 3.37.1
  • optivorbis *
  • @typescript-eslint/eslint-plugin 7.9.0
  • @typescript-eslint/parser 7.9.0
  • @wasm-tool/wasm-pack-plugin 1.7.0
  • autoprefixer 10.4.19
  • css-loader 7.1.1
  • cssnano 7.0.1
  • eslint 8.57.0
  • eslint-config-airbnb-base 15.0.0
  • eslint-import-resolver-typescript 3.6.1
  • eslint-plugin-import 2.29.1
  • favicons-webpack-plugin 6.0.1
  • html-webpack-plugin 5.6.0
  • mini-css-extract-plugin 2.9.0
  • postcss 8.4.38
  • postcss-loader 8.1.1
  • svg-inline-loader 0.8.2
  • tailwindcss 3.4.3
  • ts-loader 9.5.1
  • typescript 5.4.5
  • webpack 5.91.0
  • webpack-cli 5.1.4
  • webpack-dev-server 5.0.4

  • Check this box to trigger a request for Renovate to run again on this repository

Consider using the `indextree` crate to implement Huffman trees

Currently, OptiVorbis implements Huffman tree operations using the ouroboros and bumpalo crates. This works fine, but profiling showed that walking through Huffman trees is a hot operation during optimization, responsible for most of the execution time. Therefore, as highlighted by Amdahl's law, optimizing the runtime of this operation is crucial to increase the overall performance of OptiVorbis.

One possible avenue of optimization is to use the indextree crate instead of the two previously mentioned. The basic idea is to use it to store indexes instead of pointers to children in the tree nodes, potentially making it easier for the Rust compiler to choose to use a more efficient base + index addressing mode in the emitted assembly instructions rather than resorting to dereferencing a generic reference. Even if this change does not improve performance, it would remove one dependency and likely simplify the code, which is welcome anyway.

Some basic benchmarks should be added to the codebase to assess the performance impact of this change.

Make testing dataset publicly available

During the development of OptiVorbis, I created a dataset of Ogg Vorbis files for testing and evaluating it, which is mentioned in the README. So far, this dataset has been sitting on my hard disk and on a digital medium submitted with my thesis documentation, neither of which are accessible to the wider community.

In the interest of making it easier to reproduce the results described and to facilitate further research by interested parties, I think it's a good idea to make the dataset public in a free, reliable, research-friendly, and long-term way.

My main concerns with this idea are as follows:

  • There is no commercial file hosting service that I know of that fits the bill. Fortunately, I recently stumbled upon Zenodo, which is supported by EU institutions and seems quite suitable for this purpose, as it assigns a DOI to its uploads.
  • Intellectual property: in any case, the dataset files can be traced back to their original Freesound submission, but that doesn't mean that their licensing is compatible with this kind of distribution.

Now that file hosting is no longer an issue, only the intellectual property concerns remain, so it's wise for me to at least write this issue so that I don't forget about it and work on it can get done. If anyone has expert knowledge about my intellectual property concerns, please feel free to comment and give your perspective.

A setting to overwrite files/bulk optimization?

Hello! I've stumbled upon this program, and the first thing I thought is that it would be extremely handy if I could just point this application at a folder and have it optimize everything within it without having to manually input each file. I'm a barely tech literate sort of person so I don't really know how to write a fancy script that would do that for me automagically like what I've seen others do. If there was a setting to optimize and overwrite the original files without having to do it all manually, that would rock my socks off. It would be doubly awesome if I could just drag and drop files/folders on the executable and have it do all the magic without ever touching a command prompt, kind of like how PNGOUT does it!

reproducible files

optivorbis compares itself to jpegoptim and optipng, but it has one big difference: it seems to always generate a different file.

optivorbis file1.ogg file2.ogg
optivorbis file2.ogg file3.ogg
optivorbis file1.ogg file4.ogg

md5sum file2.ogg file3.ogg file4.ogg

All hashes are different (all sizes are equal).

jpegoptim and optipng detect if the file they are overwriting would have a bigger or equal size, and do not overwrite it.

It would be nice if optivorbis would create reproducible files (as in: same input, same output).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.