fix logic error
This commit is contained in:
parent
319a6385dd
commit
c9d7f0c2ad
1 changed files with 48 additions and 46 deletions
|
@ -327,7 +327,7 @@ impl EventHandler for Handler {
|
||||||
async fn main() {
|
async fn main() {
|
||||||
if !Path::new("vid_encoded/").is_dir() {
|
if !Path::new("vid_encoded/").is_dir() {
|
||||||
println!("encode: encoding video...");
|
println!("encode: encoding video...");
|
||||||
fs::create_dir("vid").expect("encode: unable to modify files");
|
if let Ok(_) = fs::create_dir("vid") {
|
||||||
let mut command = process::Command::new("ffmpeg")
|
let mut command = process::Command::new("ffmpeg")
|
||||||
.args([
|
.args([
|
||||||
"-i",
|
"-i",
|
||||||
|
@ -372,17 +372,18 @@ async fn main() {
|
||||||
fs::rename("aud.opus", "aud_encoded")
|
fs::rename("aud.opus", "aud_encoded")
|
||||||
.expect("encode: unable to move aud.opus to aud_encoded");
|
.expect("encode: unable to move aud.opus to aud_encoded");
|
||||||
|
|
||||||
fs::create_dir("vid_encoded").expect("encode: unable to modify files");
|
}
|
||||||
|
let _ = fs::create_dir("vid_encoded");
|
||||||
let dir = fs::read_dir("vid")
|
let dir = fs::read_dir("vid")
|
||||||
.expect("encode: unable to read files")
|
.expect("encode: unable to read files")
|
||||||
.count();
|
.count();
|
||||||
let running = Arc::new(Mutex::new(0));
|
let running = Arc::new(Mutex::new(0));
|
||||||
println!("encode: encoding gifs...");
|
println!("encode: encoding gifs...");
|
||||||
for n in 0..((dir as f32 / (25.0 * 5.0)).ceil() as usize) {
|
for n in 0..((dir as f32 / (25.0 * 5.0)).ceil() as usize) {
|
||||||
|
*running.lock().unwrap() += 1;
|
||||||
{
|
{
|
||||||
let running = running.clone();
|
let running = running.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
*running.lock().unwrap() += 1;
|
|
||||||
let mut image = File::create(format!("vid_encoded/{n}"))
|
let mut image = File::create(format!("vid_encoded/{n}"))
|
||||||
.expect("encode: unable to create gif file");
|
.expect("encode: unable to create gif file");
|
||||||
let mut encoder = Some(
|
let mut encoder = Some(
|
||||||
|
@ -438,6 +439,7 @@ async fn main() {
|
||||||
while *running.lock().unwrap() >= 6 {
|
while *running.lock().unwrap() >= 6 {
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
|
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||||
}
|
}
|
||||||
while *running.lock().unwrap() != 0 {
|
while *running.lock().unwrap() != 0 {
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
|
Loading…
Reference in a new issue