nezihtopaloglu commited on
Commit
e952ea3
·
1 Parent(s): 751144b

changing video generation to avoid ANTIALIAS error

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -58,10 +58,18 @@ def generate_images(chunks, image_size=(640, 480)):
58
 
59
 
60
  def create_video(images, durations, speech_path, image_size=(640, 480)):
61
- print("Creating video...")
62
- clips = [mp.ImageClip(img).set_duration(dur).resize(image_size) for img, dur in zip(images, durations)]
63
- black_start = mp.ColorClip(image_size, color=(0,0,0), duration=1)
64
- black_end = mp.ColorClip(image_size, color=(0,0,0), duration=2)
 
 
 
 
 
 
 
 
65
  video = mp.concatenate_videoclips([black_start] + clips + [black_end])
66
  audio = mp.AudioFileClip(speech_path)
67
  final_video = video.set_audio(audio)
 
58
 
59
 
60
  def create_video(images, durations, speech_path, image_size=(640, 480)):
61
+ clips = []
62
+ for img, dur in zip(images, durations):
63
+ pil_image = Image.open(img) # Open the image with PIL
64
+ pil_image = pil_image.resize(image_size, Image.Resampling.LANCZOS) # Resize with the new resampling filter
65
+ img_resized_path = f"resized_{os.path.basename(img)}" # Temporary file to store resized image
66
+ pil_image.save(img_resized_path) # Save resized image to file
67
+
68
+ clip = mp.ImageClip(img_resized_path).set_duration(dur)
69
+ clips.append(clip)
70
+
71
+ black_start = mp.ColorClip((512, 512), color=(0,0,0), duration=1)
72
+ black_end = mp.ColorClip((512, 512), color=(0,0,0), duration=2)
73
  video = mp.concatenate_videoclips([black_start] + clips + [black_end])
74
  audio = mp.AudioFileClip(speech_path)
75
  final_video = video.set_audio(audio)