Another minor change
This commit is contained in:
parent
dbb7950ef6
commit
0b64592453
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,11 +6,9 @@
|
||||
/output.txt
|
||||
/src/tests/morbius.webm
|
||||
/yt-dlp
|
||||
<<<<<<< HEAD
|
||||
/test.mp4
|
||||
=======
|
||||
/src/demo
|
||||
/src/tests/demo.zip
|
||||
/.DS_Store
|
||||
/src/.DS_Store
|
||||
>>>>>>> 463b110dde30173b32b4390f65df0e26aa264976
|
||||
/test2.mp4
|
BIN
output.zip
Normal file
BIN
output.zip
Normal file
Binary file not shown.
150
src/etcher.rs
150
src/etcher.rs
@ -171,7 +171,7 @@ fn etch_pixel(frame: &mut EmbedSource, rgb: Vec<u8>, x: i32, y: i32) -> anyhow::
|
||||
|
||||
fn etch_bw(source: &mut EmbedSource, data: &Vec<bool>, global_index: &mut usize)
|
||||
-> anyhow::Result<()> {
|
||||
// let _timer = Timer::new("Etching frame");
|
||||
let _timer = Timer::new("Etching frame");
|
||||
|
||||
let width = source.actual_size.width;
|
||||
let height = source.actual_size.height;
|
||||
@ -208,7 +208,7 @@ fn etch_bw(source: &mut EmbedSource, data: &Vec<bool>, global_index: &mut usize)
|
||||
|
||||
fn etch_color(source: &mut EmbedSource, data: &Vec<u8>, global_index: &mut usize)
|
||||
-> anyhow::Result<()>{
|
||||
// let _timer = Timer::new("Etching frame");
|
||||
let _timer = Timer::new("Etching frame");
|
||||
|
||||
let width = source.actual_size.width;
|
||||
let height = source.actual_size.height;
|
||||
@ -536,7 +536,8 @@ pub fn read(path: &str, threads: usize) -> anyhow::Result<Vec<u8>> {
|
||||
let instruction_source = EmbedSource::from(frame.clone(), instruction_size);
|
||||
let (out_mode, final_frame, final_byte, settings) = read_instructions(&instruction_source, threads)?;
|
||||
|
||||
let mut frames: Vec<Mat> = Vec::new();
|
||||
let mut byte_data = Vec::new();
|
||||
let mut current_frame = 1;
|
||||
loop {
|
||||
// let _timer = Timer::new("Reading frame (clone included)");
|
||||
video.read(&mut frame)?;
|
||||
@ -546,58 +547,107 @@ pub fn read(path: &str, threads: usize) -> anyhow::Result<Vec<u8>> {
|
||||
break;
|
||||
}
|
||||
|
||||
frames.push(frame.clone());
|
||||
}
|
||||
if current_frame % 20 == 0 {
|
||||
println!("On frame: {}", current_frame);
|
||||
}
|
||||
|
||||
//Required so that data is continuous between each thread
|
||||
let chunk_size = (frames.len() / settings.threads) + 1;
|
||||
let source = EmbedSource::from(frame.clone(), settings.size);
|
||||
|
||||
let mut spool = Vec::new();
|
||||
let chunks = frames.chunks(chunk_size);
|
||||
//Can get rid of final_frame because of this
|
||||
for chunk in chunks {
|
||||
let chunk_copy = chunk.to_vec();
|
||||
//Checks if this is final thread
|
||||
let final_frame = if spool.len() == settings.threads - 1 {
|
||||
chunk_copy.len() as i32
|
||||
} else {
|
||||
-1
|
||||
let frame_data = match out_mode {
|
||||
OutputMode::Color => {
|
||||
read_color(&source, current_frame, 99999999, final_byte).unwrap()
|
||||
},
|
||||
OutputMode::Binary => {
|
||||
let binary_data = read_bw(&source, current_frame, final_frame, final_byte).unwrap();
|
||||
translate_u8(binary_data).unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
let thread = thread::spawn(move || {
|
||||
let mut byte_data = Vec::new();
|
||||
let mut current_frame = 1;
|
||||
current_frame += 1;
|
||||
|
||||
for frame in chunk_copy {
|
||||
let source = EmbedSource::from(frame, settings.size);
|
||||
|
||||
let frame_data = match out_mode {
|
||||
OutputMode::Color => {
|
||||
read_color(&source, current_frame, final_frame, final_byte).unwrap()
|
||||
},
|
||||
OutputMode::Binary => {
|
||||
let binary_data = read_bw(&source, current_frame, final_frame, final_byte).unwrap();
|
||||
translate_u8(binary_data).unwrap()
|
||||
}
|
||||
};
|
||||
current_frame += 1;
|
||||
|
||||
byte_data.extend(frame_data);
|
||||
}
|
||||
|
||||
println!("Dislodging thread complete!");
|
||||
return byte_data;
|
||||
});
|
||||
|
||||
spool.push(thread);
|
||||
}
|
||||
|
||||
let mut complete_data = Vec::new();
|
||||
for thread in spool {
|
||||
let byte_chunk = thread.join().unwrap();
|
||||
complete_data.extend(byte_chunk);
|
||||
byte_data.extend(frame_data);
|
||||
}
|
||||
|
||||
println!("Video read succesfully");
|
||||
return Ok(complete_data);
|
||||
}
|
||||
return Ok(byte_data);
|
||||
}
|
||||
|
||||
//Uses literally all the RAM
|
||||
// pub fn read(path: &str, threads: usize) -> anyhow::Result<Vec<u8>> {
|
||||
// let _timer = Timer::new("Dislodging frame");
|
||||
// let instruction_size = 5;
|
||||
|
||||
// let mut video = VideoCapture::from_file(&path, CAP_ANY)
|
||||
// .expect("Could not open video path");
|
||||
// let mut frame = Mat::default();
|
||||
|
||||
// //Could probably avoid cloning
|
||||
// video.read(&mut frame)?;
|
||||
// let instruction_source = EmbedSource::from(frame.clone(), instruction_size);
|
||||
// let (out_mode, final_frame, final_byte, settings) = read_instructions(&instruction_source, threads)?;
|
||||
|
||||
// let mut frames: Vec<Mat> = Vec::new();
|
||||
// loop {
|
||||
// // let _timer = Timer::new("Reading frame (clone included)");
|
||||
// video.read(&mut frame)?;
|
||||
|
||||
// //If it reads an empty image, the video stopped
|
||||
// if frame.cols() == 0 {
|
||||
// break;
|
||||
// }
|
||||
|
||||
// frames.push(frame.clone());
|
||||
// }
|
||||
|
||||
// //Required so that data is continuous between each thread
|
||||
// let chunk_size = (frames.len() / settings.threads) + 1;
|
||||
|
||||
// let mut spool = Vec::new();
|
||||
// let chunks = frames.chunks(chunk_size);
|
||||
// //Can get rid of final_frame because of this
|
||||
// for chunk in chunks {
|
||||
// let chunk_copy = chunk.to_vec();
|
||||
// //Checks if this is final thread
|
||||
// let final_frame = if spool.len() == settings.threads - 1 {
|
||||
// chunk_copy.len() as i32
|
||||
// } else {
|
||||
// -1
|
||||
// };
|
||||
|
||||
// let thread = thread::spawn(move || {
|
||||
// let mut byte_data = Vec::new();
|
||||
// let mut current_frame = 1;
|
||||
|
||||
// for frame in chunk_copy {
|
||||
// let source = EmbedSource::from(frame, settings.size);
|
||||
|
||||
// let frame_data = match out_mode {
|
||||
// OutputMode::Color => {
|
||||
// read_color(&source, current_frame, final_frame, final_byte).unwrap()
|
||||
// },
|
||||
// OutputMode::Binary => {
|
||||
// let binary_data = read_bw(&source, current_frame, final_frame, final_byte).unwrap();
|
||||
// translate_u8(binary_data).unwrap()
|
||||
// }
|
||||
// };
|
||||
// current_frame += 1;
|
||||
|
||||
// byte_data.extend(frame_data);
|
||||
// }
|
||||
|
||||
// println!("Dislodging thread complete!");
|
||||
// return byte_data;
|
||||
// });
|
||||
|
||||
// spool.push(thread);
|
||||
// }
|
||||
|
||||
// let mut complete_data = Vec::new();
|
||||
// for thread in spool {
|
||||
// let byte_chunk = thread.join().unwrap();
|
||||
// complete_data.extend(byte_chunk);
|
||||
// }
|
||||
|
||||
// println!("Video read succesfully");
|
||||
// return Ok(complete_data);
|
||||
// }
|
12
src/ui.rs
12
src/ui.rs
@ -202,13 +202,13 @@ fn dislodge_path() -> anyhow::Result<()> {
|
||||
.with_help_message("Please include name of file and extension")
|
||||
.prompt().unwrap();
|
||||
|
||||
let threads = CustomType::<usize>::new("How many threads to dedicate for processing ?")
|
||||
.with_error_message("Please type a valid number")
|
||||
.with_help_message("The more threads, the merrier")
|
||||
.with_default(8)
|
||||
.prompt()?;
|
||||
// let threads = CustomType::<usize>::new("How many threads to dedicate for processing ?")
|
||||
// .with_error_message("Please type a valid number")
|
||||
// .with_help_message("The more threads, the merrier")
|
||||
// .with_default(8)
|
||||
// .prompt()?;
|
||||
|
||||
let out_data = etcher::read(&in_path, threads)?;
|
||||
let out_data = etcher::read(&in_path, 1)?;
|
||||
etcher::write_bytes(&out_path, out_data)?;
|
||||
|
||||
return Ok(());
|
||||
|
Loading…
Reference in New Issue
Block a user