Skip to content

Commit

Permalink
clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryshell committed Nov 29, 2024
1 parent ddeb1b2 commit dd4ff66
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ TARGET_FRAME_RATE=60
# For more information, see: https://github.com/nihui/rife-ncnn-vulkan/blob/master/README.md
J=1:2:2

# libx264 or hevc_nvenc or h264_nvenc
# FFmpeg encoder
# For more information, see: https://www.ffmpeg.org/ffmpeg-codecs.html
VIDEO_ENCODER=libx264
99 changes: 38 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ members = ["aurora-cli", "aurora-core"]
[profile.release]
lto = true
strip = true
panic = "abort"
codegen-units = 1
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Aurora

Video **Frame Interpolation** using machine learning
Video frame interpolation using machine learning

Free and **TRUELY** open source
## 🚀 How to use

## 🚀 How to run

1. Download [release](https://github.com/jerryshell/aurora/releases) according to your system
1. Download from [release](https://github.com/jerryshell/aurora/releases) according to your system

2. Edit `.env` file with your preferred text editor

Expand Down
2 changes: 1 addition & 1 deletion aurora-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aurora-cli"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

[dependencies]
Expand Down
14 changes: 4 additions & 10 deletions aurora-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
fn get_j() -> String {
match std::env::var("J") {
Ok(str) => str,
Err(_) => {
let cpus = aurora_core::get_cpus();
format!("{}:{}:{}", (cpus - 1).max(1), (cpus - 1).max(2), 2)
}
}
}

pub fn run(video_filename: &str, target_frame_rate: usize) {
let origin_frame_rate = aurora_core::get_origin_frame_rate(video_filename);
tracing::info!("origin_frame_rate: {origin_frame_rate}");
Expand Down Expand Up @@ -63,6 +53,10 @@ pub fn run(video_filename: &str, target_frame_rate: usize) {
);
}

fn get_j() -> String {
std::env::var("J").unwrap_or("1:2:2".to_owned())
}

#[cfg(test)]
mod tests {
mod j {
Expand Down
8 changes: 4 additions & 4 deletions aurora-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ fn main() {
for video_filename in path_list {
tracing::info!("video_filename: {video_filename}");

let target_frame_rate = match std::env::var("TARGET_FRAME_RATE") {
Ok(str) => str.parse::<usize>().unwrap_or(60),
Err(_) => 60,
};
let target_frame_rate = std::env::var("TARGET_FRAME_RATE")
.ok()
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(60);
tracing::info!("target_frame_rate: {target_frame_rate}");

aurora_cli::run(&video_filename, target_frame_rate);
Expand Down
3 changes: 1 addition & 2 deletions aurora-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[package]
name = "aurora-core"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

[dependencies]
regex = "*"
num_cpus = "*"
tracing = "*"
2 changes: 1 addition & 1 deletion aurora-core/src/decode_frames.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub fn decode_frames(video_filename: &str, video_frames_dir_name: &str) {
let decode_frames_cmd_str = if cfg!(target_os = "windows") {
let decode_frames_cmd_str = if cfg!(windows) {
format!(
r"ffmpeg\ffmpeg.exe -y -vsync passthrough -i {video_filename} {video_frames_dir_name}/frame_%08d.png"
)
Expand Down
8 changes: 3 additions & 5 deletions aurora-core/src/encode_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ pub fn encode_video(
video_interpolate_frames_dir_name: &str,
video_filename: &str,
) {
let video_encoder = match std::env::var("VIDEO_ENCODER") {
Ok(str) => str,
Err(_) => "libx264".to_owned(),
};
let video_encoder = std::env::var("VIDEO_ENCODER").unwrap_or("libx264".to_owned());
tracing::info!("video_encoder: {video_encoder}");
let encode_video_cmd_str = if cfg!(target_os = "windows") {

let encode_video_cmd_str = if cfg!(windows) {
format!(
r"ffmpeg\ffmpeg.exe -y -framerate {target_frame_rate} -i {video_interpolate_frames_dir_name}/%08d.png -i {video_filename}_audio.m4a -c:a copy -crf 20 -c:v {video_encoder} -pix_fmt yuv420p output_{video_filename}.mp4"
)
Expand Down
4 changes: 1 addition & 3 deletions aurora-core/src/execute_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
pub fn execute_cmd(cmd: &str) -> std::process::Output {
if cfg!(target_os = "windows") {
if cfg!(windows) {
tracing::info!("windows execute_cmd: {cmd}");
let output = std::process::Command::new("cmd")
.args(["/C", cmd])
.output()
.expect("failed to execute process");
tracing::info!("windows exe ok");
output
} else {
tracing::info!("unix execute_cmd: {cmd}");
let output = std::process::Command::new("sh")
.args(["-c", cmd])
.output()
.expect("failed to execute process");
tracing::info!("unix exe ok");
output
}
}
2 changes: 1 addition & 1 deletion aurora-core/src/extract_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub fn extract_audio(video_filename: &str) -> String {
let video_extract_audio_filename = format!("{video_filename}_audio.m4a");
tracing::info!("video_extract_audio_filename: {video_extract_audio_filename}");

let extract_audio_cmd_str = if cfg!(target_os = "windows") {
let extract_audio_cmd_str = if cfg!(windows) {
format!(
r"ffmpeg\ffmpeg.exe -y -i {video_filename} -vn -acodec copy {video_extract_audio_filename}"
)
Expand Down
3 changes: 0 additions & 3 deletions aurora-core/src/get_cpus.rs

This file was deleted.

2 changes: 1 addition & 1 deletion aurora-core/src/get_origin_frame_rate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub fn get_origin_frame_rate(video_filename: &str) -> f32 {
let ffprobe_cmd_str = if cfg!(target_os = "windows") {
let ffprobe_cmd_str = if cfg!(windows) {
format!(r"ffmpeg\ffprobe.exe {video_filename}")
} else {
format!(r"ffmpeg/ffprobe {video_filename}")
Expand Down
Loading

0 comments on commit dd4ff66

Please sign in to comment.