Make playlist generation async

This should allow other requests to be answered while we wait for ffmpeg
to do its thing.
This commit is contained in:
Cameron Cordes
2021-02-27 11:53:29 -05:00
parent e5ad88abd6
commit 1c7e54d355
4 changed files with 8 additions and 7 deletions

View File

@@ -39,7 +39,7 @@ impl Handler<ProcessMessage> for StreamActor {
}
}
pub fn create_playlist(video_path: &str, playlist_file: &str) -> Result<Child> {
pub async fn create_playlist(video_path: &str, playlist_file: &str) -> Result<Child> {
if Path::new(playlist_file).exists() {
debug!("Playlist already exists: {}", playlist_file);
return Err(std::io::Error::from(std::io::ErrorKind::AlreadyExists));
@@ -51,7 +51,7 @@ pub fn create_playlist(video_path: &str, playlist_file: &str) -> Result<Child> {
.arg("-c:v")
.arg("h264")
.arg("-crf")
.arg("23")
.arg("21")
.arg("-preset")
.arg("veryfast")
.arg("-hls_time")
@@ -67,7 +67,7 @@ pub fn create_playlist(video_path: &str, playlist_file: &str) -> Result<Child> {
let start_time = std::time::Instant::now();
loop {
std::thread::sleep(std::time::Duration::from_secs(1));
actix::clock::delay_for(std::time::Duration::from_secs(1)).await;
if Path::new(playlist_file).exists()
|| std::time::Instant::now() - start_time > std::time::Duration::from_secs(5)