Struct dash_mpd::fetch::DashDownloader
source · [−]pub struct DashDownloader { /* private fields */ }Expand description
The DashDownloader allows the download of streaming media content from a DASH MPD manifest. This involves fetching the manifest file, parsing it, identifying the relevant audio and video representations, downloading all the segments, concatenating them then muxing the audio and video streams to produce a single video file including audio. This should work with both MPEG-DASH MPD manifests (where the media segments are typically placed in MPEG-2 TS containers) and for WebM-DASH.
Implementations
sourceimpl DashDownloader
impl DashDownloader
The DashDownloader follows the builder pattern to allow various optional arguments concerning the download of DASH media content (preferences concerning bitrate/quality, specifying an HTTP proxy, etc.).
Example
use dash_mpd::fetch::DashDownloader;
let url = "https://storage.googleapis.com/shaka-demo-assets/heliocentrism/heliocentrism.mpd";
match DashDownloader::new(url)
.worst_quality()
.download()
{
Ok(path) => println!("Downloaded to {:?}", path),
Err(e) => eprintln!("Download failed: {}", e),
}sourcepub fn new(mpd_url: &str) -> DashDownloader
pub fn new(mpd_url: &str) -> DashDownloader
Create a DashDownloader for the specified DASH manifest URL mpd_url.
sourcepub fn with_http_client(self, client: HttpClient) -> DashDownloader
pub fn with_http_client(self, client: HttpClient) -> DashDownloader
Specify the reqwest Client to be used for HTTP requests that download the DASH streaming media content. Allows you to specify a proxy, the user agent, custom request headers, request timeouts, etc.
Example
use dash_mpd::fetch::DashDownloader;
let client = reqwest::blocking::Client::builder()
.user_agent("Mozilla/5.0")
.timeout(Duration::new(10, 0))
.gzip(true)
.build()
.expect("Couldn't create reqwest HTTP client");
let url = "https://cloudflarestream.com/31c9291ab41fac05471db4e73aa11717/manifest/video.mpd";
let out = PathBuf::from(env::temp_dir()).join("cloudflarestream.mp4");
DashDownloader::new(url)
.with_http_client(client)
.download_to(out)sourcepub fn add_progress_observer(
self,
observer: Arc<dyn ProgressObserver>
) -> DashDownloader
pub fn add_progress_observer(
self,
observer: Arc<dyn ProgressObserver>
) -> DashDownloader
Add a observer implementing the ProgressObserver trait, that will receive updates concerning the progression of the download (allows implementation of a progress bar, for example).
sourcepub fn best_quality(self) -> DashDownloader
pub fn best_quality(self) -> DashDownloader
If the DASH manifest specifies several Adaptations with different bitrates (levels of quality), prefer the Adaptation with the highest bitrate (largest output file).
sourcepub fn worst_quality(self) -> DashDownloader
pub fn worst_quality(self) -> DashDownloader
If the DASH manifest specifies several Adaptations with different bitrates (levels of quality), prefer the Adaptation with the lowest bitrate (smallest output file).
sourcepub fn prefer_language(self, lang: String) -> DashDownloader
pub fn prefer_language(self, lang: String) -> DashDownloader
Preferred language when multiple audio streams with different languages are available. Must be in RFC 5646 format (eg. “fr” or “en-AU”). If a preference is not specified and multiple audio streams are present, the first one listed in the DASH manifest will be downloaded.
sourcepub fn video_only(self) -> DashDownloader
pub fn video_only(self) -> DashDownloader
If the media stream has separate audio and video streams, only download the video stream.
sourcepub fn audio_only(self) -> DashDownloader
pub fn audio_only(self) -> DashDownloader
If the media stream has separate audio and video streams, only download the audio stream.
sourcepub fn sleep_between_requests(self, seconds: u8) -> DashDownloader
pub fn sleep_between_requests(self, seconds: u8) -> DashDownloader
Specify a number of seconds to sleep between network requests (default 0). This provides a primitive mechanism for throttling bandwidth consumption.
sourcepub fn verbosity(self, level: u8) -> DashDownloader
pub fn verbosity(self, level: u8) -> DashDownloader
Set the verbosity level of the download process. Possible values for level:
- 0: no information is printed
- 1: basic information on the number of Periods and bandwidth of selected representations
- 2: information above + segment addressing mode
- 3 or larger: information above + size of each downloaded segment
sourcepub fn record_metainformation(self, record: bool) -> DashDownloader
pub fn record_metainformation(self, record: bool) -> DashDownloader
If record is true, record metainformation concerning the media content (origin URL, title,
source and copyright metainformation) if present in the manifest as extended attributes in the
output file.
sourcepub fn with_ffmpeg(self, ffmpeg_path: &str) -> DashDownloader
pub fn with_ffmpeg(self, ffmpeg_path: &str) -> DashDownloader
Specify the location of the ffmpeg variable, if not located in PATH.
sourcepub fn download_to<P: Into<PathBuf>>(self, out: P) -> Result<(), DashMpdError>
pub fn download_to<P: Into<PathBuf>>(self, out: P) -> Result<(), DashMpdError>
Download DASH streaming media content to the file named by out. If the output file out
already exists, its content will be overwritten.
sourcepub fn download(self) -> Result<PathBuf, DashMpdError>
pub fn download(self) -> Result<PathBuf, DashMpdError>
Download DASH streaming media content to a file in the current working directory and return
the corresponding PathBuf. The name of the output file is derived from the manifest URL. The
output file will be overwritten if it already exists.
Auto Trait Implementations
impl !RefUnwindSafe for DashDownloader
impl !Send for DashDownloader
impl !Sync for DashDownloader
impl Unpin for DashDownloader
impl !UnwindSafe for DashDownloader
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more