ffmpeg stuff
This commit is contained in:
75
src/main.rs
75
src/main.rs
@@ -1,38 +1,61 @@
|
||||
use physarum::model;
|
||||
use physarum::{
|
||||
imgdata::{ImgData, ThinGridData},
|
||||
model,
|
||||
};
|
||||
use std::io::Write;
|
||||
|
||||
fn main() {
|
||||
// # of iterations to go through
|
||||
let n_iterations = 1024;
|
||||
// let n_iterations = 2048;
|
||||
// let n_iterations = 1 << 14;
|
||||
|
||||
// Size of grid and pictures
|
||||
// let (width, height) = (256, 256);
|
||||
// let (width, height) = (512, 512);
|
||||
let (width, height) = (1024, 1024);
|
||||
|
||||
// # of agents
|
||||
// let n_particles = 1 << 10;
|
||||
// let n_particles = 1 << 16;
|
||||
// let n_particles = 1 << 20;
|
||||
let n_particles = 1 << 24;
|
||||
println!("n_particles: {}", n_particles);
|
||||
|
||||
let n_particles = 1 << 22;
|
||||
let diffusivity = 1;
|
||||
|
||||
// `n_populations` is the # of types of agents
|
||||
// let n_populations = 4;
|
||||
let n_populations = 1;
|
||||
// let n_populations = 1 + rng.gen_range(1..4); // make # of populations between 2 and 5
|
||||
|
||||
let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity); // Create the model
|
||||
let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity);
|
||||
model.print_configurations();
|
||||
|
||||
model.print_configurations(); // Print config for model
|
||||
// Setup ffmpeg
|
||||
let mut ffmpeg = std::process::Command::new("ffmpeg")
|
||||
.args(&[
|
||||
"-y",
|
||||
"-f",
|
||||
"rawvideo",
|
||||
"-pix_fmt",
|
||||
"rgb24",
|
||||
"-s",
|
||||
&format!("{}x{}", width, height),
|
||||
"-r",
|
||||
"30",
|
||||
"-i",
|
||||
"-",
|
||||
"-c:v",
|
||||
"libx264",
|
||||
"-preset",
|
||||
"fast",
|
||||
"-crf",
|
||||
"23",
|
||||
"output.mp4",
|
||||
])
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.expect("Failed to start ffmpeg");
|
||||
let mut stdin = ffmpeg.stdin.take().unwrap();
|
||||
|
||||
model.run(n_iterations); // Actually run the model
|
||||
for _ in 0..n_iterations {
|
||||
model.step();
|
||||
|
||||
// export saved image data
|
||||
println!("Rendering all saved image data....");
|
||||
model.render_all_imgdata();
|
||||
// Generate image
|
||||
let grids = ThinGridData::new_from_grid_vec(model.population_grids());
|
||||
let img_data = ImgData::new(grids, model.palette());
|
||||
let img = img_data.to_image();
|
||||
let raw_data = img.into_raw();
|
||||
|
||||
// Write to ffmpeg
|
||||
stdin.write_all(&raw_data).unwrap();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
drop(stdin);
|
||||
ffmpeg.wait().unwrap();
|
||||
println!("Done!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user