Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -11,6 +11,7 @@ from moviepy.editor import (
|
|
| 11 |
AudioFileClip,
|
| 12 |
CompositeAudioClip,
|
| 13 |
concatenate_audioclips,
|
|
|
|
| 14 |
)
|
| 15 |
import io
|
| 16 |
from PIL import Image
|
|
@@ -31,12 +32,12 @@ def safe_video_clip(path):
|
|
| 31 |
clip.close()
|
| 32 |
raise ValueError(f"Invalid or empty video file: {os.path.basename(path)}")
|
| 33 |
logger.debug(f"Loaded video: {path}, duration: {clip.duration}s")
|
| 34 |
-
# Resize
|
| 35 |
try:
|
| 36 |
-
clip = clip.resize((1280, 720)
|
| 37 |
except Exception as e:
|
| 38 |
logger.warning(f"Failed to resize video {path}: {e}")
|
| 39 |
-
|
| 40 |
return clip
|
| 41 |
except Exception as e:
|
| 42 |
raise ValueError(f"Failed to load video file '{os.path.basename(path)}': {str(e)}")
|
|
@@ -99,7 +100,7 @@ def merge_videos_and_audios(video_paths, audio_paths, output_path, temp_dir, ori
|
|
| 99 |
logger.debug(f"Composite audio duration: {final_audio.duration}s")
|
| 100 |
|
| 101 |
# Match audio duration to video
|
| 102 |
-
if final_audio.duration < final_video.duration:
|
| 103 |
logger.debug(f"Looping audio to match video duration: {final_video.duration}s")
|
| 104 |
final_audio = final_audio.fx(vfx.loop, duration=final_video.duration)
|
| 105 |
|
|
|
|
| 11 |
AudioFileClip,
|
| 12 |
CompositeAudioClip,
|
| 13 |
concatenate_audioclips,
|
| 14 |
+
vfx, # Import vfx for looping
|
| 15 |
)
|
| 16 |
import io
|
| 17 |
from PIL import Image
|
|
|
|
| 32 |
clip.close()
|
| 33 |
raise ValueError(f"Invalid or empty video file: {os.path.basename(path)}")
|
| 34 |
logger.debug(f"Loaded video: {path}, duration: {clip.duration}s")
|
| 35 |
+
# Resize without resample keyword
|
| 36 |
try:
|
| 37 |
+
clip = clip.resize((1280, 720)) # Use default resampling
|
| 38 |
except Exception as e:
|
| 39 |
logger.warning(f"Failed to resize video {path}: {e}")
|
| 40 |
+
# Continue without resizing if it fails
|
| 41 |
return clip
|
| 42 |
except Exception as e:
|
| 43 |
raise ValueError(f"Failed to load video file '{os.path.basename(path)}': {str(e)}")
|
|
|
|
| 100 |
logger.debug(f"Composite audio duration: {final_audio.duration}s")
|
| 101 |
|
| 102 |
# Match audio duration to video
|
| 103 |
+
if final_audio and final_audio.duration < final_video.duration:
|
| 104 |
logger.debug(f"Looping audio to match video duration: {final_video.duration}s")
|
| 105 |
final_audio = final_audio.fx(vfx.loop, duration=final_video.duration)
|
| 106 |
|