我必须从特定帧播放视频,我可以使用opencv来播放,但是如何播放该特定视频的音频 我已经有了要开始播放视频的框架,我也只想要相应的音频。
cap = cv2.VideoCapture('tcs.mp4')
fps = cap.get(cv2.CAP_PROP_FPS)
count = 0
success = True
while success:
success,frame = cap.read()
count+=1
ts = count/fps
if t == ts:
print("time stamp of current frame:",count/fps)
print("Press Q to quit")
f_count = count
cap.set(cv2.CAP_PROP_POS_FRAMES, f_count)
# Check if camera opened successfully
if (cap.isOpened()== False):
print("Error opening video file")
# Read until video is completed
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
# Display the resulting frame
cv2.imshow('Frame', frame)
# Press Q on keyboard to exit
if cv2.waitKey(25) & 0xFF == ord('q'):
break
# Break the loop
else:
break
# When everything done, release
# the video capture object
cap.release()
# Closes all the frames
cv2.destroyAllWindows()
答案 0 :(得分:2)
OpenCV是用于计算机视觉的库。要播放音频,您将不得不使用另一个库(即,在C ++中,一个库将使用FFMPEG)。
Python中的另一种选择是ffpyplayer(https://pypi.org/project/ffpyplayer/),它基于FFMPEG。
您可以使用OpenCV处理帧,并在同时播放ffpyplayer捕获的音频帧时显示帧。
更好的选择是处理视频文件并将其写入OpenCV中的磁盘,然后使用python-VLC播放。