diff --git a/Cargo.lock b/Cargo.lock index 737636c..d444578 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1206,7 +1206,6 @@ dependencies = [ "serde", "serde_json", "sha2", - "tokio 1.2.0", "walkdir", ] diff --git a/Cargo.toml b/Cargo.toml index f0ee5a5..a5c2f64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ image = "0.23.7" walkdir = "2" rayon = "1.3" notify = "4.0" -tokio = "1" path-absolutize = "3.0.6" log="0.4" env_logger="0.8" diff --git a/src/main.rs b/src/main.rs index fb7e310..70cd111 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,11 @@ use std::sync::Arc; use actix::{Actor, Addr}; use actix_files::NamedFile; use actix_multipart as mp; -use actix_web::web::{HttpRequest, HttpResponse, Json}; use actix_web::{get, post, web, App, HttpServer, Responder}; +use actix_web::{ + middleware, + web::{HttpRequest, HttpResponse, Json}, +}; use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; use rayon::prelude::*; use serde::Serialize; @@ -157,7 +160,7 @@ async fn generate_video( let filename = name.to_str().expect("Filename should convert to string"); let playlist = format!("tmp/{}.m3u8", filename); if let Some(path) = is_valid_path(&body.path) { - if let Ok(child) = create_playlist(&path.to_str().unwrap(), &playlist) { + if let Ok(child) = create_playlist(&path.to_str().unwrap(), &playlist).await { data.stream_manager .do_send(ProcessMessage(playlist.clone(), child)); } diff --git a/src/video.rs b/src/video.rs index 4395e66..c143621 100644 --- a/src/video.rs +++ b/src/video.rs @@ -39,7 +39,7 @@ impl Handler for StreamActor { } } -pub fn create_playlist(video_path: &str, playlist_file: &str) -> Result { +pub async fn create_playlist(video_path: &str, playlist_file: &str) -> Result { 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 { .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 { 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)