cv2.waitKey will not allow for decimals, because of this my videos that have frame rates of 59.97fps will only run at 59. This causes the video and the audio not to sync up correctly. Also, the display size of certain videos does not fill the whole screen, instead, they get cut off. Thanks in advance Here is my code:
import cv2
import numpy as np
#ffpyplayer for playing audio
from ffpyplayer.player import MediaPlayer
userinput = input('What video u want? ')
variable = 'j'
video_path = ""
while(userinput != 'v'):
if(userinput.find("LTP") != -1):
video_path = "LTP.mp4"
break
if(userinput.find("Henry") != -1):
video_path= "Henry Smith.mp4"
break
if(userinput.find("Apple")!= -1):
video_path = "Apple Factory.mp4"
break
if(userinput.find("Grinch") != -1):
video_path = "Grinch Sample.mp4"
break
def PlayVideo(video_path):
video=cv2.VideoCapture(video_path)
player = MediaPlayer(video_path)
fps = video.get(cv2.CAP_PROP_FPS)
interval = int(1000/fps)
while True:
grabbed, frame=video.read()
audio_frame, val = player.get_frame()
if not grabbed:
print("End of video")
break
if cv2.waitKey(interval) & 0xFF == ord("q"):
break
cv2.imshow("Video", frame)
if val != 'eof' and audio_frame is not None:
#audio
img, t = audio_frame
video.release()
cv2.destroyAllWindows()
PlayVideo(video_path)