This commit is contained in:
HistidineDwarf 2023-02-04 12:41:32 -08:00
parent ea147e5323
commit 867c29bf9f
15 changed files with 79 additions and 7 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@
/src/tests/Lagtrain.mp4
/src/tests/ytvid.mkv
/src/tests/morbius.webm
/output.avi
/output.avi
/setting_tests

BIN
Baby2.wav

Binary file not shown.

BIN
Baby3.wav

Binary file not shown.

BIN
Baby4.wav

Binary file not shown.

BIN
Baby5.wav

Binary file not shown.

26
note.txt Normal file
View File

@ -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

View File

@ -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();

View File

@ -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<u8>, 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<Vec<u8>>{
// 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<Vec
continue;
} else {
let rgb = rgb.unwrap();
if rgb[0] >= 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<EmbedSource> {
let mut u8_instructions: Vec<u8> = 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<Vec<u8>> {
//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<u8> = Vec::new();
loop {
// let _timer = Timer::new("Reading frame (clone included)");
video.read(&mut frame)?;
//If it reads an empty image, the video stopped

View File

@ -2,6 +2,7 @@ mod ui;
mod etcher;
mod settings;
mod embedsource;
mod timer;
use settings::{Data, Settings};

23
src/timer.rs Normal file
View File

@ -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,
}
}
}

View File

@ -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();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.