diff --git a/src/filter/mod.rs b/src/filter/mod.rs index b85d5d46..9c99aa68 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -74,23 +74,13 @@ fn deinterlace(field_order: &Option, chain: &mut Filters) { fn pad(aspect: f64, chain: &mut Filters, config: &GlobalConfig) { if !is_close(aspect, config.processing.aspect, 0.03) { - if aspect < config.processing.aspect { - chain.add_filter( - &format!( - "pad=ih*{}/{}/sar:ih:(ow-iw)/2:(oh-ih)/2", - config.processing.width, config.processing.height - ), - "video", - ) - } else if aspect > config.processing.aspect { - chain.add_filter( - &format!( - "pad=iw:iw*{}/{}/sar:(ow-iw)/2:(oh-ih)/2", - config.processing.width, config.processing.height - ), - "video", - ) - } + chain.add_filter( + &format!( + "pad=max(iw\\,ih*({0}/{1})):ow/({0}/{1}):(ow-iw)/2:(oh-ih)/2", + config.processing.width, config.processing.height + ), + "video", + ) } } diff --git a/src/input/playlist.rs b/src/input/playlist.rs index 6606b329..bc497d66 100644 --- a/src/input/playlist.rs +++ b/src/input/playlist.rs @@ -12,7 +12,7 @@ use simplelog::*; use crate::utils::{ check_sync, gen_dummy, get_delta, get_sec, is_close, json_serializer::read_json, modified_time, - seek_and_length, validate_source, GlobalConfig, Media, PlayoutStatus, DUMMY_LEN, + seek_and_length, valid_source, GlobalConfig, Media, PlayoutStatus, DUMMY_LEN, }; /// Struct for current playlist. @@ -430,7 +430,7 @@ fn timed_source( /// Generate the source CMD, or when clip not exist, get a dummy. fn gen_source(config: &GlobalConfig, mut node: Media) -> Media { - if validate_source(&node.source) { + if valid_source(&node.source) { node.add_probe(); node.cmd = Some(seek_and_length( node.source.clone(), @@ -440,13 +440,13 @@ fn gen_source(config: &GlobalConfig, mut node: Media) -> Media { )); node.add_filter(config); } else { - if node.source.chars().count() == 0 { + if node.source.is_empty() { warn!( "Generate filler with {:.2} seconds length!", node.out - node.seek ); } else { - error!("File not found: {}", node.source); + error!("Source not found: {}", node.source); } let (source, cmd) = gen_dummy(config, node.out - node.seek); node.source = source; diff --git a/src/utils/json_validate.rs b/src/utils/json_validate.rs index f8eb7446..f16024bf 100644 --- a/src/utils/json_validate.rs +++ b/src/utils/json_validate.rs @@ -5,7 +5,7 @@ use std::sync::{ use simplelog::*; -use crate::utils::{sec_to_time, validate_source, GlobalConfig, MediaProbe, Playlist}; +use crate::utils::{sec_to_time, valid_source, GlobalConfig, MediaProbe, Playlist}; /// Validate a given playlist, to check if: /// @@ -28,7 +28,7 @@ pub fn validate_playlist(playlist: Playlist, is_terminated: Arc, con return; } - if validate_source(&item.source) { + if valid_source(&item.source) { let probe = MediaProbe::new(&item.source); if probe.format.is_none() { @@ -40,7 +40,7 @@ pub fn validate_playlist(playlist: Playlist, is_terminated: Arc, con } } else { error!( - "File on position {} not exists: {}", + "Source on position {} not exists: {}", sec_to_time(begin), item.source ); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 949a6258..36362424 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -432,17 +432,11 @@ pub fn prepare_output_cmd( /// Validate input /// /// Check if input is a remote source, or from storage and see if it exists. -pub fn validate_source(source: &str) -> bool { +pub fn valid_source(source: &str) -> bool { let re = Regex::new(r"^https?://.*").unwrap(); - if re.is_match(source) { - match MediaProbe::new(source).video_streams { - Some(_) => return true, - None => { - error!("Remote file not exist: {source}"); - return false; - } - } + if re.is_match(source) && MediaProbe::new(source).video_streams.is_some() { + return true; } Path::new(&source).is_file()