Wedeo – FFmpeg 的 Rust 重写
Wedeo – a Rust Rewrite of FFmpeg

原始链接: https://github.com/sharifhsn/wedeo

## Wedeo:一个用AI重写的FFmpeg项目(Rust语言) Wedeo是一个基于Rust的项目,旨在利用AI(具体来说是Anthropic的Claude,通过Claude Code)重现FFmpeg的功能,并辅以人工指导和审查。目标是探索AI驱动代码重写的极限,通过在每次提交时进行自动CI测试,实现与FFmpeg输出的逐位验证。 目前,Wedeo实现了FFmpeg功能的一个子集,重点是H.264解码(对于Baseline到High profile完全逐位精确,不包括隔行扫描和10位),WAV解复用/复用,FLAC/Vorbis/AAC通过适配器,以及通过rav1d进行AV1解码。还包含一个具有A/V同步的基本视频播放器。 虽然Wedeo实现了符合标准,但即使集成了汇编代码,其速度也明显慢于FFmpeg。该项目采用基于crate的架构,模仿FFmpeg的库,并采用严格的测试,包括FATE和JVT符合性测试套件。在编解码器支持(VP9、HEVC等)、编码能力以及复用器/解复用器覆盖方面仍然存在重大差距。开发由详细的AI代理文档指导,强调架构和约定。

## Wedeo:AI 生成的 Rust FFmpeg 重写 Sharifhsn 发布了 “wedeo”,这是一个使用 AI Claude 完全生成的、对强大的多媒体框架 FFmpeg 的 Rust 重写版本。该项目旨在探索 LLM 在大规模代码重写方面的能力,利用 FFmpeg 定义明确的规范和高质量的 C/汇编代码。 目前,wedeo 包含一个 30,000 行的 H.264 解码器,支持 99% 的编码视频,以及通过现有库(rav1d, rav1e, symphonia, wgpu, winit)提供的 AV1 支持。目前性能明显慢于 FFmpeg,因为缺乏优化,但作者希望缩小差距。 值得注意的是,作者尚未手动审查任何 AI 生成的代码,除了针对 AI 提出的错误修复和解释。这引发了关于“AI 垃圾”和许可(代码包含 FFmpeg 的 LGPL 代码)的讨论。尽管存在担忧,作者认为该项目是一个独特的实验,并且是 AI 资源的有价值的应用。目前测试仅限于 MacOS M 系列,欢迎贡献。
相关文章

原文

Rust rewrite of FFmpeg, verified against FFmpeg's output bit-for-bit.

This codebase is AI-generated. Written by Claude (Anthropic) via Claude Code, directed and reviewed by a human. The AI reads FFmpeg's C source and reimplements it in Rust. Every conformance claim below is verified by automated CI on every commit, comparing to FFmpeg's output.

The intention of this project is to push the boundaries of what is possible with AI rewriting codebases in Rust. It provides no additional features compared to FFmpeg, and despite incorporating FFmpeg's assembly code, is significantly slower.

Component Conformance Notes
H.264 decode 79/79 BITEXACT CAVLC + CABAC, Baseline through High profile
H.264 FRext 23/55 bitexact Progressive 4:2:0 8-bit done; MBAFF/PAFF/10-bit remaining
H.264 NEON (aarch64) 1.75x speedup MC, IDCT, deblock — FFmpeg's vendored assembly via cc
WAV demuxer + PCM bitexact RIFF/RIFX/RF64/BW64, 17 PCM formats, 13/13 FATE files
WAV muxer bitexact Roundtrip verified
FLAC, WavPack bitexact Via symphonia adapter
Vorbis, AAC, MP3 ~120-140 dB SNR Lossy codecs, float precision only
AV1 bitexact Via rav1d adapter
MP4 demuxer working H.264, AV1, AAC tracks
Video player 24fps 0-drop GPU (wgpu), ffplay-style A/V sync, pause, volume

The H.264 decoder is ~30K lines of Rust across 25 modules. It implements:

  • CAVLC and CABAC entropy coding
  • All intra prediction modes (4x4, 8x8, 16x16, chroma)
  • Quarter-pel motion compensation (6-tap FIR luma, bilinear chroma)
  • 4x4 and 8x8 IDCT with Hadamard DC transforms
  • In-loop deblocking filter
  • MMCO and sliding-window reference management
  • Weighted prediction (uni/bi)
  • B-frames with direct prediction (spatial + temporal)
  • High profile: 8x8 transforms, custom scaling matrices
  • MBAFF interlaced (partial — field/frame MB switching, CABAC context adaptation)
  • Frame-level threading with wavefront deblocking
  • aarch64 NEON assembly for MC, IDCT, and deblocking (feature-gated)

Architecture details: H264.md. Known FFmpeg behavioral differences: DIVERGENCES.md.

FFmpeg has hundreds of codecs and formats. wedeo currently covers a small subset. Major gaps for parity:

  • Video codecs — VP9, HEVC/H.265, MPEG-2, MPEG-4 Part 2, VP8, Theora. H.264 is missing interlaced (MBAFF/PAFF), 10-bit, and 4:2:2/4:4:4.
  • Video encoding — no encoders exist yet (H.264, H.265, AV1 via rav1e)
  • Muxers — only WAV. No MP4/MOV, MKV/WebM, or MPEG-TS muxer.
  • Demuxers — no MKV/WebM, MPEG-TS, FLV, or AVI demuxer (MP4 and WAV only, plus symphonia-backed formats)
  • Filters — trait skeleton exists but no functional filter graph (no scale, crop, overlay, fps, etc.)
  • Player — no seek, no subtitle rendering, no hardware-accelerated decode
  • Infrastructure — no interruptible I/O (network streams), no chapter/program support, no avformat_find_stream_info equivalent
