From 5918a413252812cbbaef8f3f3493433f55e90f85 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 28 May 2024 21:20:50 -0400 Subject: [PATCH] cleanup logging --- .../download_input_video.rs | 4 +- .../video_style_transfer/job_outputs.rs | 78 -------- .../comfy_ui/video_style_transfer/mod.rs | 2 +- .../video_style_transfer/process_job.rs | 114 +----------- .../validate_and_save_results.rs | 4 +- .../video_style_transfer/video_paths.rs | 172 ++++++++++++++++++ 6 files changed, 183 insertions(+), 191 deletions(-) delete mode 100644 crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/job_outputs.rs create mode 100644 crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/video_paths.rs diff --git a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/download_input_video.rs b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/download_input_video.rs index 271f70d62c..8ec578f93b 100644 --- a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/download_input_video.rs +++ b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/download_input_video.rs @@ -8,7 +8,7 @@ use filesys::path_to_string::path_to_string; use mysql_queries::queries::media_files::get::get_media_file::{get_media_file, MediaFile}; use crate::job::job_loop::process_single_job_error::ProcessSingleJobError; -use crate::job::job_types::workflow::comfy_ui::video_style_transfer::job_outputs::JobOutputs; +use crate::job::job_types::workflow::comfy_ui::video_style_transfer::video_paths::VideoPaths; use crate::job::job_types::workflow::comfy_ui::video_style_transfer::validate_job::JobArgs; pub struct VideoDownloadDetails { @@ -17,7 +17,7 @@ pub struct VideoDownloadDetails { pub struct DownloadInputVideoArgs<'a> { pub job_args: &'a JobArgs<'a>, - pub videos: &'a JobOutputs, + pub videos: &'a VideoPaths, pub mysql_pool: &'a MySqlPool, pub remote_cloud_file_client: &'a RemoteCloudFileClient, } diff --git a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/job_outputs.rs b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/job_outputs.rs deleted file mode 100644 index e9afd91b95..0000000000 --- a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/job_outputs.rs +++ /dev/null @@ -1,78 +0,0 @@ -use std::path::{Path, PathBuf}; - -pub struct JobOutputs { - /// Filesystem path of the downloaded original video - /// This is the input. - pub original_video_path: PathBuf, - - /// Filesystem path of the trimmed and resampled video - /// This is the first output we generate. - /// We'll use this downstream once it's available. - pub trimmed_resampled_video_path: PathBuf, - - /// This is the input into Comfy. - /// This is typically the `trimmed_resampled_video_path`, but since Comfy - /// can overwrite the source, we'll keep a separate copy of that file for - /// later downstream sound restoration (since comfy wipes sound). - pub comfy_input_video_path: PathBuf, - - /// Filesystem path of the style transfer output - /// This is the main purpose of the job, and the second output we generate. - pub comfy_output_video_path: PathBuf, - - /// Filesystem path of the audio-restored output - /// This is the third output we generate. - /// We'll want to upload this as a result, if available. - pub audio_restored_video_path: Option, - - /// Watermarked final result - /// This is the fourth output we generate. - /// We'll want to upload this as a result, if available. - pub watermarked_video_path: Option, -} - - -impl JobOutputs { - pub fn new(root_comfy_path: &Path, job_output_path: &str) -> Self { - // TODO(bt,2024-04-21): The pathing for this job is complicated. ComfyUI - // was set up with some of these expectations, which is bad. Worse, the - // jobs enqueue the expected output path -- no idea why that was done. - // This should all be fixed. - let input_dir = root_comfy_path.join("input"); - let output_dir = root_comfy_path.join("output"); - - let original_video_path = input_dir.join("video.mp4"); - let trimmed_resampled_video_path = input_dir.join("trimmed.mp4"); - let comfy_input_video_path = input_dir.join("input.mp4"); - let comfy_output_video_path = output_dir.join(job_output_path); // TODO: This sucks. - - Self { - original_video_path, - trimmed_resampled_video_path, - comfy_input_video_path, - comfy_output_video_path, - audio_restored_video_path: None, - watermarked_video_path: None, - } - } - - pub fn video_to_watermark(&self) -> &PathBuf { - // Try to use the audio-restored video if it's available - self.audio_restored_video_path.as_ref() - .unwrap_or(&self.comfy_output_video_path) - } - - pub fn get_final_video_to_upload(&self) -> &PathBuf { - // This is the video to upload as the result and save in the media_files table. - self.watermarked_video_path.as_ref() - .or(self.audio_restored_video_path.as_ref()) - .unwrap_or(&self.comfy_output_video_path) - } - - pub fn get_non_watermarked_video_to_upload(&self) -> &PathBuf { - // We'll upload this for internal use and for premium users. - // Same as "video_to_watermark()" - self.audio_restored_video_path.as_ref() - .unwrap_or(&self.comfy_output_video_path) - } -} diff --git a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/mod.rs b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/mod.rs index ab3c4981b8..dab44d95e1 100644 --- a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/mod.rs +++ b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/mod.rs @@ -1,6 +1,6 @@ pub mod comfy_ui_inference_command; pub mod download_input_video; -pub mod job_outputs; +pub mod video_paths; pub mod process_job; pub mod validate_job; pub mod validate_and_save_results; diff --git a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/process_job.rs b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/process_job.rs index 25fb58936a..c777316fd4 100644 --- a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/process_job.rs +++ b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/process_job.rs @@ -45,7 +45,7 @@ use crate::job::job_loop::process_single_job_error::ProcessSingleJobError; use crate::job::job_types::workflow::comfy_ui::comfy_process_job_args::ComfyProcessJobArgs; use crate::job::job_types::workflow::comfy_ui::video_style_transfer::comfy_ui_inference_command::{InferenceArgs, InferenceDetails}; use crate::job::job_types::workflow::comfy_ui::video_style_transfer::download_input_video::{download_input_video, DownloadInputVideoArgs}; -use crate::job::job_types::workflow::comfy_ui::video_style_transfer::job_outputs::JobOutputs; +use crate::job::job_types::workflow::comfy_ui::video_style_transfer::video_paths::VideoPaths; use crate::job::job_types::workflow::comfy_ui::video_style_transfer::validate_and_save_results::{SaveResultsArgs, validate_and_save_results}; use crate::job::job_types::workflow::comfy_ui::video_style_transfer::validate_job::validate_job; use crate::job::job_types::workflow::comfy_ui::video_style_transfer::write_workflow_prompt::{WorkflowPromptArgs, write_workflow_prompt}; @@ -231,7 +231,7 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result) -> Result) -> Result) -> Result) -> Result) -> Result { pub job_progress_reporter: &'a mut Box, pub download_video: VideoDownloadDetails, - pub videos: &'a JobOutputs, + pub videos: &'a VideoPaths, pub inference_duration: Duration, // TODO: Maybe group these diff --git a/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/video_paths.rs b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/video_paths.rs new file mode 100644 index 0000000000..fcf0c616b5 --- /dev/null +++ b/crates/service/job/inference_job/src/job/job_types/workflow/comfy_ui/video_style_transfer/video_paths.rs @@ -0,0 +1,172 @@ +use std::path::{Path, PathBuf}; + +use log::info; + +use filesys::file_exists::file_exists; + +pub struct VideoPaths { + /// Filesystem path of the downloaded original video + /// This is the input. + pub original_video_path: PathBuf, + + /// Filesystem path of the trimmed and resampled video + /// This is the first output we generate. + /// We'll use this downstream once it's available. + pub trimmed_resampled_video_path: PathBuf, + + /// This is the input into Comfy. + /// This is typically the `trimmed_resampled_video_path`, but since Comfy + /// can overwrite the source, we'll keep a separate copy of that file for + /// later downstream sound restoration (since comfy wipes sound). + pub comfy_input_video_path: PathBuf, + + /// Filesystem path of the style transfer output + /// This is the main purpose of the job, and the second output we generate. + pub comfy_output_video_path: PathBuf, + + /// Filesystem path of the audio-restored output + /// This is the third output we generate. + /// We'll want to upload this as a result, if available. + pub audio_restored_video_path: Option, + + /// Watermarked final result + /// This is the fourth output we generate. + /// We'll want to upload this as a result, if available. + pub watermarked_video_path: Option, +} + + +impl VideoPaths { + pub fn new(root_comfy_path: &Path, job_output_path: &str) -> Self { + // TODO(bt,2024-04-21): The pathing for this job is complicated. ComfyUI + // was set up with some of these expectations, which is bad. Worse, the + // jobs enqueue the expected output path -- no idea why that was done. + // This should all be fixed. + let input_dir = root_comfy_path.join("input"); + let output_dir = root_comfy_path.join("output"); + + let original_video_path = input_dir.join("video.mp4"); + let trimmed_resampled_video_path = input_dir.join("trimmed.mp4"); + let comfy_input_video_path = input_dir.join("input.mp4"); + let comfy_output_video_path = output_dir.join(job_output_path); // TODO: This sucks. + + Self { + original_video_path, + trimmed_resampled_video_path, + comfy_input_video_path, + comfy_output_video_path, + audio_restored_video_path: None, + watermarked_video_path: None, + } + } + + pub fn video_to_watermark(&self) -> &PathBuf { + // Try to use the audio-restored video if it's available + self.audio_restored_video_path.as_ref() + .unwrap_or(&self.comfy_output_video_path) + } + + pub fn get_final_video_to_upload(&self) -> &PathBuf { + // This is the video to upload as the result and save in the media_files table. + self.watermarked_video_path.as_ref() + .or(self.audio_restored_video_path.as_ref()) + .unwrap_or(&self.comfy_output_video_path) + } + + pub fn get_non_watermarked_video_to_upload(&self) -> &PathBuf { + // We'll upload this for internal use and for premium users. + // Same as "video_to_watermark()" + self.audio_restored_video_path.as_ref() + .unwrap_or(&self.comfy_output_video_path) + } + + pub fn debug_print_paths_after_download(&self) { + info!(r#"[debugging] Downstream video paths: + - original video path: {:?} + - original video path (exists): {:?} + - trimmed video path: {:?} + - trimmed video path (exists): {:?} + - comfy output path: {:?} + - comfy output path (exists): {:?} + "#, + &self.original_video_path, + file_exists(&self.original_video_path), + &self.trimmed_resampled_video_path, + file_exists(&self.trimmed_resampled_video_path), + &self.comfy_output_video_path, + file_exists(&self.comfy_output_video_path), + ); + } + + pub fn debug_print_paths_after_trim(&self) { + info!(r#"[debugging] After trim / resampling, video paths: + - original video path: {:?} + - original video path (exists): {:?} + - trimmed video path: {:?} + - trimmed video path (exists): {:?} + - comfy input path: {:?} + - comfy input path (exists): {:?} + - comfy output path: {:?} + - comfy output path (exists): {:?} + "#, + &self.original_video_path, + file_exists(&self.original_video_path), + &self.trimmed_resampled_video_path, + file_exists(&self.trimmed_resampled_video_path), + &self.comfy_input_video_path, + file_exists(&self.comfy_input_video_path), + &self.comfy_output_video_path, + file_exists(&self.comfy_output_video_path), + ); + } + + pub fn debug_print_paths_after_comfy(&self) { + info!(r#"[debugging] After comfy, video paths: + - original video path: {:?} + - original video path (exists): {:?} + - trimmed video path: {:?} + - trimmed video path (exists): {:?} + - comfy input path: {:?} + - comfy input path (exists): {:?} + - comfy output path: {:?} + - comfy output path (exists): {:?} + "#, + &self.original_video_path, + file_exists(&self.original_video_path), + &self.trimmed_resampled_video_path, + file_exists(&self.trimmed_resampled_video_path), + &self.comfy_input_video_path, + file_exists(&self.comfy_input_video_path), + &self.comfy_output_video_path, + file_exists(&self.comfy_output_video_path), + ); + } + + pub fn debug_print_paths_after_post_processing(&self) { + info!(r#"[debugging] After post processing video, video paths: + - original video path: {:?} + - original video path (exists): {:?} + - trimmed video path: {:?} + - trimmed video path (exists): {:?} + - comfy output path: {:?} + - comfy output path (exists): {:?} + - restored audio output path: {:?} + - restored audio output path (exists): {:?} + - watermarking output path: {:?} + - watermarking output path (exists): {:?} + "#, + &self.original_video_path, + file_exists(&self.original_video_path), + &self.trimmed_resampled_video_path, + file_exists(&self.trimmed_resampled_video_path), + &self.comfy_output_video_path, + file_exists(&self.comfy_output_video_path), + &self.audio_restored_video_path, + self.audio_restored_video_path.as_ref() + .map(|path| file_exists(path)).unwrap_or(false), + &self.watermarked_video_path, + self.watermarked_video_path.as_ref() + .map(|path| file_exists(path)).unwrap_or(false), + ); + } +}