reorganize filler code, better ffprobe log, no stream_loop when duration is long enough
This commit is contained in:
parent
baf10cfdda
commit
88254226f7
@ -12,7 +12,8 @@ use simplelog::*;
|
||||
|
||||
use ffplayout_lib::utils::{
|
||||
check_sync, gen_dummy, get_delta, get_sec, is_close, is_remote, json_serializer::read_json,
|
||||
modified_time, seek_and_length, valid_source, Media, PlayoutConfig, PlayoutStatus, DUMMY_LEN,
|
||||
loop_input, modified_time, seek_and_length, valid_source, Media, MediaProbe, PlayoutConfig,
|
||||
PlayoutStatus, DUMMY_LEN,
|
||||
};
|
||||
|
||||
/// Struct for current playlist.
|
||||
@ -470,20 +471,30 @@ fn gen_source(
|
||||
));
|
||||
node.add_filter(config, filter_chain);
|
||||
} else {
|
||||
let duration = node.out - node.seek;
|
||||
if node.source.is_empty() {
|
||||
warn!(
|
||||
"Generate filler with <yellow>{:.2}</> seconds length!",
|
||||
node.out - node.seek
|
||||
);
|
||||
warn!("Generate filler with <yellow>{duration:.2}</> seconds length!");
|
||||
} else {
|
||||
error!("Source not found: <b><magenta>{}</></b>", node.source);
|
||||
}
|
||||
let (source, cmd) = gen_dummy(config, node.out - node.seek);
|
||||
node.source = source.clone();
|
||||
node.cmd = Some(cmd);
|
||||
|
||||
if source == config.storage.filler_clip {
|
||||
let probe = MediaProbe::new(&config.storage.filler_clip);
|
||||
|
||||
if let Some(length) = probe
|
||||
.format
|
||||
.and_then(|f| f.duration)
|
||||
.and_then(|d| d.parse::<f64>().ok())
|
||||
{
|
||||
// create placeholder from config filler.
|
||||
let cmd = loop_input(&config.storage.filler_clip, length, duration);
|
||||
node.source = config.storage.filler_clip.clone();
|
||||
node.cmd = Some(cmd);
|
||||
node.add_probe();
|
||||
} else {
|
||||
// create colored placeholder.
|
||||
let (source, cmd) = gen_dummy(config, duration);
|
||||
node.source = source;
|
||||
node.cmd = Some(cmd);
|
||||
}
|
||||
|
||||
node.add_filter(config, filter_chain);
|
||||
|
@ -198,7 +198,7 @@ impl MediaProbe {
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
"Can't read source '{input}' with ffprobe, source is probably damaged! Error is: {e:?}"
|
||||
"Can't read source <b><magenta>{input}</></b> with ffprobe, source not exists or damaged! Error is: {e:?}"
|
||||
);
|
||||
|
||||
MediaProbe {
|
||||
@ -395,39 +395,28 @@ pub fn check_sync(config: &PlayoutConfig, delta: f64) -> bool {
|
||||
}
|
||||
|
||||
/// Loop source until target duration is reached.
|
||||
fn loop_input(source: &str, source_duration: f64, target_duration: f64) -> Vec<String> {
|
||||
pub fn loop_input(source: &str, source_duration: f64, target_duration: f64) -> Vec<String> {
|
||||
let loop_count = (target_duration / source_duration).ceil() as i32;
|
||||
let mut cmd = vec![];
|
||||
|
||||
info!("Loop <b><magenta>{source}</></b> <yellow>{loop_count}</> times, total duration: {target_duration:.2}");
|
||||
if loop_count > 1 {
|
||||
info!("Loop <b><magenta>{source}</></b> <yellow>{loop_count}</> times, total duration: <yellow>{target_duration:.2}</>");
|
||||
|
||||
vec_strings![
|
||||
"-stream_loop",
|
||||
loop_count.to_string(),
|
||||
cmd.append(&mut vec_strings!["-stream_loop", loop_count.to_string()]);
|
||||
}
|
||||
|
||||
cmd.append(&mut vec_strings![
|
||||
"-i",
|
||||
source,
|
||||
"-t",
|
||||
target_duration.to_string()
|
||||
]
|
||||
]);
|
||||
|
||||
cmd
|
||||
}
|
||||
|
||||
/// Create a dummy clip as a placeholder for missing video files.
|
||||
pub fn gen_dummy(config: &PlayoutConfig, duration: f64) -> (String, Vec<String>) {
|
||||
// create placeholder from config filler.
|
||||
if Path::new(&config.storage.filler_clip).is_file() {
|
||||
let probe = MediaProbe::new(&config.storage.filler_clip);
|
||||
|
||||
if let Some(length) = probe
|
||||
.format
|
||||
.and_then(|f| f.duration)
|
||||
.and_then(|d| d.parse::<f64>().ok())
|
||||
{
|
||||
let cmd = loop_input(&config.storage.filler_clip, length, duration);
|
||||
|
||||
return (config.storage.filler_clip.clone(), cmd);
|
||||
}
|
||||
}
|
||||
|
||||
// create colored placeholder.
|
||||
let color = "#121212";
|
||||
let source = format!(
|
||||
"color=c={color}:s={}x{}:d={duration}",
|
||||
|
Loading…
Reference in New Issue
Block a user