# From source (includes AV1 support via rav1d)
cargo install --git https://github.com/sharifhsn/wedeo wedeo-cli
# Also from source — AV1, H.264, and audio all work
cargo install --git https://github.com/sharifhsn/wedeo wedeo-play
wedeo-play video.mp4
# Cargo.toml — core crates are on crates.io
[dependencies]
wedeo = "0.1.2"
wedeo-codec-h264 = "0.1.2"    # H.264 decoder
wedeo-format-mp4 = "0.1.2"    # MP4 demuxer
wedeo-symphonia = "0.1.2"     # audio codecs (AAC, MP3, FLAC, etc.)

# AV1 requires a git dependency (rav1d is not yet on crates.io)
wedeo-rav1d = { git = "https://github.com/sharifhsn/wedeo" }
cargo build
cargo nextest run            # or cargo test
cargo clippy

Decode a file and compare against FFmpeg:

cargo run --release --bin wedeo-framecrc -- input.264
ffmpeg -bitexact -i input.264 -f framecrc -

FFmpeg's native test suite.

./scripts/fetch-fate-suite.sh                    # downloads full suite (~1.2 GB)
FATE_SUITE=./fate-suite cargo nextest run -p wedeo-fate

JVT conformance (ITU test vectors)

204 test vectors from the ITU JVT conformance suite, with MD5 ground truth from the Fluster project. No FFmpeg required — comparison is against ITU-provided checksums.

python3 scripts/fetch_jvt.py                     # download vectors (~50 MB)
python3 scripts/suite_runner.py --suite jvt-avc-v1,jvt-fr-ext --format yuv420p

The unified suite runner also wraps the FATE suites:

python3 scripts/suite_runner.py --suite all --format yuv420p
python3 scripts/suite_runner.py --suite fate-cavlc --save-snapshot
python3 scripts/suite_runner.py --suite fate-cavlc --check-snapshot   # regression check
wedeo/
  crates/
    wedeo-core/          libavutil   — Rational, Buffer, Frame, Packet, errors
    wedeo-codec/         libavcodec  — Decoder/Encoder traits, codec registry
    wedeo-format/        libavformat — Demuxer/Muxer traits, I/O, InputContext
    wedeo-filter/        libavfilter (stub)
    wedeo-resample/      libswresample (rubato)
    wedeo-scale/         libswscale (dcv-color-primitives)
  codecs/
    wedeo-codec-h264/    H.264 decoder — 30K lines, NEON assembly, 55 benchmarks
    wedeo-codec-pcm/     PCM codec — 17 formats
  formats/
    wedeo-format-h264/   H.264 Annex B demuxer
    wedeo-format-wav/    WAV demuxer + muxer
    wedeo-format-mp4/    MP4/MOV demuxer
  adapters/
    wedeo-symphonia/     Wraps symphonia (FLAC, Vorbis, MP3, AAC, WavPack)
    wedeo-rav1d/         Wraps rav1d (AV1)
  bins/
    wedeo-cli/           CLI tool
    wedeo-play/          Video player — wgpu+winit, ffplay-style A/V sync
  tests/
    fate/                FATE cross-validation harness
  scripts/
    suite_runner.py      Unified conformance runner (FATE + JVT)
    fetch_jvt.py         JVT vector downloader
    conformance_full.py  FATE conformance report
    regression_check.py  Quick regression check
  test_suites/
    h264/                JVT manifest JSONs (tracked)

Each FFmpeg library maps to one Rust crate. Codecs and formats register themselves via inventory at link time — no central enum.

Five parallel jobs run on every PR (all required to merge):

  • Lint — clippy + rustfmt
  • Test — 462 unit and integration tests via nextest
  • FATE Regression — no previously-passing FATE test may regress (framecrc vs FFmpeg)
  • JVT Regression — no previously-passing JVT test may regress (MD5 vs ITU checksums)
  • Deny — license allow-list and advisory audit via cargo-deny

Conformance baselines are committed in test_suites/baselines/. To update after expanding coverage:

python3 scripts/suite_runner.py --suite fate-cavlc,fate-cabac \
  --save-snapshot --snapshot-dir test_suites/baselines

Pre-commit hook available: pip install pre-commit && pre-commit install

The FFmpeg/ submodule is pinned to n8.1. Optional — only needed to read the C source or build a debug FFmpeg for development:

git submodule update --init
cd FFmpeg && ./configure --disable-optimizations --enable-debug=3 \
  --disable-stripping --disable-asm && make -j$(nproc) ffmpeg

See CONTRIBUTING.md.

This repo is designed for AI-assisted development. CLAUDE.md contains the full project context: architecture, conventions, debugging procedures, and technical requirements. It is the canonical reference for any AI agent working on this codebase — read it before writing code.

The llms.txt file provides a machine-readable project summary following the llms.txt convention.

LGPL-2.1-or-later. See LICENSE and COPYING.LGPLv2.1.

联系我们 contact @ memedata.com