Deddy commited on
Commit
94e3df0
·
verified ·
1 Parent(s): f501adc

Update process_energy.py

Browse files
Files changed (1) hide show
  1. process_energy.py +8 -104
process_energy.py CHANGED
@@ -72,7 +72,7 @@ import time
72
  import numpy as np
73
  from tqdm import tqdm
74
  from scipy.io.wavfile import write
75
- from moviepy.editor import ImageClip, TextClip, CompositeVideoClip, VideoFileClip, AudioFileClip
76
  from moviepy.video.fx.all import fadein, fadeout, loop
77
  from PIL import Image, ImageDraw, ImageFont
78
 
@@ -167,117 +167,21 @@ def activate_transfer():
167
  new_mp = recipient_mp + transferred_mp
168
  return new_mp
169
 
170
- # Fungsi untuk membuat frame gambar afirmasi
171
- def create_affirmation_frames(texts, width=640, height=480, duration=5):
172
- frames = []
173
- font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf" # Path font default
174
- font_size = 24
175
-
176
- for text in texts:
177
- frame = Image.new("RGBA", (width, height), color=(0, 0, 0, 0)) # Transparan
178
- draw = ImageDraw.Draw(frame)
179
-
180
- # Menggunakan font default
181
- try:
182
- font = ImageFont.truetype(font_path, font_size)
183
- except IOError:
184
- font = ImageFont.load_default()
185
-
186
- lines = text.split('\n')
187
- y_text = height // 2 - (len(lines) * font_size) // 2
188
- for line in lines:
189
- bbox = draw.textbbox((0, 0), line, font=font)
190
- width_text = bbox[2] - bbox[0]
191
- height_text = bbox[3] - bbox[1]
192
- draw.text(((width - width_text) / 2, y_text), line, font=font, fill="white")
193
- y_text += height_text
194
-
195
- frames.append(frame)
196
-
197
- return frames
198
-
199
- # Fungsi untuk membuat video afirmasi dengan audio
200
- def create_affirmation_video_with_audio(tujuan, nama_anda, audio_filename, output_filename="affirmation_video.mp4"):
201
- # Texts for the video
202
- texts = [
203
- f"HAI {nama_anda.upper()}! DENGARLAH SUARA ENERGI SEMESTA DIGITAL SELAMA 3 MENIT AGAR PROSES TRANSFER BERJALAN MULUS.",
204
- f"{nama_anda.upper()}, BAYANGKAN ANDA MENCAPAI SEMUA TUJUAN ANDA DENGAN SUKSES DAN KEBAHAGIAAN.",
205
- f"SAYA, {nama_anda.upper()}, ADALAH MAGNET DAHSYAT BAGI REALITAS KESUKSESAN DAN KEBAHAGIAAN.",
206
- f"SAYA, {nama_anda.upper()}, MENARIK HAL-HAL POSITIF DALAM HIDUP SAYA. SAYA AKAN MENCAPAI TUJUAN SAYA SUKSES DI: {tujuan.upper()}",
207
- ]
208
-
209
- # Create frames
210
- frames = create_affirmation_frames(texts, width=640, height=480)
211
-
212
- # Save frames as images and load into a video
213
- image_filenames = []
214
- for i, frame in enumerate(frames):
215
- image_filename = f"frame_{i}.png"
216
- frame.save(image_filename)
217
- image_filenames.append(image_filename)
218
-
219
- # Load images as video clips
220
- clips = [ImageClip(m).set_duration(45) for m in image_filenames] # Durasi setiap teks 45 detik
221
-
222
  # Load background GIF and loop it
223
- background_clip = VideoFileClip("spin_energy.gif").fx(loop, duration=len(clips) * 45)
224
 
225
  # Load the generated audio file
226
  audio_clip = AudioFileClip(audio_filename)
227
 
228
- # Concatenate text clips with background
229
- video = CompositeVideoClip([background_clip] + clips).set_duration(len(clips) * 45).set_audio(audio_clip)
230
 
231
- # Write the result to a file
232
- video.write_videofile(output_filename, fps=24, codec='libx264')
233
 
