dash_mpd/lib.rs
1//! A Rust library for downloading media content from a DASH MPD manifest, as used for on-demand
2//! replay of TV content and video streaming services.
3//!
4//! [DASH](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP) (dynamic adaptive
5//! streaming over HTTP), also called MPEG-DASH, is a technology used for media streaming over the
6//! web, commonly used for video on demand (VOD) services. The Media Presentation Description (MPD)
7//! is a description of the resources (manifest or “playlist”) forming a streaming service, that a
8//! DASH client uses to determine which assets to request in order to perform adaptive streaming of
9//! the content. DASH MPD manifests can be used both with content encoded as MPEG and as WebM.
10//!
11//! The DASH format is formally defined in ISO/IEC standard 23009-1:2022. This version of the
12//! standard is [available for free
13//! online](https://standards.iso.org/ittf/PubliclyAvailableStandards/c083314_ISO_IEC%2023009-1_2022(en).zip).
14//! XML schema files are [available for no cost from
15//! ISO](https://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/). When
16//! MPD files in practical use diverge from the formal standard, this library prefers to
17//! interoperate with existing practice.
18//!
19//! This library provides support for downloading content (audio or video) described by an MPD
20//! manifest. This involves selecting the alternative with the most appropriate encoding (in terms
21//! of bitrate, codec, etc.), fetching segments of the content using HTTP or HTTPS requests (this
22//! functionality depends on the `reqwest` crate) and muxing audio and video segments together
23//!
24//!
25//! ## DASH features supported
26//!
27//! - VOD (static) stream manifests
28//! - Multi-period content
29//! - XLink elements (only with actuate=onLoad semantics, resolve-to-zero supported)
30//! - All forms of segment index info: SegmentBase@indexRange, SegmentTimeline,
31//! SegmentTemplate@duration, SegmentTemplate@index, SegmentList
32//! - Media containers of types supported by mkvmerge, ffmpeg, VLC and MP4Box (this includes
33//! Matroska, ISO-BMFF / CMAF / MP4, WebM, MPEG-2 TS)
34//! - Subtitles: support for WebVTT, SRT, STPP, TTML, tx3g and SMIL streams, either provided as a single media
35//! stream or as a fragmented MP4 stream.
36//!
37//! ## Limitations / unsupported features
38//!
39//! - Dynamic MPD manifests, that are used for live streaming/OTT TV
40//! - XLink with actuate=onRequest semantics
41//! - Application of MPD patches
42//
43//
44//
45// Reference libdash library: https://github.com/bitmovin/libdash
46// https://github.com/bitmovin/libdash/blob/master/libdash/libdash/source/xml/Node.cpp
47// Reference dash.js library: https://github.com/Dash-Industry-Forum/dash.js
48// Google Shaka player: https://github.com/google/shaka-player
49// The DASH code in VLC: https://code.videolan.org/videolan/vlc/-/tree/master/modules/demux/dash
50// Streamlink source code: https://github.com/streamlink/streamlink/blob/master/src/streamlink/stream/dash_manifest.py
51
52// TODO: improve handling of dynamic manifests, as per https://livesim.dashif.org/livesim/mup_30/testpic_2s/Manifest.mpd
53// TODO: handle indexRange attribute, as per https://dash.akamaized.net/dash264/TestCasesMCA/dolby/2/1/ChID_voices_71_768_ddp.mpd
54// TODO: implement MPD Patch support when downloading, with test cases from https://github.com/ab2022/mpddiffs/tree/main
55
56
57#![allow(non_snake_case)]
58
59/// If library feature `libav` is enabled, muxing support (combining audio and video streams, which
60/// are often separated out in DASH streams) is provided by ffmpeg's libav library, via the
61/// `ac_ffmpeg` crate. Otherwise, muxing is implemented by calling `mkvmerge`, `ffmpeg` or `vlc` as
62/// a subprocess.
63pub mod media;
64#[cfg(feature = "libav")]
65mod libav;
66#[cfg(not(feature = "libav"))]
67pub mod ffmpeg;
68pub mod sidx;
69pub mod fetch;
70pub mod decryption;
71pub mod subtitles;
72pub mod stpp;
73pub mod vtt;
74
75#[cfg(feature = "libav")]
76use crate::libav::{mux_audio_video, copy_video_to_container, copy_audio_to_container};
77#[cfg(not(feature = "libav"))]
78use crate::ffmpeg::{mux_audio_video, copy_video_to_container, copy_audio_to_container};
79
80#[cfg(all(feature = "sandbox", target_os = "linux"))]
81pub mod sandbox;
82
83
84pub use crate::fetch::{DashDownloader, ProgressObserver, parse_resolving_xlinks};