From 728bcebb0176cc52cb0eafb2a3d7a40cc8024a50 Mon Sep 17 00:00:00 2001 From: jerry Date: Sun, 12 Feb 2023 21:25:15 +0800 Subject: [PATCH] fix windows cmd --- aurora-cli/src/lib.rs | 52 ++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/aurora-cli/src/lib.rs b/aurora-cli/src/lib.rs index dcb9242..ffbf0ec 100644 --- a/aurora-cli/src/lib.rs +++ b/aurora-cli/src/lib.rs @@ -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); @@ -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:?}"); } @@ -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); @@ -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 } @@ -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); @@ -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);