mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 09:48:44 +00:00
some progress on restoring audio
This commit is contained in:
1 parent
2bee82f0ae
commit
5d89e87527
3 files changed
+44
-25
No files matched your search
+6
-4
@@ -206,10 +206,12 @@ pub async fn process_live_portrait_job(
|
||||
|
||||
// // ==================== COPY BACK AUDIO ==================== //
|
||||
//
|
||||
// post_process_restore_audio(PostProcessRestoreVideoArgs {
|
||||
// comfy_deps,
|
||||
// videos: &mut videos,
|
||||
// });
|
||||
let result = post_process_restore_audio(PostProcessRestoreVideoArgs {
|
||||
comfy_deps,
|
||||
input_video_file: &output_file_path,
|
||||
input_audio_file: &driver_file_path,
|
||||
output_video_file: &output_file_path.with_extension("_restored.mp4"),
|
||||
});
|
||||
//
|
||||
// // ==================== OPTIONAL WATERMARK ==================== //
|
||||
//
|
||||
|
||||
+17
-3
@@ -412,10 +412,24 @@ pub async fn process_video_style_transfer_job(deps: &JobDependencies, job: &Avai
|
||||
|
||||
// ==================== COPY BACK AUDIO ==================== //
|
||||
|
||||
post_process_restore_audio(PostProcessRestoreVideoArgs {
|
||||
if let (result) = post_process_restore_audio(PostProcessRestoreVideoArgs {
|
||||
comfy_deps,
|
||||
videos: &mut videos,
|
||||
});
|
||||
input_video_file: videos.primary_video.comfy_output_video_path.as_path(),
|
||||
input_audio_file: videos.primary_video.input_video(),
|
||||
output_video_file: &videos
|
||||
.primary_video
|
||||
.comfy_output_video_path
|
||||
.with_extension("_restored.mp4"),
|
||||
}) {
|
||||
match result.audio_restored_video_path {
|
||||
Some(audio_restored_video_path) => {
|
||||
videos.primary_video.audio_restored_video_path = Some(audio_restored_video_path);
|
||||
}
|
||||
None => {
|
||||
error!("Audio restoration failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== OPTIONAL WATERMARK ==================== //
|
||||
|
||||
|
||||
+21
-18
@@ -1,3 +1,4 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use log::{error, info};
|
||||
|
||||
use filesys::check_file_exists::check_file_exists;
|
||||
@@ -11,31 +12,29 @@ use crate::util::common_commands::ffmpeg_audio_replace_args::FfmpegAudioReplaceA
|
||||
|
||||
pub struct PostProcessRestoreVideoArgs<'a> {
|
||||
pub comfy_deps: &'a ComfyDependencies,
|
||||
pub videos: &'a mut VideoPathing,
|
||||
pub input_video_file: &'a Path,
|
||||
pub input_audio_file: &'a Path,
|
||||
pub output_video_file: &'a Path,
|
||||
}
|
||||
|
||||
/// NB: Purposefully infallible.
|
||||
pub struct PostProcessRestoreVideoResult {
|
||||
pub audio_restored_video_path: Option<PathBuf>,
|
||||
}
|
||||
/// NB: Purposefully infallible.
|
||||
pub fn post_process_restore_audio(
|
||||
args: PostProcessRestoreVideoArgs<'_>
|
||||
) -> () {
|
||||
) -> (PostProcessRestoreVideoResult) {
|
||||
info!("Restoring audio...");
|
||||
|
||||
// Use the original downloaded video if we didn't trim and resample it.
|
||||
let input_video_file = args.videos.primary_video.input_video();
|
||||
|
||||
let output_video_fs_path_restored = args.videos
|
||||
.primary_video
|
||||
.comfy_output_video_path
|
||||
.with_extension("_restored.mp4");
|
||||
|
||||
let command_exit_status = args
|
||||
.comfy_deps
|
||||
.ffmpeg_command_runner
|
||||
.run_with_subprocess(RunAsSubprocessArgs {
|
||||
args: Box::new(&FfmpegAudioReplaceArgs {
|
||||
input_video_file: &args.videos.primary_video.comfy_output_video_path,
|
||||
input_audio_file: &input_video_file,
|
||||
output_video_file: &output_video_fs_path_restored,
|
||||
input_video_file: &args.input_video_file,
|
||||
input_audio_file: &args.input_audio_file,
|
||||
output_video_file: &args.output_video_file,
|
||||
}),
|
||||
stderr: StreamRedirection::None,
|
||||
stdout: StreamRedirection::None,
|
||||
@@ -44,7 +43,7 @@ pub fn post_process_restore_audio(
|
||||
let mut use_restored_audio = true;
|
||||
|
||||
// NB: Don't fail the entire command if audio restoration fails
|
||||
if let Err(err) = check_file_exists(&output_video_fs_path_restored) {
|
||||
if let Err(err) = check_file_exists(&args.output_video_file.to_path_buf()) {
|
||||
use_restored_audio = false;
|
||||
error!("Audio copy failed: {:?}", err);
|
||||
}
|
||||
@@ -54,8 +53,12 @@ pub fn post_process_restore_audio(
|
||||
error!("Audio copy failed: {:?} ; we'll save the non-audio copy.", command_exit_status);
|
||||
}
|
||||
|
||||
if use_restored_audio {
|
||||
info!("Success generating restored audio file: {:?}", output_video_fs_path_restored);
|
||||
args.videos.primary_video.audio_restored_video_path = Some(output_video_fs_path_restored);
|
||||
}
|
||||
PostProcessRestoreVideoResult {
|
||||
audio_restored_video_path: if use_restored_audio {
|
||||
info!("Success generating restored audio file: {:?}", &args.output_video_file);
|
||||
Some(args.output_video_file.to_path_buf())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user