Advertisement
yclee126

Image player (hairline sim)

Jan 17th, 2022
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. # sound + image + hairline -> video
  2.  
  3. import cv2
  4. from moviepy.editor import *
  5.  
  6. audio_file = 'graph_combined_edited.wav'
  7. audio_clip = AudioFileClip(audio_file)
  8. img_orig = cv2.imread('graph.png')
  9. img_orig = cv2.cvtColor(img_orig, cv2.COLOR_BGR2RGB)
  10.  
  11. img_h, img_w, _ = img_orig.shape
  12.  
  13. def make_frame(t):
  14.     img = img_orig.copy()
  15.    
  16.     cur_pos = t / audio_clip.duration
  17.     x = int(cur_pos * img_w)
  18.     img = cv2.line(img, (x, 0), (x, img_h-1), (0, 0, 0), 2)
  19.    
  20.     return img
  21.  
  22. video_clip = VideoClip(make_frame, duration=audio_clip.duration)
  23. video_clip.audio = audio_clip
  24. video_clip.write_videofile("graph.mp4", fps=60, audio_codec='libvorbis', audio_bitrate='320k')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement