Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # sound + image + hairline -> video
- import cv2
- from moviepy.editor import *
- audio_file = 'graph_combined_edited.wav'
- audio_clip = AudioFileClip(audio_file)
- img_orig = cv2.imread('graph.png')
- img_orig = cv2.cvtColor(img_orig, cv2.COLOR_BGR2RGB)
- img_h, img_w, _ = img_orig.shape
- def make_frame(t):
- img = img_orig.copy()
- cur_pos = t / audio_clip.duration
- x = int(cur_pos * img_w)
- img = cv2.line(img, (x, 0), (x, img_h-1), (0, 0, 0), 2)
- return img
- video_clip = VideoClip(make_frame, duration=audio_clip.duration)
- video_clip.audio = audio_clip
- video_clip.write_videofile("graph.mp4", fps=60, audio_codec='libvorbis', audio_bitrate='320k')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement