JaMugen commited on
Commit
a9cce14
·
1 Parent(s): b05155b

Update Milestone5API.py

Browse files
Files changed (1) hide show
  1. Milestone5API.py +13 -9
Milestone5API.py CHANGED
@@ -10,6 +10,18 @@ from moviepy.editor import VideoFileClip
10
  from pydub import AudioSegment
11
  from moviepy.editor import VideoFileClip, AudioFileClip, TextClip, CompositeVideoClip
12
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_path, translated_text):
15
  print("Loading video...")
@@ -28,17 +40,9 @@ def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_
28
  video = video.set_audio(new_audio)
29
  print("Audio set to video successfully.")
30
 
31
- # Add text to video
32
- txt_clip = TextClip(translated_text, fontsize=70, color='white')
33
- txt_clip = txt_clip.set_duration(video.duration)
34
- txt_clip = txt_clip.set_position(('center', 'bottom'))
35
- video = CompositeVideoClip([video, txt_clip])
36
- print("Translated text added successfully.")
37
-
38
- print("Writing video file...")
39
- print("Writing video file...")
40
  try:
41
  video.write_videofile(output_video_file_path, codec="libx264", audio_codec="aac", remove_temp=True)
 
42
  print("Video file written successfully.")
43
  except Exception as e:
44
  print("Error writing video file:", e)
 
10
  from pydub import AudioSegment
11
  from moviepy.editor import VideoFileClip, AudioFileClip, TextClip, CompositeVideoClip
12
 
13
+ def add_text_to_video(input_video_path, output_video_path, text):
14
+ try:
15
+ subprocess.run([
16
+ 'ffmpeg',
17
+ '-i', input_video_path,
18
+ '-vf', f"drawtext=text='{text}':fontsize=24:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2",
19
+ '-c:a', 'copy',
20
+ output_video_path
21
+ ], check=True)
22
+ print("Text added to video successfully.")
23
+ except subprocess.CalledProcessError as e:
24
+ print("Error adding text to video:", e)
25
 
26
  def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_path, translated_text):
27
  print("Loading video...")
 
40
  video = video.set_audio(new_audio)
41
  print("Audio set to video successfully.")
42
 
 
 
 
 
 
 
 
 
 
43
  try:
44
  video.write_videofile(output_video_file_path, codec="libx264", audio_codec="aac", remove_temp=True)
45
+ add_text_to_video(output_video_file_path, output_video_file_path, translated_text)
46
  print("Video file written successfully.")
47
  except Exception as e:
48
  print("Error writing video file:", e)