5 releases (breaking)
new 0.5.0 | Nov 2, 2024 |
---|---|
0.4.0 | Nov 1, 2024 |
0.3.0 | Nov 1, 2024 |
0.2.0 | Nov 1, 2024 |
0.1.0 | Nov 1, 2024 |
#82 in Video
203 downloads per month
53KB
1K
SLoC
M3U8 Parser
A Rust crate for parsing and creating M3U8 version 7 files for HTTP Live Streaming (HLS), as specified by RFC 8216.
[!IMPORTANT] This project is under active development. Features and APIs may change.
Features
- Parse M3U8 playlists from strings, files, or readers
- Generate M3U8 playlists and write them to strings, files, or writers
- Support for all tags specified in RFC 8216, including:
- Basic Tags (e.g.,
#EXTM3U
,#EXT-X-VERSION
) - Media Segment Tags (e.g.,
#EXTINF
,#EXT-X-BYTERANGE
) - Media Playlist Tags (e.g.,
#EXT-X-TARGETDURATION
,#EXT-X-MEDIA-SEQUENCE
) - Master Playlist Tags (e.g.,
#EXT-X-STREAM-INF
,#EXT-X-MEDIA
) - Encryption Tags (e.g.,
#EXT-X-KEY
,#EXT-X-SESSION-KEY
) - Date Range Tags (e.g.,
#EXT-X-DATERANGE
)
- Basic Tags (e.g.,
Installation
Add this to your Cargo.toml
:
[dependencies]
m3u8-parser = "0.5.0"
Usage
Parsing a Playlist
use m3u8_parser::m3u8::playlist::Playlist;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = r#"
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:6
#EXTINF:5.009,
https://media.example.com/first.ts
#EXTINF:5.009,
https://media.example.com/second.ts
#EXTINF:3.003,
https://media.example.com/third.ts
#EXT-X-ENDLIST
"#;
let playlist = Playlist::from_reader(data.as_bytes())?;
println!("{:?}", playlist);
Ok(())
}
Creating a Playlist
use m3u8_parser::m3u8::playlist::builder::PlaylistBuilder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let playlist = PlaylistBuilder::new()
.extm3u()
.version(7)
.target_duration(6)
.extinf(5.009, None)
.uri("https://media.example.com/first.ts".to_string())
.extinf(5.009, None)
.uri("https://media.example.com/second.ts".to_string())
.extinf(3.003, None)
.uri("https://media.example.com/third.ts".to_string())
.end_list()
.build()?;
playlist.write_to_file("playlist.m3u8")?;
Ok(())
}