fix compiler error

This commit is contained in:
Daniella 2022-10-11 06:40:44 +02:00
parent 5ba44d216f
commit 9402193e1f

View file

@ -379,60 +379,62 @@ async fn main() {
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) {
let running = running.clone(); {
thread::spawn(move || { let running = running.clone();
*running.lock().unwrap() += 1; thread::spawn(move || {
let mut image = File::create(format!("vid_encoded/{n}")) *running.lock().unwrap() += 1;
.expect("encode: unable to create gif file"); let mut image = File::create(format!("vid_encoded/{n}"))
let mut encoder = Some( .expect("encode: unable to create gif file");
Encoder::new(&mut image, 240, 180, &[]).expect("encode: unable to create gif"), let mut encoder = Some(
); Encoder::new(&mut image, 240, 180, &[]).expect("encode: unable to create gif"),
encoder );
.as_mut() encoder
.unwrap() .as_mut()
.write_extension(gif::ExtensionData::new_control_ext( .unwrap()
4, .write_extension(gif::ExtensionData::new_control_ext(
gif::DisposalMethod::Any, 4,
false, gif::DisposalMethod::Any,
None, false,
)) None,
.expect("encode: unable to write extension data"); ))
encoder .expect("encode: unable to write extension data");
.as_mut() encoder
.unwrap() .as_mut()
.set_repeat(gif::Repeat::Finite(0)) .unwrap()
.expect("encode: unable to set repeat"); .set_repeat(gif::Repeat::Finite(0))
println!("encode: encoding {n}..."); .expect("encode: unable to set repeat");
for i in (n * (25 * 5))..dir { println!("encode: encoding {n}...");
{ for i in (n * (25 * 5))..dir {
let i = i + 1; {
let decoder = Decoder::new( let i = i + 1;
File::open(format!("vid/{}.png", i)) let decoder = Decoder::new(
.expect(format!("encode: unable to read vid/{}.png", i).as_str()), File::open(format!("vid/{}.png", i))
); .expect(format!("encode: unable to read vid/{}.png", i).as_str()),
let mut reader = decoder );
.read_info() let mut reader = decoder
.expect(format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str()); .read_info()
let mut buf: Vec<u8> = vec![0; reader.output_buffer_size()]; .expect(format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str());
let info = reader let mut buf: Vec<u8> = vec![0; reader.output_buffer_size()];
.next_frame(&mut buf) let info = reader
.expect(format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str()); .next_frame(&mut buf)
let bytes = &mut buf[..info.buffer_size()]; .expect(format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str());
let mut frame = gif::Frame::from_rgb(240, 180, bytes); let bytes = &mut buf[..info.buffer_size()];
frame.delay = 4; let mut frame = gif::Frame::from_rgb(240, 180, bytes);
encoder frame.delay = 4;
.as_mut() encoder
.unwrap() .as_mut()
.write_frame(&frame) .unwrap()
.expect("encode: unable to encode frame to gif"); .write_frame(&frame)
.expect("encode: unable to encode frame to gif");
}
if i / (25 * 5) != n {
break;
}
} }
if i / (25 * 5) != n { *running.lock().unwrap() -= 1;
break; println!("encode: encoded {n}");
} });
} }
*running.lock().unwrap() -= 1;
println!("encode: encoded {n}");
});
while *running.lock().unwrap() < 5 { while *running.lock().unwrap() < 5 {
tokio::time::sleep(Duration::from_millis(100)).await; tokio::time::sleep(Duration::from_millis(100)).await;
} }