2222
2323import numpy as np
2424from dotenv import load_dotenv
25- from moviepy .editor import CompositeVideoClip , VideoFileClip
26- import moviepy .video .fx .crop as crop_vid
25+ from moviepy import CompositeVideoClip , VideoFileClip
2726from scipy .ndimage import gaussian_filter
2827from scenedetect import SceneManager , open_video
2928from scenedetect .detectors import ContentDetector
@@ -209,12 +208,7 @@ def compute_video_action_profile(
209208
210209 prev_gray : np .ndarray | None = None
211210
212- # Sequential frame reading is much cheaper than random access get_frame(t)
213- # Compatibility with different MoviePy versions: 'progress_bar' arg may not exist.
214- try :
215- frame_iter = clip .iter_frames (fps = eff_fps , dtype = "uint8" , progress_bar = False )
216- except TypeError :
217- frame_iter = clip .iter_frames (fps = eff_fps , dtype = "uint8" )
211+ frame_iter = clip .iter_frames (fps = eff_fps , dtype = "uint8" , logger = "bar" )
218212
219213 for idx , frame in enumerate (frame_iter ):
220214 t = idx / eff_fps
@@ -455,17 +449,15 @@ def crop_clip(
455449
456450 if current_ratio > target_ratio :
457451 new_width = round (height * ratio_w / ratio_h )
458- return crop_vid .crop (
459- clip ,
452+ return clip .cropped (
460453 width = new_width ,
461454 height = height ,
462455 x_center = width * x_center ,
463456 y_center = height * y_center ,
464457 )
465458
466459 new_height = round (width / ratio_w * ratio_h )
467- return crop_vid .crop (
468- clip ,
460+ return clip .cropped (
469461 width = width ,
470462 height = new_height ,
471463 x_center = width * x_center ,
@@ -542,7 +534,7 @@ def get_final_clip(
542534) -> VideoFileClip :
543535 """Prepare a clip ready for rendering."""
544536
545- result_clip = clip .subclip (start_point , start_point + final_clip_length )
537+ result_clip = clip .subclipped (start_point , start_point + final_clip_length )
546538
547539 width , height = result_clip .size
548540 target_ratio = config .target_ratio_w / config .target_ratio_h
@@ -557,22 +549,22 @@ def get_final_clip(
557549
558550 width , height = result_clip .size
559551 bg_w , bg_h = select_background_resolution (width )
560- result_clip = result_clip .resize (width = bg_w )
552+ result_clip = result_clip .resized (width = bg_w )
561553
562554 if width >= height :
563- background_clip = clip .subclip (start_point , start_point + final_clip_length )
555+ background_clip = clip .subclipped (start_point , start_point + final_clip_length )
564556 background_clip = crop_clip (background_clip , 1 , 1 , config .x_center , config .y_center )
565- background_clip = background_clip .resize (width = 720 , height = 720 )
566- background_clip = background_clip .fl_image (blur )
567- background_clip = background_clip .resize (width = bg_w , height = bg_w )
568- result_clip = CompositeVideoClip ([background_clip , result_clip .set_position ("center" )])
557+ background_clip = background_clip .resized (width = 720 , height = 720 )
558+ background_clip = background_clip .image_transform (blur )
559+ background_clip = background_clip .resized (width = bg_w , height = bg_w )
560+ result_clip = CompositeVideoClip ([background_clip , result_clip .with_position ("center" )])
569561 elif width / 9 < height / 16 :
570- background_clip = clip .subclip (start_point , start_point + final_clip_length )
562+ background_clip = clip .subclipped (start_point , start_point + final_clip_length )
571563 background_clip = crop_clip (background_clip , 9 , 16 , config .x_center , config .y_center )
572- background_clip = background_clip .resize (width = 720 , height = 1280 )
573- background_clip = background_clip .fl_image (blur )
574- background_clip = background_clip .resize (width = bg_w , height = bg_h )
575- result_clip = CompositeVideoClip ([background_clip , result_clip .set_position ("center" )])
564+ background_clip = background_clip .resized (width = 720 , height = 1280 )
565+ background_clip = background_clip .image_transform (blur )
566+ background_clip = background_clip .resized (width = bg_w , height = bg_h )
567+ result_clip = CompositeVideoClip ([background_clip , result_clip .with_position ("center" )])
576568
577569 return result_clip
578570
0 commit comments