diff --git a/Cargo.lock b/Cargo.lock index f1c21866b8..ed7a02ee9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2507,6 +2507,16 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "ffprobe" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ffef835e1f9ac151db5bb2adbb95c9dfe1f315f987f011dd89cd655b4e9a52c" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "filesys" version = "0.0.1" @@ -8040,6 +8050,7 @@ name = "videos" version = "0.0.1" dependencies = [ "errors", + "ffprobe", "log", "mp4", "my-workspace-hack", diff --git a/crates/lib/files/videos/Cargo.toml b/crates/lib/files/videos/Cargo.toml index 2d4469ac9b..f287783cb3 100644 --- a/crates/lib/files/videos/Cargo.toml +++ b/crates/lib/files/videos/Cargo.toml @@ -25,8 +25,9 @@ errors = { path = "../../errors" } my-workspace-hack = { version = "0.1", path = "../../../my-workspace-hack" } # External -mp4 = "0.14.0" +ffprobe = "0.4.0" log = "0.4.20" +mp4 = "0.14.0" [dev-dependencies] testing = { path = "../../testing" } diff --git a/crates/lib/files/videos/src/ffprobe_get_dimensions.rs b/crates/lib/files/videos/src/ffprobe_get_dimensions.rs new file mode 100644 index 0000000000..12b31d129c --- /dev/null +++ b/crates/lib/files/videos/src/ffprobe_get_dimensions.rs @@ -0,0 +1,33 @@ +use std::path::Path; + +use errors::AnyhowResult; + +pub struct VideoDimensions { + pub width: u64, + pub height: u64, +} + +pub fn ffprobe_get_dimensions( + video_path: impl AsRef +) -> AnyhowResult> +{ + let result = ffprobe::ffprobe(video_path)?; + + let maybe_dimensions = result.streams.iter() + .filter(|stream| stream.codec_type.as_deref() == Some("video")) + .find_map(|stream| { + if let (Some(width), Some(height)) = (stream.width, stream.height) { + Some((width, height)) + } else { + None + } + }); + + match maybe_dimensions { + None => Ok(None), + Some((width, height)) => Ok(Some(VideoDimensions { + width: width.unsigned_abs(), + height: height.unsigned_abs(), + })), + } +} diff --git a/crates/lib/files/videos/src/lib.rs b/crates/lib/files/videos/src/lib.rs index bc5578da2d..5d35240395 100644 --- a/crates/lib/files/videos/src/lib.rs +++ b/crates/lib/files/videos/src/lib.rs @@ -18,4 +18,5 @@ #![allow(dead_code)] #![allow(non_snake_case)] +pub mod ffprobe_get_dimensions; pub mod get_mp4_info; \ No newline at end of file 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 8ec578f93b..7db1f1e9c9 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 @@ -6,6 +6,7 @@ use buckets::public::media_files::bucket_file_path::MediaFileBucketPath; use cloud_storage::remote_file_manager::remote_cloud_file_manager::RemoteCloudFileClient; use filesys::path_to_string::path_to_string; use mysql_queries::queries::media_files::get::get_media_file::{get_media_file, MediaFile}; +use videos::ffprobe_get_dimensions::ffprobe_get_dimensions; use crate::job::job_loop::process_single_job_error::ProcessSingleJobError; use crate::job::job_types::workflow::comfy_ui::video_style_transfer::video_paths::VideoPaths; 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 dab44d95e1..76e1422c3b 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,7 +1,7 @@ pub mod comfy_ui_inference_command; pub mod download_input_video; -pub mod video_paths; pub mod process_job; -pub mod validate_job; pub mod validate_and_save_results; -mod write_workflow_prompt; +pub mod validate_job; +pub mod video_paths; +pub mod write_workflow_prompt; 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 0b76be10c0..2dc0faa605 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 @@ -39,6 +39,7 @@ use subprocess_common::command_runner::command_runner_args::{RunAsSubprocessArgs use thumbnail_generator::task_client::thumbnail_task::ThumbnailTaskBuilder; use tokens::tokens::media_files::MediaFileToken; use tokens::tokens::prompts::PromptToken; +use videos::ffprobe_get_dimensions::ffprobe_get_dimensions; use crate::job::job_loop::job_success_result::{JobSuccessResult, ResultEntity}; use crate::job::job_loop::process_single_job_error::ProcessSingleJobError; @@ -227,6 +228,10 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result) -> Result) -> Result) -> Result