pub mod common;
use std::fs;
use std::env;
use file_format::FileFormat;
use ffprobe::ffprobe;
use dash_mpd::fetch::DashDownloader;
use common::{check_file_size_approx, check_media_duration, setup_logging};
#[tokio::test]
async fn test_multiperiod_helio() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "https://storage.googleapis.com/shaka-demo-assets/heliocentrism/heliocentrism.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("heliocentrism-multiperiod.webm");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.download_to(&out).await
.unwrap();
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Webm);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_multiperiod_nomor5a_ffmpeg() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "https://dash.akamaized.net/dash264/TestCases/5a/nomor/1.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("nomor.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.concatenate_periods(true)
.with_concat_preference("mp4", "ffmpeg")
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 95_623_359);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_multiperiod_nomor5b_ffmpeg() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "http://dash.edgesuite.net/dash264/TestCases/5b/1/manifest.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("multiperiod-5b.mp4");
let p2 = tmpd.path().join("multiperiod-5b-p2.mp4");
let p3 = tmpd.path().join("multiperiod-5b-p3.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "ffmpeg")
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 28_755_275);
check_file_size_approx(&p2, 4_383_256);
check_file_size_approx(&p3, 31_215_605);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 3, "Expecting 3 output files, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_multiperiod_nomor5b_mkvmerge() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "http://dash.edgesuite.net/dash264/TestCases/5b/1/manifest.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("multiperiod-5b.mp4");
let p2 = tmpd.path().join("multiperiod-5b-p2.mp4");
let p3 = tmpd.path().join("multiperiod-5b-p3.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "mkvmerge")
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 28_755_275);
check_file_size_approx(&p2, 4_383_256);
check_file_size_approx(&p3, 31_215_605);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 3, "Expecting 3 output files, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_multiperiod_withsubs_ffmpeg() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "http://media.axprod.net/TestVectors/v6-Clear/MultiPeriod_Manifest_1080p.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("multiperiod-withsubs.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "ffmpeg")
.verbosity(2)
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 94_818_672);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_multiperiod_withsubs_ffmpegdemuxer() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "http://media.axprod.net/TestVectors/v6-Clear/MultiPeriod_Manifest_1080p.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("multiperiod-withsubs.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "ffmpegdemuxer")
.verbosity(2)
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 94_818_672);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_multiperiod_audio_ffmpeg() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "https://media.axprod.net/TestVectors/v7-Clear/Manifest_MultiPeriod_AudioOnly.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("multiperiod-audio.mp3");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp3", "ffmpeg")
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 23_868_589);
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg12AudioLayer3);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
async fn test_multiperiod_audio_ffmpegdemuxer() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "https://media.axprod.net/TestVectors/v7-Clear/Manifest_MultiPeriod_AudioOnly.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("multiperiod-audio.mp3");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp3", "ffmpegdemuxer")
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 23_868_589);
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg12AudioLayer3);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[ignore]
#[tokio::test]
async fn test_multiperiod_diffbase() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "https://dash.akamaized.net/dash264/TestCasesIOP33/multiplePeriods/3/manifest_multiple_Periods_Content_Offering_CDN.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("multiperiod-diffbase.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "ffmpeg")
.download_to(&out).await
.unwrap();
check_file_size_approx(&out, 245_287_205);
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg4Part14Video);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
#[cfg(not(feature = "libav"))]
async fn test_multiperiod_witha_withouta_ffmpegfilter() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "http://dash.edgesuite.net/fokus/adinsertion-samples/xlink/twoperiods.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("twoperiods.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "ffmpeg")
.download_to(&out).await
.unwrap();
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg4Part14Video);
check_file_size_approx(&out, 5_973_570);
let meta = ffprobe(&out).unwrap();
assert_eq!(meta.streams.len(), 2);
let audio = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("audio"))))
.expect("finding audio stream");
assert_eq!(audio.codec_name, Some(String::from("aac")));
let video = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("video"))))
.expect("finding video stream");
assert_eq!(video.codec_name, Some(String::from("h264")));
assert!(video.width.is_some());
check_media_duration(&out, 40.0);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
#[cfg(not(feature = "libav"))]
async fn test_multiperiod_witha_withouta_ffmpegdemuxer() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "http://dash.edgesuite.net/fokus/adinsertion-samples/xlink/twoperiods.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("twoperiods.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "ffmpegdemuxer")
.download_to(&out).await
.unwrap();
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg4Part14Video);
check_file_size_approx(&out, 5_973_570);
let meta = ffprobe(&out).unwrap();
assert_eq!(meta.streams.len(), 2);
let audio = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("audio"))))
.expect("finding audio stream");
assert_eq!(audio.codec_name, Some(String::from("aac")));
let video = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("video"))))
.expect("finding video stream");
assert_eq!(video.codec_name, Some(String::from("h264")));
assert!(video.width.is_some());
check_media_duration(&out, 40.0);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}
#[tokio::test]
#[cfg(not(feature = "libav"))]
async fn test_multiperiod_witha_withouta_witha() {
setup_logging();
if env::var("CI").is_ok() {
return;
}
let mpd_url = "http://dash.edgesuite.net/fokus/adinsertion-samples/xlink/threeperiods.mpd";
let tmpd = tempfile::tempdir().unwrap();
let out = tmpd.path().join("threeperiods.mp4");
DashDownloader::new(mpd_url)
.worst_quality()
.sandbox(true)
.with_concat_preference("mp4", "ffmpeg")
.download_to(&out).await
.unwrap();
let format = FileFormat::from_file(&out).unwrap();
assert_eq!(format, FileFormat::Mpeg4Part14Video);
check_file_size_approx(&out, 14_435_150);
let meta = ffprobe(&out).unwrap();
assert_eq!(meta.streams.len(), 2);
let audio = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("audio"))))
.expect("finding audio stream");
assert_eq!(audio.codec_name, Some(String::from("aac")));
let video = meta.streams.iter()
.find(|s| s.codec_type.eq(&Some(String::from("video"))))
.expect("finding video stream");
assert_eq!(video.codec_name, Some(String::from("h264")));
assert!(video.width.is_some());
check_media_duration(&out, 72.0);
let entries = fs::read_dir(tmpd.path()).unwrap();
let count = entries.count();
assert_eq!(count, 1, "Expecting a single output file, got {count}");
let _ = fs::remove_dir_all(tmpd);
}