This commit is contained in:
Crispy 2024-04-14 16:39:42 +02:00
commit a1b5dd9ce8
7 changed files with 85 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/target
out/*

7
Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bad-apple-mpv"
version = "0.1.0"

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "bad-apple-mpv"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

BIN
bad_apple.webm Normal file

Binary file not shown.

BIN
bad_apple_audio.webm Normal file

Binary file not shown.

1
rustfmt.toml Normal file
View file

@ -0,0 +1 @@
hard_tabs = true

66
src/main.rs Normal file
View file

@ -0,0 +1,66 @@
use std::{env, process::Command, thread, time::Duration};
// const WIDTH: u32 = 7;
// const HEIGHT: u32 = 7;
const WIDTH: u32 = 14;
const HEIGHT: u32 = 13;
const _SIZE: u32 = WIDTH * HEIGHT;
const SCALE: u32 = 2; // resolution of chunks
const OFFSET: f32 = 0.1; // time offset for starting
fn main() {
let args: Vec<_> = env::args().collect();
if args.contains(&"gen".into()) {
generate();
} else {
launch();
}
}
fn generate() {
for x in 0..WIDTH {
for y in 0..HEIGHT {
let name = format!("out/{x:02}_{y:02}.mp4");
let index = (WIDTH - x) + (HEIGHT - y) * WIDTH;
let offset = index as f32 * OFFSET;
// println!("{name}");
// if PathBuf::from(&name).exists() {
// continue;
// }
Command::new("ffmpeg")
.arg("-i")
.arg("bad_apple.webm")
.arg("-ss")
.arg(format!("{:.1}", offset))
.arg("-filter_complex")
.arg(dbg!(format!(
"[0:v]scale={}:{}[SC];[SC]crop={SCALE}:{SCALE}:{}:{}",
WIDTH * SCALE,
HEIGHT * SCALE,
x * SCALE,
y * SCALE
)))
.arg("-an")
.arg("-y")
.arg(&name)
.spawn()
.unwrap();
}
}
}
fn launch() {
thread::sleep(Duration::from_secs(2));
Command::new("mpv")
.arg(format!("bad_apple_audio.webm"))
.spawn()
.unwrap();
for y in (0..HEIGHT).rev() {
for x in (0..WIDTH).rev() {
let name = format!("out/{x:02}_{y:02}.mp4");
Command::new("mpv").arg(name).spawn().unwrap();
thread::sleep(Duration::from_millis((1000.0 * OFFSET) as u64));
}
}
}