From 884082fa0acb0f02bb8cde1ce984a68e181b9deb Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Mon, 27 Jun 2022 11:49:43 +0200 Subject: [PATCH] add null output --- README.md | 1 + assets/ffplayout.yml | 7 ++-- ffplayout-engine/src/output/mod.rs | 2 + ffplayout-engine/src/output/null.rs | 64 +++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 ffplayout-engine/src/output/null.rs diff --git a/README.md b/README.md index 1f4405a2..14c8d600 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Check the [releases](https://github.com/ffplayout/ffplayout-engine/releases/late - **stream** - **desktop** - **HLS** + - **null** (for debugging) - JSON RPC server, for getting infos about current playing and controlling - [live ingest](/docs/live_ingest.md) diff --git a/assets/ffplayout.yml b/assets/ffplayout.yml index 802e06fd..e285b9d7 100644 --- a/assets/ffplayout.yml +++ b/assets/ffplayout.yml @@ -115,10 +115,9 @@ text: regex: ^.+[/\\](.*)(.mp4|.mkv)$ out: - help_text: The final playout compression. Set the settings to your needs. - 'mode' has the standard options 'desktop', 'hls', 'stream'. Self made - outputs can be define, by adding script in output folder with an 'output' function - inside. 'preview' works only in streaming output and creates a separate preview stream. + help_text: The final playout compression. Set the settings to your needs. 'mode' + has the options 'desktop', 'hls', 'null', 'stream'. + 'preview' works only in streaming output and creates a separate preview stream. mode: 'stream' preview: false preview_param: >- diff --git a/ffplayout-engine/src/output/mod.rs b/ffplayout-engine/src/output/mod.rs index 337753a1..e223413d 100644 --- a/ffplayout-engine/src/output/mod.rs +++ b/ffplayout-engine/src/output/mod.rs @@ -11,6 +11,7 @@ use simplelog::*; mod desktop; mod hls; +mod null; mod stream; pub use hls::write_hls; @@ -55,6 +56,7 @@ pub fn player( // get ffmpeg output instance let mut enc_proc = match config.out.mode.as_str() { "desktop" => desktop::output(config, &ff_log_format), + "null" => null::output(config, &ff_log_format), "stream" => stream::output(config, &ff_log_format), _ => panic!("Output mode doesn't exists!"), }; diff --git a/ffplayout-engine/src/output/null.rs b/ffplayout-engine/src/output/null.rs new file mode 100644 index 00000000..73b73fda --- /dev/null +++ b/ffplayout-engine/src/output/null.rs @@ -0,0 +1,64 @@ +use std::process::{self, Command, Stdio}; + +use simplelog::*; + +use ffplayout_lib::filter::v_drawtext; +use ffplayout_lib::utils::{Media, PlayoutConfig}; +use ffplayout_lib::vec_strings; + +/// Desktop Output +/// +/// Instead of streaming, we run a ffplay instance and play on desktop. +pub fn output(config: &PlayoutConfig, log_format: &str) -> process::Child { + let mut enc_filter: Vec = vec![]; + + let mut enc_cmd = vec_strings![ + "-hide_banner", + "-nostats", + "-v", + log_format, + "-re", + "-i", + "pipe:0", + "-f", + "null", + "-" + ]; + + if config.text.add_text && !config.text.text_from_filename { + if let Some(socket) = config.text.bind_address.clone() { + debug!( + "Using drawtext filter, listening on address: {}", + socket + ); + + let mut filter: String = "null,".to_string(); + filter.push_str( + v_drawtext::filter_node(config, &Media::new(0, String::new(), false)).as_str(), + ); + enc_filter = vec!["-vf".to_string(), filter]; + } + } + + enc_cmd.splice(7..7, enc_filter); + + debug!( + "Encoder CMD: \"ffmpeg {}\"", + enc_cmd.join(" ") + ); + + let enc_proc = match Command::new("ffmpeg") + .args(enc_cmd) + .stdin(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + { + Err(e) => { + error!("couldn't spawn encoder process: {e}"); + panic!("couldn't spawn encoder process: {e}") + } + Ok(proc) => proc, + }; + + enc_proc +}