forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_photo_to_audio.py
31 lines (25 loc) · 1.24 KB
/
add_photo_to_audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from moviepy.editor import AudioFileClip, ImageClip
def add_static_image_to_audio(image_path, audio_path, output_path):
"""Create and save a video file to `output_path` after
combining a static image that is located in `image_path`
with an audio file in `audio_path`"""
# create the audio clip object
audio_clip = AudioFileClip(audio_path)
# create the image clip object
image_clip = ImageClip(image_path)
# use set_audio method from image clip to combine the audio with the image
video_clip = image_clip.set_audio(audio_clip)
# specify the duration of the new clip to be the duration of the audio clip
video_clip.duration = audio_clip.duration
# set the FPS to 1
video_clip.fps = 1
# write the resuling video clip
video_clip.write_videofile(output_path)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Simple Python script to add a static image to an audio to make a video")
parser.add_argument("image", help="The image path")
parser.add_argument("audio", help="The audio path")
parser.add_argument("output", help="The output video file path")
args = parser.parse_args()
add_static_image_to_audio(args.image, args.audio, args.output)