Skip to content

Commit

Permalink
fix windows cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryshell committed Feb 12, 2023
1 parent f2ddeb0 commit 728bceb
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions aurora-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ fn extract_audio(video_filename: &str) -> String {
let video_extract_audio_filename = format!("{video_filename}_audio.m4a");
println!("video_extract_audio_filename: {video_extract_audio_filename}");

let extract_audio_cmd_str =
format!("ffmpeg -y -i {video_filename} -vn -acodec copy {video_extract_audio_filename}");
let extract_audio_cmd_str = if cfg!(target_os = "windows") {
format!("ffmpeg.exe -y -i {video_filename} -vn -acodec copy {video_extract_audio_filename}")
} else {
format!("ffmpeg -y -i {video_filename} -vn -acodec copy {video_extract_audio_filename}")
};
println!("extract_audio_cmd_str: {extract_audio_cmd_str}");

let extract_audio_output = execute_cmd(&extract_audio_cmd_str);
Expand All @@ -29,21 +32,21 @@ fn video_frames_dir_mkdir(video_filename: &str) -> String {
let video_frames_dir_name = format!("{video_filename}_frames");
println!("video_frames_dir_name {video_frames_dir_name}");

let video_frames_dir_mkdir_cmd_str = format!("mkdir {video_frames_dir_name}");
println!("video_frames_dir_mkdir_cmd_str: {video_frames_dir_mkdir_cmd_str}");

let mkdir_cmd_output = execute_cmd(&video_frames_dir_mkdir_cmd_str);
println!("mkdir_cmd_output: {mkdir_cmd_output:?}");
let video_frames_dir_mkdir_result = std::fs::create_dir(&video_frames_dir_name);
println!("video_frames_dir_mkdir_result: {video_frames_dir_mkdir_result:?}");

video_frames_dir_name
}

fn decode_frames(video_filename: &str, video_frames_dir_name: &str) {
let decode_frames_cmd =
format!("ffmpeg -y -i {video_filename} {video_frames_dir_name}/frame_%08d.png");
println!("decode_frames_cmd: {decode_frames_cmd}");
let decode_frames_cmd_str = if cfg!(target_os = "windows") {
format!("ffmpeg.exe -y -i {video_filename} {video_frames_dir_name}/frame_%08d.png")
} else {
format!("ffmpeg -y -i {video_filename} {video_frames_dir_name}/frame_%08d.png")
};
println!("decode_frames_cmd_str: {decode_frames_cmd_str}");

let decode_frames_cmd_output = execute_cmd(&decode_frames_cmd);
let decode_frames_cmd_output = execute_cmd(&decode_frames_cmd_str);
println!("decode_frames_cmd_output: {decode_frames_cmd_output:?}");
}

Expand All @@ -55,7 +58,11 @@ fn get_origin_frame_count(video_frames_dir_name: &str) -> usize {
}

fn get_origin_frame_rate(video_filename: &str) -> f32 {
let ffprobe_cmd_str = format!("ffprobe {video_filename}");
let ffprobe_cmd_str = if cfg!(target_os = "windows") {
format!("ffprobe.exe {video_filename}")
} else {
format!("ffprobe {video_filename}")
};
println!("ffprobe_cmd_str: {ffprobe_cmd_str}");

let ffprobe_cmd_output = execute_cmd(&ffprobe_cmd_str);
Expand All @@ -82,11 +89,12 @@ fn video_interpolate_frames_dir_mkdir(video_filename: &str) -> String {
let video_interpolate_frames_dir_name = format!("{video_filename}_interpolate_frames");
println!("video_interpolate_frames_dir_name: {video_interpolate_frames_dir_name}");

let mkdir_cmd_str = format!("mkdir {video_interpolate_frames_dir_name}");
println!("mkdir_cmd_str: {mkdir_cmd_str}");
let video_interpolate_frames_dir_mkdir_result =
std::fs::create_dir(&video_interpolate_frames_dir_name);
println!(
"video_interpolate_frames_dir_mkdir_result: {video_interpolate_frames_dir_mkdir_result:?}"
);

let mkdir_cmd_output = execute_cmd(&mkdir_cmd_str);
println!("mkdir_cmd_output: {mkdir_cmd_output:?}");
video_interpolate_frames_dir_name
}

Expand All @@ -95,7 +103,11 @@ fn interpolate_frame(
video_frames_dir_name: &str,
video_interpolate_frames_dir_name: &str,
) {
let interpolate_frame_cmd_str = format!("rife-ncnn-vulkan/rife-ncnn-vulkan -m rife-v4.6 -n {target_frame_count} -i {video_frames_dir_name} -o {video_interpolate_frames_dir_name}");
let interpolate_frame_cmd_str = if cfg!(target_os = "windows") {
format!("rife-ncnn-vulkan/rife-ncnn-vulkan.exe -m rife-v4.6 -n {target_frame_count} -i {video_frames_dir_name} -o {video_interpolate_frames_dir_name}")
} else {
format!("rife-ncnn-vulkan/rife-ncnn-vulkan -m rife-v4.6 -n {target_frame_count} -i {video_frames_dir_name} -o {video_interpolate_frames_dir_name}")
};
println!("interpolate_frame_cmd_str: {interpolate_frame_cmd_str}");

let interpolate_frame_cmd_output = execute_cmd(&interpolate_frame_cmd_str);
Expand All @@ -107,7 +119,11 @@ fn encode_video(
video_interpolate_frames_dir_name: &str,
video_filename: &str,
) {
let encode_video_cmd_str = format!("ffmpeg -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 libx264 -pix_fmt yuv420p output_{video_filename}.mp4");
let encode_video_cmd_str = if cfg!(target_os = "windows") {
format!("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 libx264 -pix_fmt yuv420p output_{video_filename}.mp4")
} else {
format!("ffmpeg -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 libx264 -pix_fmt yuv420p output_{video_filename}.mp4")
};
println!("encode_video_cmd_str: {encode_video_cmd_str}");

let encode_video_cmd_output = execute_cmd(&encode_video_cmd_str);
Expand Down

0 comments on commit 728bceb

Please sign in to comment.