Spaces:
Runtime error
Runtime error
none
commited on
Commit
·
3936b33
1
Parent(s):
93fde94
try to fix bugs in online inference
Browse files
src/moviedubber/infer_with_mmlm_result.py
CHANGED
|
@@ -14,38 +14,28 @@ from src.moviedubber.model import ControlNetDiT, DiT
|
|
| 14 |
|
| 15 |
|
| 16 |
def concat_movie_with_audio(wav, video_path, out_dir):
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
codec="libx264",
|
| 40 |
-
audio_codec="mp3",
|
| 41 |
-
fps=25,
|
| 42 |
-
logger=None,
|
| 43 |
-
threads=1,
|
| 44 |
-
temp_audiofile_path=out_dir,
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f"Error processing {wav} {video_path}: {str(e)}")
|
| 49 |
|
| 50 |
return output_path
|
| 51 |
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
def concat_movie_with_audio(wav, video_path, out_dir):
|
| 17 |
+
with (
|
| 18 |
+
AudioFileClip(str(wav)) as audio_clip,
|
| 19 |
+
VideoFileClip(str(video_path)) as video_clip,
|
| 20 |
+
):
|
| 21 |
+
duration = min(video_clip.duration, audio_clip.duration)
|
| 22 |
+
|
| 23 |
+
video_subclip = video_clip.subclipped(0, duration)
|
| 24 |
+
audio_subclip = audio_clip.subclipped(0, duration)
|
| 25 |
+
|
| 26 |
+
final_video = video_subclip.with_audio(audio_subclip)
|
| 27 |
+
|
| 28 |
+
output_path = wav.replace(".wav", ".mp4")
|
| 29 |
+
|
| 30 |
+
final_video.write_videofile(
|
| 31 |
+
str(output_path),
|
| 32 |
+
codec="libx264",
|
| 33 |
+
audio_codec="mp3",
|
| 34 |
+
fps=25,
|
| 35 |
+
logger=None,
|
| 36 |
+
threads=1,
|
| 37 |
+
temp_audiofile_path=out_dir,
|
| 38 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
return output_path
|
| 41 |
|