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
tokio
: provides aStream
implementation for theVideoStream
type using Tokio’s runtime.quickcheck
: Provides implementations ofArbitrary
for types in theconfig
module.serde
: Add implementations ofSerialize
andDeserialize
for types in theconfig
andcapabilities
modules.tracing
: Enable logging and instrumentation with the [tracing
] crate.
Modules
Utilities to detect a camera’s capabilities.
Types for stream and camera configuration.
Structs
An opaque type representing an fMP4 media segment.
Enums
The error type for
mp4-stream
.Functions
Creates a new video stream.
Start capturing video.
Type Definitions
A channel receiver for
MediaSegment
s.A channel for adding a subscriber to the stream.