Struct dash_mpd::fetch::DashDownloader
source · pub struct DashDownloader {
pub mpd_url: String,
pub output_path: Option<PathBuf>,
pub ffmpeg_location: String,
pub vlc_location: String,
pub mkvmerge_location: String,
/* 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.
Fields§
§mpd_url: String
§output_path: Option<PathBuf>
§ffmpeg_location: String
§vlc_location: String
§mkvmerge_location: String
Implementations§
source§impl 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("creating 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 keep_video(self) -> DashDownloader
pub fn keep_video(self) -> DashDownloader
Don’t delete the file containing video once muxing is complete.
sourcepub fn keep_audio(self) -> DashDownloader
pub fn keep_audio(self) -> DashDownloader
Don’t delete the file containing audio once muxing is complete.
sourcepub fn without_content_type_checks(self) -> DashDownloader
pub fn without_content_type_checks(self) -> DashDownloader
Don’t check that the content-type of downloaded segments corresponds to audio or video content (may be necessary with poorly configured HTTP servers).
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
application, if not located in PATH.
Example
#[cfg(target_os = "unix")]
let ddl = ddl.with_ffmpeg("/opt/ffmpeg-next/bin/ffmpeg");
sourcepub fn with_vlc(self, vlc_path: &str) -> DashDownloader
pub fn with_vlc(self, vlc_path: &str) -> DashDownloader
Specify the location of the VLC application, if not located in PATH.
Example
#[cfg(target_os = "windows")]
let ddl = ddl.with_vlc("C:/Program Files/VideoLAN/VLC/vlc.exe");
sourcepub fn with_mkvmerge(self, mkvmerge_path: &str) -> DashDownloader
pub fn with_mkvmerge(self, mkvmerge_path: &str) -> DashDownloader
Specify the location of the mkvmerge application, if not located in PATH.
sourcepub fn download_to<P: Into<PathBuf>>(
self,
out: P
) -> Result<PathBuf, DashMpdError>
pub fn download_to<P: Into<PathBuf>>(
self,
out: P
) -> Result<PathBuf, DashMpdError>
Download DASH streaming media content to the file named by out
. If the output file out
already exists, its content will be overwritten.
Note that the media container format used when muxing audio and video streams depends on
the filename extension of the path out
. If the filename extension is .mp4
, an MPEG-4
container will be used; if it is .mkv
a Matroska container will be used, and otherwise
the heuristics implemented by ffmpeg will apply (e.g. an .avi
extension will generate
an AVI container).
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.
The downloaded media will be placed in an MPEG-4 container. To select another media container,
see the download_to
function.