#ffmpeg #color-space #decoding #parts #wrapper #streaming

moonfire-ffmpeg

safe wrapper around select parts of ffmpeg

2 releases

0.0.2 Mar 8, 2022
0.0.1 May 11, 2021

#212 in Video

MIT/Apache

98KB
1.5K SLoC

Rust 1.5K SLoC // 0.1% comments C 231 SLoC // 0.1% comments

moonfire-ffmpeg

A Rust wrapper around select parts of ffmpeg needed for Moonfire NVR:

  • basic streaming: connecting to a RTSP stream. (Though eventually I want Moonfire NVR to do this in pure Rust; see scottlamb/moonfire-nvr#37.)
  • video analytics: decoding H.264 (likely also H.265 eventually; and eventually with hardware acceleration), converting its colorspace to RGB, and downscaling it to feed to moonfire-tflite.

There's a much more full-featured ffmpeg crate. A few reasons I use my own instead though:

  • the ffmpeg crate isn't actively maintained. (There are some forks though. Maybe ffmpeg4 is what you're looking for.)
  • building moonfire-ffmpeg doesn't need bindgen, which can be a pain to install on some platforms. (See its requirements.) Instead, moonfire-ffmpeg uses a very thin C wrapper around ffmpeg to avoid baking in (possibly version-specific) details of the ffmpeg ABI such as struct layouts.
  • moonfire-ffmpeg checks ABI compatibility between the ffmpeg it was compiled with and the ffmpeg it's actually running with, which is important for making it fool-proof with shared libraries. I think the ffmpeg crate is more intended to be used with a static library.
  • moonfire-ffmpeg exposes a few very specific pieces of the ffmpeg API that I needed and the ffmpeg crate doesn't, such as reading non-understood parameters to avcodec_open2.
  • moonfire-ffmpeg is licensed under MIT and Apache-2.0, vs the ffmpeg crate's WTFPL. I consider this an advantage for moonfire-ffmpeg because WTFPL scares away some people and companies.

Dependencies

~0.4–7MB
~16K SLoC