使用python+opencv+ffpyplayer对视频进行播放,同时播放音频

import cv2
import numpy as np
from ffpyplayer.player import MediaPlayer

video_path = "./source.mp4"

def PlayVideo(video_path):
    video=cv2.VideoCapture(video_path)
    player = MediaPlayer(video_path)
    while True:
        grabbed, frame = video.read()
        audio_frame, val = player.get_frame()
        if not grabbed:
            print("End of video")
            break
        if cv2.waitKey(28) & 0xFF == ord("q"):
            break
        cv2.imshow("Video", frame)
        if val != 'eof' and audio_frame is not None:
            # audio
            img, t = audio_frame
            # print(img, t)
    video.release()
    cv2.destroyAllWindows()

PlayVideo(video_path)

posted @ 2022-06-14 20:01  小Aer  阅读(133)  评论(0编辑  收藏  举报  来源