diff --git a/.gitignore b/.gitignore index 1d70880..bf330f4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /src/tests/Lagtrain.mp4 /src/tests/ytvid.mkv /src/tests/morbius.webm -/output.avi \ No newline at end of file +/output.avi +/setting_tests \ No newline at end of file diff --git a/Baby2.wav b/Baby2.wav deleted file mode 100644 index 59eded3..0000000 Binary files a/Baby2.wav and /dev/null differ diff --git a/Baby3.wav b/Baby3.wav deleted file mode 100644 index 936c377..0000000 Binary files a/Baby3.wav and /dev/null differ diff --git a/Baby4.wav b/Baby4.wav deleted file mode 100644 index 1c0eb32..0000000 Binary files a/Baby4.wav and /dev/null differ diff --git a/Baby5.wav b/Baby5.wav deleted file mode 100644 index 6482ed0..0000000 Binary files a/Baby5.wav and /dev/null differ diff --git a/note.txt b/note.txt new file mode 100644 index 0000000..542c634 --- /dev/null +++ b/note.txt @@ -0,0 +1,26 @@ +FPS matters more and more with increasing FPS +Weird stuff under 10fps +size 1 = data corruption +cargo build --release +720p had less crunchy sound, what about 144p ? + +WHAT TO DO ON THE ISG: +Optimize: + Find a tool for optimization + GET RID OF THAT FUCKING CLONE (Doesn't matter much) + Multithreading (thread # agnostic) +Fix the weird bug + Make blocks start from top right corner (Gives me even sizes) + make it so differentiates between regular, 16:9 size and actual size + It stops me from using anything other than 360p/720p + Might have something built in + Might be the length of file written in instructions +Test more b/w formats + What leads to max compression resistance and min runtime + See if lower resolution changes anything +u32 instructions + Might still be not enough, idk + Used for end-of-file pointers + Convert every instruction to u32 + +Use branches \ No newline at end of file diff --git a/src/embedsource.rs b/src/embedsource.rs index 6a90631..2e59917 100644 --- a/src/embedsource.rs +++ b/src/embedsource.rs @@ -15,6 +15,8 @@ impl EmbedSource { let width = width - (width % size); let height = height - (height % size); + // dbg!(width, height); + //WHy does this have to be unsafe smh unsafe { let image = Mat::new_rows_cols(height, width, CV_8UC3).unwrap(); diff --git a/src/etcher.rs b/src/etcher.rs index 5599efd..4db4df9 100644 --- a/src/etcher.rs +++ b/src/etcher.rs @@ -10,6 +10,7 @@ use opencv::videoio::{VideoWriter, VideoCapture, CAP_ANY}; use crate::settings::{Settings, OutputMode, Data, self}; use crate::embedsource::EmbedSource; +use crate::timer::Timer; //Get and write bytes from and to files. Start and end of app //sounds cooler than og name (encode) @@ -155,6 +156,7 @@ fn etch_pixel(frame: &mut EmbedSource, rgb: Vec, x: i32, y: i32) -> anyhow:: fn etch_frame(source: &mut EmbedSource, data: &Data, global_index: &mut usize) -> anyhow::Result<()>{ + let half_size = source.size/2; let width = source.width; let height = source.height; @@ -212,6 +214,8 @@ fn etch_frame(source: &mut EmbedSource, data: &Data, global_index: &mut usize) } fn read_frame(source: &EmbedSource, out_mode: &OutputMode) -> anyhow::Result>{ + // let _timer = Timer::new("Reading frame"); + let size = source.size as usize; let half_size = (source.size/2) as i32; let width = source.width; @@ -246,7 +250,7 @@ fn read_frame(source: &EmbedSource, out_mode: &OutputMode) -> anyhow::Result= 127 { + if rgb[0] >= 130 { binary_data.push(true); } else { binary_data.push(false); @@ -274,6 +278,7 @@ Potentially add ending pointer so it doesn't make useless bytes fn etch_instructions(settings: &Settings, data: &Data) -> anyhow::Result { + let mut u8_instructions: Vec = Vec::new(); //Both adds the output mode to instructions and finds last byte @@ -295,7 +300,15 @@ fn etch_instructions(settings: &Settings, data: &Data) binary_instructions.extend(last_byte_pointer); let instruction_data = Data::from_binary(binary_instructions); - let mut source = EmbedSource::new(5, settings.width, settings.height); + //Here to make sure instruction frame and the rest are of the same size + //Using EmbedSource::new() in case it changes and this code becomes disconnected from the rest + let dummy = EmbedSource::new(settings.size, settings.width, settings.height); + let width = dummy.width; + let height = dummy.height; + + //TEMPORARY + // let mut source = EmbedSource::new(5, width, height); + let mut source = EmbedSource::new(settings.size, width, height); let mut index = 0; match etch_frame(&mut source, &instruction_data, &mut index) { Ok(_) => {}, @@ -348,6 +361,7 @@ pub fn etch(path: &str, data: Data, settings: Settings) -> anyhow::Result<()> { loop { // dbg!("Looped!"); + // let _timer = Timer::new("Etching frame"); let mut source = EmbedSource::new(settings.size, settings.width, settings.height); match etch_frame(&mut source, &data, &mut index) { Ok(_) => frames.push(source), @@ -361,7 +375,9 @@ pub fn etch(path: &str, data: Data, settings: Settings) -> anyhow::Result<()> { //Mess around with lossless codecs, png seems fine //Fourcc is a code for video codecs, trying to use a lossless one let fourcc = VideoWriter::fourcc('p', 'n', 'g', ' ')?; - let frame_size = Size::new(frames[0].width, frames[0].height); + + let frame_size = Size::new(frames[1].width, frames[1].height); + dbg!(&frame_size); let mut video = VideoWriter::new(path, fourcc, settings.fps, frame_size, true)?; //Putting them in vector might be slower @@ -383,12 +399,14 @@ pub fn read(path: &str) -> anyhow::Result> { //Could probably avoid cloning video.read(&mut frame)?; - let instruction_source = EmbedSource::from(frame.clone(), 5); + //TEMPORARY + let instruction_source = EmbedSource::from(frame.clone(), 3); let (out_mode, settings) = read_instructions(&instruction_source)?; dbg!(&settings); let mut byte_data: Vec = Vec::new(); loop { + // let _timer = Timer::new("Reading frame (clone included)"); video.read(&mut frame)?; //If it reads an empty image, the video stopped diff --git a/src/main.rs b/src/main.rs index e02fd10..9772f1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod ui; mod etcher; mod settings; mod embedsource; +mod timer; use settings::{Data, Settings}; diff --git a/src/timer.rs b/src/timer.rs new file mode 100644 index 0000000..093f0bb --- /dev/null +++ b/src/timer.rs @@ -0,0 +1,23 @@ +use std::time::{self, Duration}; +use std::time::Instant; + +pub struct Timer { + title: &'static str, + time: Instant, +} + +impl Drop for Timer { + fn drop(&mut self) { + println!("{} ended in {}ms", self.title, self.time.elapsed().as_millis()); + } +} + +impl Timer { + pub fn new(title: &'static str) -> Timer { + let start = Instant::now(); + Timer { + title, + time: start, + } + } +} \ No newline at end of file diff --git a/src/ui.rs b/src/ui.rs index 657d828..8d30de4 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -75,9 +75,10 @@ fn embed_path() -> anyhow::Result<()> { .with_default("src/tests/Baby.wav") .prompt().unwrap(); + //"144p" => (192, 144), //For some reason only 360p and 720p work let (width, height) = match resolution { - "144p" => (192, 144), + "144p" => (100, 100), "240p" => (426, 240), "360p" => (640, 360), "480p" => (854, 480), @@ -138,7 +139,7 @@ fn dislodge_path() -> anyhow::Result<()> { .prompt().unwrap(); let out_path = Text::new("Where should the output go ?") - .with_default("Baby2.wav") + .with_default("setting_tests/Baby.wav") .with_help_message("Please include name of file and extension") .prompt().unwrap(); diff --git a/yt_out.mp4 b/yt_out.mp4 deleted file mode 100644 index 29f8f70..0000000 Binary files a/yt_out.mp4 and /dev/null differ diff --git a/yt_out2.mp4 b/yt_out2.mp4 deleted file mode 100644 index 30a5668..0000000 Binary files a/yt_out2.mp4 and /dev/null differ diff --git a/yt_out3.mp4 b/yt_out3.mp4 deleted file mode 100644 index 735bc54..0000000 Binary files a/yt_out3.mp4 and /dev/null differ diff --git a/yt_out5.mp4 b/yt_out5.mp4 deleted file mode 100644 index 33d78e2..0000000 Binary files a/yt_out5.mp4 and /dev/null differ