Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
9521c6cf15 |
2 changed files with 30 additions and 0 deletions
|
@ -48,6 +48,7 @@ fn write_raw(cmd_in: &mut ChildStdin, media: util::RawMedia) -> Result<(), Box<d
|
|||
}
|
||||
|
||||
pub fn read_raw_loop(mut cmd_in: ChildStdin, c_in: mpsc::Receiver<util::RawMedia>, c_err: mpsc::Sender<Box<dyn Error + Send + Sync>>) {
|
||||
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<util::RawMedia
|
|||
// needed, park to keep c_err
|
||||
// allocated
|
||||
};
|
||||
if i % 30 == 0 {
|
||||
match media.media_type {
|
||||
util::RawMediaType::YUV420P => {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Box<dyn Error + Send + Sync>>, err
|
|||
pub fn blank_vec(n: usize) -> Vec<u8> {
|
||||
return vec![0u8; n];
|
||||
}
|
||||
|
||||
pub fn cursed_jpg(yuv: Vec<u8>) {
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue