start with text filter

This commit is contained in:
jb-alvarado 2022-03-15 16:52:36 +01:00
parent 4c045a778f
commit e80f2c93d9

View File

@ -1,5 +1,6 @@
use std::path::Path;
use regex::Regex;
use simplelog::*;
use crate::utils::{is_close, GlobalConfig, Media};
@ -191,6 +192,35 @@ fn extend_video(node: &mut Media, chain: &mut Filters) {
}
}
fn add_text(node: &mut Media, chain: &mut Filters, config: &GlobalConfig) {
// add drawtext filter for lower thirds messages
if config.text.add_text && config.text.over_pre {
let mut font: String = "".to_string();
let filter: String;
if Path::new(&config.text.fontfile).is_file() {
font = format!(":fontfile='{}'", config.text.fontfile)
}
if config.text.text_from_filename {
let source = node.source.clone();
let regex: Regex = Regex::new(config.text.regex.as_str()).unwrap();
let text: String = regex.captures(source.as_str()).unwrap()[0].to_string();
let escape = text.replace("'", "'\\\\\\''").replace("%", "\\\\\\%");
filter = format!("drawtext=text='{escape}':{}{font}", config.text.style)
} else {
filter = format!(
"null,zmq=b=tcp\\\\://'{}',drawtext=text=''{}",
config.text.bind_address, font
)
}
chain.add_filter(filter, "video".into())
}
}
fn add_audio(node: &mut Media, chain: &mut Filters) {
let audio_streams = node.probe.clone().unwrap().audio_streams.unwrap();
if audio_streams.len() == 0 {
@ -278,6 +308,7 @@ pub fn filter_chains(node: &mut Media) -> Vec<String> {
&config,
);
extend_video(node, &mut filters);
add_text(node, &mut filters, &config);
add_audio(node, &mut filters);
extend_audio(node, &mut filters);
}