三分钟带你用python写一个自己的播放器

步骤:

1.用OpenCV读取视频流;

2.用cv2.show()把读取的帧显示出来即可。

看代码:

#coding:utf-8
import os
import cv2


def video_reader(video_path):
    video = cv2.VideoCapture(video_path)
    succ, frame = video.read()
    height, width, _ = frame.shape

    fourcc = cv2.VideoWriter_fourcc(*'MJPG')
    out = cv2.VideoWriter('result.avi', fourcc, 10.0, (width, height))


    while succ:
        succ, frame = video.read()
        if not succ:
            break
        out.write(frame)
        cv2.imshow("test_video", frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cv2.destroyAllWindows()
    video.release()
    out.release()


if __name__ == "__main__":
    video_path = "test.mp4"
    video_reader(video_path)

参考:https://blog.csdn.net/Guo_Python/article/details/105821786

猜你喜欢

转载自blog.csdn.net/Guo_Python/article/details/105833392