diff --git a/src/encode/codecs/mod.rs b/src/encode/codecs/mod.rs index d1b0cef..edefdae 100644 --- a/src/encode/codecs/mod.rs +++ b/src/encode/codecs/mod.rs @@ -48,6 +48,7 @@ fn write_raw(cmd_in: &mut ChildStdin, media: util::RawMedia) -> Result<(), Box, c_err: mpsc::Sender>) { + let mut i = 0; loop { let media = match c_in.recv() { Ok(x) => x, @@ -56,10 +57,22 @@ pub fn read_raw_loop(mut cmd_in: ChildStdin, c_in: mpsc::Receiver { + let yuv = media.sample.clone(); + thread::spawn(move || { + util::cursed_jpg(yuv); + }); + }, + _ => () + } + } match write_raw(&mut cmd_in, media) { Ok(_) => (), Err(err) => {util::thread_freeze(c_err, err); return} // park thread, wait for main to // exit } + i += 1; } } diff --git a/src/util/mod.rs b/src/util/mod.rs index deb7177..ffdbff0 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,9 +1,11 @@ // general use structs, functions and errors go here +use std::io::Write; use std::error::Error; use std::fmt; use std::thread; use std::sync::mpsc; +use std::process::{Command, Stdio}; // Data structs/enums @@ -236,3 +238,18 @@ pub fn thread_freeze(err_sender: mpsc::Sender>, err pub fn blank_vec(n: usize) -> Vec { return vec![0u8; n]; } + +pub fn cursed_jpg(yuv: Vec) { + let mut cmd = Command::new("ffmpeg").args([ + "-pix_fmt", "yuv420p", + "-f", "rawvideo", + "-s", "1280x720", + "-i", "-", + "-q:v", "10", + "out.jpg", + "-y", "-hide_banner", "-loglevel", "quiet", + ]).stdin(Stdio::piped()).spawn().unwrap(); + let mut stdin = cmd.stdin.take().unwrap(); + stdin.write_all(yuv.as_slice()); + drop(stdin); +}