diff --git a/models/Wav2Lip/vocodes_process_inference.py b/models/Wav2Lip/vocodes_process_inference.py index 40f6da7d86..5f604c0995 100644 --- a/models/Wav2Lip/vocodes_process_inference.py +++ b/models/Wav2Lip/vocodes_process_inference.py @@ -47,11 +47,14 @@ parser.add_argument('--cached_faces_filename', type=str, parser.add_argument('--audio_filename', type=str, help='Filepath of video/audio file to use as raw audio source', required=True) +parser.add_argument('--output_video_filename', type=str, + help='Output filename for the final video', required=True) + parser.add_argument('--output_metadata_filename', type=str, help='Output filename for the JSON containing width, height, etc.', required=True) -parser.add_argument('--outfile', type=str, help='Video path to save result. See default for an e.g.', - default='results/result_voice.mp4') +#parser.add_argument('--outfile', type=str, help='Video path to save result. See default for an e.g.', +# default='results/result_voice.mp4') parser.add_argument('--static', type=bool, help='If True, then use only first video frame for inference', default=False) @@ -309,7 +312,7 @@ def maybe_concatenate_end_bump(tempdir, args, frame_w, frame_h): # More info on filters: https://stackoverflow.com/a/22958746 command = ' '.join([ 'ffmpeg', - '-i {}'.format(args.outfile), + '-i {}'.format(args.output_video_filename), '-i {}'.format(bumpfile), '-filter_complex "concat=n=2:v=1:a=1"', '{}'.format(padded_wav_filename) @@ -321,7 +324,7 @@ def maybe_concatenate_end_bump(tempdir, args, frame_w, frame_h): print('Failed to concatenate end bump') else: print('Done concatenating end bump; renaming file...', flush=True) - os.rename(padded_wav_filename, args.outfile) + os.rename(padded_wav_filename, args.output_video_filename) def main(tempdir): @@ -476,7 +479,7 @@ def main(tempdir): out.release() - command = 'ffmpeg -y -i {} -i {} -strict -2 -q:v 1 {}'.format(args.audio_filename, output_video_filename, args.outfile) + command = 'ffmpeg -y -i {} -i {} -strict -2 -q:v 1 {}'.format(args.audio_filename, output_video_filename, args.output_video_filename) print('command:', command, flush=True) subprocess.call(command, shell=True) diff --git a/src/script_execution/wav2lip_inference_command.rs b/src/script_execution/wav2lip_inference_command.rs index 5826f2ac87..b33f7e0497 100644 --- a/src/script_execution/wav2lip_inference_command.rs +++ b/src/script_execution/wav2lip_inference_command.rs @@ -32,7 +32,7 @@ impl Wav2LipInferenceCommand { media_template_filename: P, cached_faces_filename: P, output_metadata_filename: P, - output_media_filename: P, + output_video_filename: P, is_image: bool, spawn_process: bool) -> AnyhowResult<()> { @@ -54,6 +54,8 @@ impl Wav2LipInferenceCommand { command.push_str(&audio_filename.as_ref().display().to_string()); command.push_str(" --cached_faces_filename "); command.push_str(&cached_faces_filename.as_ref().display().to_string()); + command.push_str(" --output_video_filename "); + command.push_str(&output_video_filename.as_ref().display().to_string()); command.push_str(" --output_metadata_filename "); command.push_str(&output_metadata_filename.as_ref().display().to_string()); diff --git a/src/util/semi_persistent_cache_dir.rs b/src/util/semi_persistent_cache_dir.rs index fd03496b03..1aa0f8d51f 100644 --- a/src/util/semi_persistent_cache_dir.rs +++ b/src/util/semi_persistent_cache_dir.rs @@ -1,6 +1,7 @@ use std::path::{PathBuf, Path}; use std::fs; use crate::util::anyhow_result::AnyhowResult; +use tempdir::TempDir; /// These are for files on the worker filesystems pub struct SemiPersistentCacheDir { @@ -103,4 +104,35 @@ impl SemiPersistentCacheDir { let _ = fs::create_dir_all(self.video_asset_path())?; Ok(()) } + + // ==================== W2L OUTPUT RESULTS ==================== + + /// We cache W2L faces here. + /// We'll likely need to LRU cache them. + pub fn w2l_output_results_path(&self, temp_dir: &TempDir, inference_job_token: &str) -> PathBuf { + // NB: We don't want colons from the token in the filename. + let filename = inference_job_token.replace(":", ""); + let filename = format!("{}_result.mp4", filename); + + temp_dir.path().join(&filename) + } +} + +#[cfg(test)] +mod tests { + use crate::util::semi_persistent_cache_dir::SemiPersistentCacheDir; + use tempdir::TempDir; + + #[test] + fn test_w2l_output_results_path() { + let dirs = SemiPersistentCacheDir::default_paths(); + let temp_dir = TempDir::new("test").unwrap(); + + let filename = dirs.w2l_output_results_path(&temp_dir, "TYPE:TOKEN") + .to_str() + .map(|s| s.to_string()) + .unwrap(); + + assert!(&filename.ends_with("TYPETOKEN_result.mp4")); + } } diff --git a/src/w2l_inference_job.rs b/src/w2l_inference_job.rs index 2f4a7a8758..6f5bd64aa4 100644 --- a/src/w2l_inference_job.rs +++ b/src/w2l_inference_job.rs @@ -441,6 +441,8 @@ async fn process_job(inferencer: &Inferencer, job: &W2lInferenceJobRecord) -> An false )?; + let output_video_fs_path = temp_dir.path().join(&audio_bucket_hash); + if true { info!("FAKE DONE"); thread::sleep(Duration::from_millis(5000));