Categories
Tags
3d ABI Actions algorithms alignment analyze APIT Arc Architecture arm array ascii ash assembly asynchronous attribute base64 bithacks Blogging box c c23 cdylib CHAR_BIT clamp clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete dll doc DP drawio dtruss dylib Dynamic emulator example Example FFI ffmpeg flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative inference intel interop invariant iterator join justfile kernel LaTeX leak LFU limits linux lto MachineLearning macOS map Markdown math ML mmap mod mp3 nc nextest OnceLock optimization OS ownership panic parallels perf physics pin postgresql procedure product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift SIMD sin size SmallProjects so socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous syscall tan test thread time toml tracing traits trap triangulation type uint32_t UnsafeRust utf16 utf8 vector Video vulkan wsl x86_64 xilem zig
366 words
2 minutes
Rust_ver_FFmpeg_001
Rust version of FFmpeg
Yes. If you’re designing a Rust version of FFmpeg, I would organize codecs by codec/format family, rather than putting everything into one large
codec.rs.A structure like this works well:
src/
└── codec/
├── mod.rs
│
├── audio/
│ ├── mod.rs
│ ├── pcm.rs
│ ├── aac.rs
│ ├── mp3.rs
│ ├── opus.rs
│ ├── vorbis.rs
│ ├── flac.rs
│ └── ac3.rs
│
└── video/
├── mod.rs
├── h264.rs
├── h265.rs
├── vp8.rs
├── vp9.rs
├── av1.rs
└── mpeg2.rsCommon codecs to implement
Audio
| Rust file | Codec | Type |
|---|---|---|
pcm.rs | PCM | Uncompressed audio |
aac.rs | AAC | Lossy audio |
mp3.rs | MP3 | Lossy audio |
opus.rs | Opus | Lossy audio |
vorbis.rs | Vorbis | Lossy audio |
flac.rs | FLAC | Lossless audio |
ac3.rs | AC-3 / Dolby Digital | Lossy audio |
eac3.rs | E-AC-3 | Lossy audio |
alac.rs | ALAC | Lossless audio |
Video
| Rust file | Codec | Type |
|---|---|---|
h264.rs | H.264 / AVC | Lossy video |
h265.rs | H.265 / HEVC | Lossy video |
mpeg1.rs | MPEG-1 Video | Lossy video |
mpeg2.rs | MPEG-2 Video | Lossy video |
mpeg4.rs | MPEG-4 Part 2 | Lossy video |
vp8.rs | VP8 | Lossy video |
vp9.rs | VP9 | Lossy video |
av1.rs | AV1 | Lossy video |
theora.rs | Theora | Lossy video |
If you’re trying to reproduce FFmpeg’s architecture
I’d actually go one step further:
src/
├── codec/
│ ├── mod.rs
│ │
│ ├── audio/
│ │ ├── mod.rs
│ │ ├── pcm.rs
│ │ ├── aac.rs
│ │ ├── mp3.rs
│ │ └── opus.rs
│ │
│ └── video/
│ ├── mod.rs
│ ├── h264.rs
│ ├── h265.rs
│ └── av1.rs
│
├── format/
│ ├── mod.rs
│ ├── mp4.rs
│ ├── mkv.rs
│ ├── avi.rs
│ ├── mov.rs
│ ├── flv.rs
│ └── wav.rs
│
├── bitstream/
│ ├── mod.rs
│ ├── reader.rs
│ └── writer.rs
│
├── frame/
│ ├── mod.rs
│ ├── audio.rs
│ └── video.rs
│
├── packet.rs
├── decoder.rs
└── encoder.rs- The important distinction is:
FFmpeg-like library
│
┌──────────────┴──────────────┐
│ │
CODECS FORMATS
│ │
┌─────┴─────┐ ┌─────┴─────┐
│ │ │ │
Audio Video MP4 MKV
│ │
AAC H.264
MP3 H.265
Opus AV1
FLAC VP9So:
src/codec/aac.rs- means AAC codec implementation.
src/codec/h264.rsmeans H.264 codec implementation.
But:
src/format/mp4.rs- means MP4 container/muxer/demuxer, which is different from H.264.
- For example, an MP4 file might contain:
movie.mp4
│
├── Container: MP4
│
├── Video stream
│ └── Codec: H.264
│
└── Audio stream
└── Codec: AAC- So if you’re building this from scratch, I’d recommend implementing them in roughly this order:
1. PCM
2. WAV container
3. MP3
4. AAC
5. H.264
6. MP4
7. H.265
8. VP9
9. AV1
10. MKV- PCM → AAC/MP3 → H.264 → MP4 is a particularly good progression because it takes you from a very simple codec to a sophisticated video codec and then to a container combining audio + video.
Rust_ver_FFmpeg_001
https://younghakim7.github.io/blog/posts/rust_ver_ffmpeg_001/