Opus or FLAC in Rust: Choosing an Audio Codec for Voice, Music and Archives
Opus or FLAC? One audio codec is built for live voice and streams, the other keeps every sample. How to choose in Rust, with rusty-opus and rusty_flac, and when to use both.

Should I use Opus or FLAC in a Rust project?
Use Opus when audio has to travel live or small, such as voice calls, game chat and streams, because it is a lossy codec built for interactive use. Use FLAC when every sample must survive, such as recordings, archives and audio you will process later, because it is lossless. Many pipelines keep FLAC at rest and send Opus on the wire.
Two open audio codecs cover most of what a Rust program needs to do with sound. Opus is the one you hear on calls and in game chat. FLAC is the one you keep when the recording matters. Picking the wrong one is not a crash. It is a slow leak: voice notes far bigger than they need to be, or transcripts built from audio that already threw detail away.
This note is for builders in the Media band. It explains the one question that decides Opus or FLAC, how each audio codec behaves in Rust through rusty-opus and rusty-flac, and the common pattern where you use both. Both crates are pure Rust, with no C code and no FFI, and both are part of the codec set behind remade_ffmpeg_rs.
Opus or FLAC: the audio codec question that decides it
Ask whether the audio has to come back exactly as it went in.
If it does, you want a lossless audio codec, and that is FLAC. RFC 9639, published in December 2024, defines FLAC as a format that reduces the storage needed for digital audio "losslessly, i.e., it does so without losing information." Decode a FLAC stream and you get the original samples back, bit for bit. The RFC also stresses low complexity: FLAC can be encoded and decoded with little computing power and without floating-point arithmetic, which is why it runs comfortably on small chips.
If the audio only has to sound right to a listener, and it has to be small or arrive fast, you want Opus. RFC 6716, from September 2012, describes Opus as an interactive speech and audio codec for voice over IP, videoconferencing, in-game chat and even live music performance. It scales from narrowband speech at 6 kbit/s to stereo music at 510 kbit/s, and mixes a speech layer (SILK) with a transform layer (CELT). Frames run from 2.5 ms to 60 ms, and the RFC calls 20 ms frames a good choice for most applications. Opus is lossy. What comes out is close to the source, not the source.
A second question breaks most ties: who listens, and when? A person listening now favors Opus. A program that will analyze, edit or transcribe later favors FLAC, because every lossy pass removes detail you cannot get back.
Opus in Rust: the audio codec for live voice and streams
rusty-opus is a pure-Rust Opus encoder and decoder covering SILK, CELT and Hybrid modes. Version 1.1.1 is on crates.io. Its README says it is bit-exact on all 12 official RFC 6716 and RFC 8251 decoder test vectors.
Encode 20 ms frames with the Opus audio codec
The README's usage example is short. You create an OpusEncoder with a sample rate, a channel count and an Application, set bitrate_bps, and call encode with one frame of interleaved f32 samples and a packet buffer. At 48 kHz, a 20 ms frame is 960 samples per channel. Each call returns one packet's length, and the decoder takes that packet back with decode. We compiled and ran exactly that loop against rusty-opus 1.1.1 on rustc 1.85.1 in a scratch project: one second of a mono test tone became 50 packets. That is a smoke test of the calls shown in the README, not a benchmark.
Packet loss and real-time threads
Networks drop packets, and Opus plans for it. The README lists packet-loss concealment, in-band forward error correction, discontinuous transmission (DTX) and comfort noise. Pass an empty packet to decode and the decoder conceals the gap instead of erroring. For audio threads, the README states that after warm-up OpusDecoder::decode performs zero heap allocations, including concealment and mode changes. Malformed packets return an Err, never a panic, which matters when packets come from peers you do not control.
Files need a container
Opus packets are not a file. A .opus file is Opus inside Ogg, defined by RFC 7845. The rusty-opus README documents packets, multistream surround and a repacketizer, and does not document an Ogg writer, so plan for that layer if you are saving voice notes to disk. Inside WebRTC or a custom protocol you send the packets directly.
FLAC in Rust: the lossless audio codec for archives and processing
rusty_flac is a pure-Rust FLAC encoder and decoder. Version 0.5.1 is on crates.io under Apache-2.0, with no required dependencies.
Encode once, check that it is lossless
You create Encoder::new(sample_rate, channels, bits_per_sample), pick a compression level, push planar samples with push_planar and call finish to get the stream. rusty_flac::decode returns the stream info and the channels. In the same scratch project we encoded the test tone at level 8, decoded it, and compared every sample with the input: equal. Every FLAC stream also carries an MD5 of the unencoded audio in its STREAMINFO block, per RFC 9639, so other tools can verify the file too.
Long recordings and small boards
Long captures should not sit in memory until the end. The README's quick start uses take_frames to pull out every complete block as you go, so a long stream is written in constant memory. The crate is no_std plus alloc ready with an optional pure-Rust libm, CI checks bare-metal RISC-V and Arm targets, and the README reports the encoder running on an ESP32-S3. That makes it a fit for capture devices like the boards behind rusty-esp-audio. One honest gap: seek tables and Vorbis comment or picture blocks are unchecked roadmap items, so tags and fast seeking in long files are not there yet.
Opus or FLAC? Often both: FLAC at rest, Opus on the wire
The common answer to Opus or FLAC is both. Record and store in FLAC, so the original survives. Encode an Opus copy when you need to send or stream it. For transcription and search, starting from the lossless copy avoids stacking a second lossy pass on the first. RAG Converter is one user: the rusty_flac README says it decodes audio with rusty_flac, and the whole conversion runs as WebAssembly in the browser tab with nothing uploaded. If you are replacing C audio stacks one at a time, the pure-Rust alternative for libopus and libFLAC notes compare the swap, and the rusty-opus and rusty-flac repo pages list the current releases.
FAQ
Quick answers for builders evaluating this technology.
Is Opus lossless?
No. Opus is a lossy audio codec defined in RFC 6716. It is designed for interactive speech and music and scales from 6 kbit/s narrowband speech to 510 kbit/s stereo music. Decoded Opus sounds close to the source at good bitrates, but it is not the same samples.
Is FLAC good for voice calls?
Not usually. FLAC keeps every sample, so its streams are larger than Opus at speech bitrates, and it has none of the packet loss tools that interactive audio needs. It is the better fit for recordings you keep, edit or transcribe later, then send in a lossy codec if needed.
Does rusty-opus write .opus files?
The rusty-opus README documents raw Opus packets: an encoder, a decoder, multistream and a repacketizer. A .opus file wraps those packets in Ogg as described in RFC 7845, and this note does not claim rusty-opus writes that container. Check the repository before you rely on it.
Can rusty_flac run without the standard library?
Yes, per its README. rusty_flac is no_std plus alloc ready with an optional pure-Rust libm feature, CI checks bare-metal RISC-V and Arm targets, and the same encoder has been measured on an ESP32-S3. Seek tables and Vorbis comment or picture blocks are still roadmap items.
Do I need C libraries to use Opus or FLAC in Rust?
Not with these crates. rusty-opus and rusty_flac are both pure-Rust audio codec implementations with no C code and no FFI, published on crates.io. rusty-opus is BSD-3-Clause and needs Rust 1.85 or later, and rusty_flac is Apache-2.0.