Improve video streaming speed
All checks were successful
Core Repos/ImageApi/pipeline/head This commit looks good

Instead of waiting for an entire video to stream, we spawn a child
ffmpeg process to start generating the HLS playlist, and once it creates
the first part of the playlist we return the response so the client can
start streaming almost immediately. HTTP Live streaming can handle
playlist updates after the initial playlist is created, although I don't
think the user can skip to the end and skip streaming parts of the
video.
This commit is contained in:
Cameron Cordes
2021-02-08 19:46:38 -05:00
parent ecd43f776a
commit e4c23c0fe5

View File

@@ -26,11 +26,16 @@ pub fn create_playlist(video_path: &str, playlist_file: &str) {
.arg("-vf") .arg("-vf")
.arg("scale=1080:-2,setsar=1:1") .arg("scale=1080:-2,setsar=1:1")
.arg(playlist_file) .arg(playlist_file)
.output() .spawn();
.expect("Expected this to work..");
println!("{:?}", result); let start_time = std::time::Instant::now();
println!("Status: {}", String::from_utf8(result.stdout).unwrap()) loop {
std::thread::sleep(std::time::Duration::from_secs(1));
if Path::new(playlist_file).exists() || std::time::Instant::now() - start_time > std::time::Duration::from_secs(5) {
break;
}
}
} }
pub fn generate_video_thumbnail(path: &Path, destination: &Path) { pub fn generate_video_thumbnail(path: &Path, destination: &Path) {