I need to play audio in sync with frames extracted from a video

Viewed 118

i am a beginner in coding and i need to play audio in sync with frames extracted from a video. I already extracted all the frames from the video and the audio too. and now i'm stuck .I need help to make a python app, that will 'play' the images along with the audio, and make sure it is synchronized. the program should measure time. Time will start at the begging of the playback, audio will start playing at the begging of the playback. Then use the current time and framerate to get the appropriate image and show it on screen.

find below what i have done so far . Thank you in advance .

import cv2
import moviepy.editor as mp

#Extracting frames for a video and saving those frames.

vidcap = cv2.VideoCapture('video_tiav.mp4')
success,image = vidcap.read()
count = 0
while success:
  cv2.imwrite("frame%d.jpg" % count, image)     # save frame as JPEG file      
  success,image = vidcap.read()
  print('Read a new frame: ', success)
  count += 1

#Extracting audio for a video and saving .

  video = mp.VideoFileClip(r'video_tiav.mp4') #'r' indicates that we are reading a file
  video.audio.write_audiofile(r"output.mp3")
0 Answers
Related