27 releases

new 0.4.8 May 26, 2024
0.4.7 Jan 9, 2024
0.4.6 Dec 29, 2023
0.4.5 Feb 2, 2023
0.0.5 Jul 8, 2021

#224 in Multimedia

Download history 63/week @ 2024-02-04 101/week @ 2024-02-11 54/week @ 2024-02-18 247/week @ 2024-02-25 283/week @ 2024-03-03 108/week @ 2024-03-10 56/week @ 2024-03-17 48/week @ 2024-03-24 87/week @ 2024-03-31 48/week @ 2024-04-07 59/week @ 2024-04-14 96/week @ 2024-04-21 36/week @ 2024-04-28 13/week @ 2024-05-05 49/week @ 2024-05-12 65/week @ 2024-05-19

166 downloads per month
Used in 2 crates

MIT/Apache

470KB
10K SLoC

retina

crates.io version Documentation CI

High-level RTSP multimedia streaming library, in Rust. Good support for ONVIF RTSP/1.0 IP surveillance cameras, as needed by Moonfire NVR. Works around brokenness in cheap closed-source cameras.

Status: In production use in Moonfire NVR. Many missing features.

Progress:

  • client support
    • basic authentication.
    • digest authentication.
    • RTP over TCP via RTSP interleaved channels.
    • RTP over UDP (experimental).
      • re-order buffer. (Out-of-order packets are dropped now.)
    • RTSP/1.0.
    • RTSP/2.0.
    • SRTP.
    • ONVIF backchannel support (for sending audio).
    • ONVIF replay mode.
    • receiving RTCP Sender Reports (currently only uses the timestamp)
    • sending RTCP Receiver Reports
  • server support
  • I/O modes
    • async with tokio
    • async-std
    • synchronous with std only
  • codec depacketization
    • video
      • H.264
        • SVC
        • periodic infra refresh
        • multiple slices per picture
        • multiple SPS/PPS
        • interleaved mode
        • AAC output format
        • Annex B output format (#44)
        • (RFC 6184)
      • MJPEG
    • audio
      • AAC
        • interleaving
      • RFC 3551 codecs: G.711, G.723, L8/L16
    • application: ONVIF metadata
  • clean, stable API. (See #47.)
  • quality errors
    • detailed error description text.
    • programmatically inspectable error type.
  • good functional testing coverage. (Currently lightly / unevenly tested. Most depacketizers have no tests.)
  • fuzz testing. (In progress.)
  • benchmark

Help welcome!

Getting started

Try the mp4 example. It streams from an RTSP server to a .mp4 file until you hit ctrl-C.

$ cargo run --package client mp4 --url rtsp://ip.address.goes.here/ --username admin --password test out.mp4
...
^C

Example client

$ cargo run --package client <CMD>

Where CMD:

  • info - Gets info about available streams and exits.
  • mp4 - Writes RTSP streams to mp4 file; exit with Ctrl+C.
  • onvif - Gets realtime onvif metadata if available; exit with Ctrl+C.
  • jpeg - Writes depacketized JPEG images to disk; exit with CTRL+C.

Example WebRTC proxy

This allows viewing a H.264 video stream from your browser, with the help of webrtc-rs.

$ cargo run --package webrtc-proxy -- --help

Acknowledgements

This builds on the whole Rust ecosystem. A couple folks have been especially helpful:

Why "retina"?

It's a working name. Other ideas welcome. I started by looking at dictionary words with the letters R, T, S, and P in order and picking out ones related to video:

$ egrep '^r.*t.*s.*p' /usr/share/dict/words'
retinoscope close but too long, thus retina
retrospect good name for an NVR, but I already picked Moonfire
rotascope misspelling of "rotascope" (animation tool) or archaic name for "gyroscope"?

License

Your choice of MIT or Apache; see LICENSE-MIT.txt or LICENSE-APACHE, respectively.

Dependencies

~9–22MB
~280K SLoC