Crate mp4_stream

Source
Expand description

A fast and easy to use fMP4 streaming implementation.

mp4-stream is an efficient and scalable implementation of fragmented MP4 video streaming. It uses channels to separate video capture and encoding from MP4 muxing, making it possible to stream live video over multiple connections. It can also handle live configuration updates, which require restarting the individual streams, but the video capture worker does not have to be restarted.

§Example

use mp4_stream::{config::Config, VideoStream, stream_media_segments};
use std::{fs, thread, io::Write};

// Create a configuration
let config = Config::default();
let config_clone = config.clone();
// Create a channel to send requests for video data on
let (tx, rx) = flume::unbounded();
// Start another thread to capture video and send it on the channel
thread::spawn(move || {
    stream_media_segments(rx, config_clone, None).unwrap();
});

let mut file = fs::File::create("video.mp4")?;
// Create a stream from the channel
let stream = VideoStream::new(&config, tx)?;
// Take the first 10 segments and write them to a file
for segment in stream.take(10) {
    file.write_all(&segment?)?;
}

§Cargo Features

Modules§

capabilities
Utilities to detect a camera’s capabilities.
config
Types for stream and camera configuration.

Structs§

MediaSegment
An opaque type representing an fMP4 media segment.

Enums§

Error
The error type for mp4-stream.

Functions§

stream
Creates a new video stream.
stream_media_segments
Start capturing video.

Type Aliases§

MediaSegReceiver
A channel receiver for MediaSegments.
Result
A Result type alias for mp4-stream’s Error type.
StreamSubscriber
A channel for adding a subscriber to the stream.