mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-07 02:21:23 +00:00
cleanup logging
This commit is contained in:
1 parent
6649e88ba4
commit
5918a41325
6 files changed
+183
-191
No files matched your search
+2
-2
@@ -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,
|
||||
}
|
||||
|
||||
-78
@@ -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<PathBuf>,
|
||||
|
||||
/// 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<PathBuf>,
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+6
-108
@@ -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<JobSuccessResu
|
||||
info!("Root comfy path: {:?}", &root_comfy_path);
|
||||
info!("Job output path will be (fix this code! the job shouldn't set this path!): {:?}", &job_args.output_path);
|
||||
|
||||
let mut videos = JobOutputs::new(&root_comfy_path, job_args.output_path);
|
||||
let mut videos = VideoPaths::new(&root_comfy_path, job_args.output_path);
|
||||
|
||||
// TODO(bt,2024-04-20): Clean up this mess.
|
||||
|
||||
@@ -246,21 +246,7 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
|
||||
info!("Downloaded video!");
|
||||
|
||||
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): {:?}
|
||||
"#,
|
||||
&videos.original_video_path,
|
||||
file_exists(&videos.original_video_path),
|
||||
&videos.trimmed_resampled_video_path,
|
||||
file_exists(&videos.trimmed_resampled_video_path),
|
||||
&videos.comfy_output_video_path,
|
||||
file_exists(&videos.comfy_output_video_path),
|
||||
);
|
||||
videos.debug_print_paths_after_download();
|
||||
|
||||
// ========================= PROCESS VIDEO ======================== //
|
||||
|
||||
@@ -335,28 +321,7 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
})?;
|
||||
}
|
||||
|
||||
// TODO: I think comfy overwrites the original stripped video !
|
||||
// To fix it, we just need a copy.
|
||||
|
||||
info!(r#"[debugging] After 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): {:?}
|
||||
"#,
|
||||
&videos.original_video_path,
|
||||
file_exists(&videos.original_video_path),
|
||||
&videos.trimmed_resampled_video_path,
|
||||
file_exists(&videos.trimmed_resampled_video_path),
|
||||
&videos.comfy_input_video_path,
|
||||
file_exists(&videos.comfy_input_video_path),
|
||||
&videos.comfy_output_video_path,
|
||||
file_exists(&videos.comfy_output_video_path),
|
||||
);
|
||||
videos.debug_print_paths_after_trim();
|
||||
|
||||
// make outputs dir if not exist
|
||||
let output_dir = root_comfy_path.join("output");
|
||||
@@ -441,25 +406,7 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
info!("Captured stduout output: {}", contents);
|
||||
}
|
||||
|
||||
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): {:?}
|
||||
"#,
|
||||
&videos.original_video_path,
|
||||
file_exists(&videos.original_video_path),
|
||||
&videos.trimmed_resampled_video_path,
|
||||
file_exists(&videos.trimmed_resampled_video_path),
|
||||
&videos.comfy_input_video_path,
|
||||
file_exists(&videos.comfy_input_video_path),
|
||||
&videos.comfy_output_video_path,
|
||||
file_exists(&videos.comfy_output_video_path),
|
||||
);
|
||||
videos.debug_print_paths_after_comfy();
|
||||
|
||||
// ==================== CHECK OUTPUT FILE ======================== //
|
||||
|
||||
@@ -533,31 +480,6 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
}
|
||||
}
|
||||
|
||||
info!(r#"[debugging] After restored audio, 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): {:?}
|
||||
- restored audio output path: {:?}
|
||||
- restored audio output path (exists): {:?}
|
||||
"#,
|
||||
&videos.original_video_path,
|
||||
file_exists(&videos.original_video_path),
|
||||
&videos.trimmed_resampled_video_path,
|
||||
file_exists(&videos.trimmed_resampled_video_path),
|
||||
&videos.comfy_input_video_path,
|
||||
file_exists(&videos.comfy_input_video_path),
|
||||
&videos.comfy_output_video_path,
|
||||
file_exists(&videos.comfy_output_video_path),
|
||||
&videos.audio_restored_video_path,
|
||||
videos.audio_restored_video_path.as_ref()
|
||||
.map(|path| file_exists(path)).unwrap_or(false),
|
||||
);
|
||||
|
||||
// ==================== OPTIONAL WATERMARK ==================== //
|
||||
|
||||
// TODO(bt, 2024-03-01): Interrogate account for premium
|
||||
@@ -598,31 +520,7 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
}
|
||||
}
|
||||
|
||||
info!(r#"[debugging] After watermarking 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): {:?}
|
||||
"#,
|
||||
&videos.original_video_path,
|
||||
file_exists(&videos.original_video_path),
|
||||
&videos.trimmed_resampled_video_path,
|
||||
file_exists(&videos.trimmed_resampled_video_path),
|
||||
&videos.comfy_output_video_path,
|
||||
file_exists(&videos.comfy_output_video_path),
|
||||
&videos.audio_restored_video_path,
|
||||
videos.audio_restored_video_path.as_ref()
|
||||
.map(|path| file_exists(path)).unwrap_or(false),
|
||||
&videos.watermarked_video_path,
|
||||
videos.watermarked_video_path.as_ref()
|
||||
.map(|path| file_exists(path)).unwrap_or(false),
|
||||
);
|
||||
videos.debug_print_paths_after_post_processing();
|
||||
|
||||
// ==================== VALIDATE AND SAVE RESULTS ======================== //
|
||||
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ use crate::job::job_loop::job_success_result::{JobSuccessResult, ResultEntity};
|
||||
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::download_input_video::VideoDownloadDetails;
|
||||
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;
|
||||
use crate::job_dependencies::JobDependencies;
|
||||
|
||||
@@ -54,7 +54,7 @@ pub struct SaveResultsArgs<'a> {
|
||||
pub job_progress_reporter: &'a mut Box<dyn JobProgressReporter>,
|
||||
|
||||
pub download_video: VideoDownloadDetails,
|
||||
pub videos: &'a JobOutputs,
|
||||
pub videos: &'a VideoPaths,
|
||||
pub inference_duration: Duration,
|
||||
|
||||
// TODO: Maybe group these
|
||||
|
||||
+172
@@ -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<PathBuf>,
|
||||
|
||||
/// 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<PathBuf>,
|
||||
}
|
||||
|
||||
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user