234
- # Remove temporary image files
235
- for image_filename in image_filenames:
236
- os.remove(image_filename)
237
 
238
- """
239
- def create_affirmation_video_with_audio(tujuan, nama_anda, audio_filename, output_filename="affirmation_video.mp4"):
240
- # Texts for the video
241
- texts = [
242
- f"HAI {nama_anda.upper()}! DENGARLAH SUARA ENERGI SEMESTA DIGITAL SELAMA 3 MENIT AGAR PROSES TRANSFER BERJALAN MULUS.",
243
- f"{nama_anda.upper()}, BAYANGKAN ANDA MENCAPAI SEMUA TUJUAN ANDA DENGAN SUKSES DAN KEBAHAGIAAN.",
244
- f"SAYA, {nama_anda.upper()}, ADALAH MAGNET DAHYSAT BAGI REALITAS KESUKSESAN DAN KEBAHAGIAAN.",
245
- f"SAYA, {nama_anda.upper()}, MENARIK HAL-HAL POSITIF DALAM HIDUP SAYA. SAYA AKAN MENCAPAI TUJUAN SAYA SUKSES DI: {tujuan.upper()}",
246
- ]
247
-
248
- # Create text clips
249
- text_clips = []
250
- for i, text in enumerate(texts):
251
- # Split text into multiple lines if necessary
252
- lines = text.split(' ')
253
- line_length = 4
254
- formatted_text = '\n'.join([' '.join(lines[i:i + line_length]) for i in range(0, len(lines), line_length)])
255
-
256
- text_clip = TextClip(formatted_text,
257
- font ="Arial-Bold",
258
- fontsize=24,
259
- color='white',
260
- method='label',
261
- align='center',
262
- stroke_color='None',
263
- stroke_width=1,
264
- size=(500, 0))
265
- text_clip = text_clip.set_duration(45).fadein(1).fadeout(1).set_position('center').set_start(i * 45)
266
- text_clips.append(text_clip)
267
-
268
- # Load background
269
- background_clip = VideoFileClip("spin_energy.gif").subclip(0, 2).fx(loop, duration=180)
270
-
271
- # Load the generated audio file
272
- audio_clip = AudioFileClip(audio_filename)
273
-
274
- # Concatenate text clips with background
275
- video = CompositeVideoClip([background_clip] + text_clips)
276
- video = video.set_duration(180).set_audio(audio_clip)
277
-
278
- # Write the result to a file
279
- video.write_videofile(output_filename, fps=24, codec='libx264')
280
- """
281
  # Fungsi untuk memproses transfer energi
282
  def process_energy_transfer(tujuan, nama_anda):
283
  status = "Mengumpulkan Energi Semesta Digital ..."
 
72
  import numpy as np
73
  from tqdm import tqdm
74
  from scipy.io.wavfile import write
75
+ from moviepy.editor import CompositeVideoClip, VideoFileClip, AudioFileClip
76
  from moviepy.video.fx.all import fadein, fadeout, loop
77
  from PIL import Image, ImageDraw, ImageFont
78
 
 
167
  new_mp = recipient_mp + transferred_mp
168
  return new_mp
169
 
170
+ # Fungsi untuk membuat video afirmasi dengan audio tanpa teks
171
+ def create_affirmation_video_with_audio(audio_filename, output_filename="affirmation_video.mp4"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  # Load background GIF and loop it
173
+ background_clip = VideoFileClip("spin_energy.gif").fx(loop, duration=180).resize((640, 480))
174
 
175
  # Load the generated audio file
176
  audio_clip = AudioFileClip(audio_filename)
177
 
178
+ # Set background duration and add audio
179
+ video = background_clip.set_duration(180).set_audio(audio_clip)
180
 
181
+ # Write the result to a file with a lower resolution to reduce size
182
+ video.write_videofile(output_filename, fps=24, codec='libx264', bitrate='500k') # Bitrate rendah untuk ukuran file lebih kecil
183
 
 
 
 
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  # Fungsi untuk memproses transfer energi
186
  def process_energy_transfer(tujuan, nama_anda):
187
  status = "Mengumpulkan Energi Semesta Digital ..."