OpenCV 实现播放本地mp4视频或远程服务mp4视频 您所在的位置:网站首页 远程播放音频怎么弄 OpenCV 实现播放本地mp4视频或远程服务mp4视频

OpenCV 实现播放本地mp4视频或远程服务mp4视频

2024-05-17 04:09| 来源: 网络整理| 查看: 265

上代码:

import cv2 # 获得视频的格式 videoCapture = cv2.VideoCapture('./mac-bruce-tpl-cn-2018_1280x720h.mp4') # 本地mp4文件 # videoCapture = cv2.VideoCapture('http://127.0.0.1:8080/static/mac-bruce-tpl-cn-2018_1280x720h.mp4') # 服务端mp4文件 # 获得码率及尺寸 fps = videoCapture.get(cv2.CAP_PROP_FPS) width = int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)) size = (width, height) # print(fps, size) # 编码格式 # fourcc = cv2.VideoWriter_fourcc(*'XVID') f = cv2.VideoWriter_fourcc('M', 'P', '4', '2') # ?? # 指定写视频的格式, I420-avi, MJPG-mp4 videoWriter = cv2.VideoWriter('oto_other.avi', f, fps, size) # 读帧 success, frame = videoCapture.read() while success : videoWriter.write(frame) # 写视频帧 cv2.imshow("video", frame) # 显示 cv2.waitKey(int(1000/int(fps))) # 延迟 # if ord("q") == cv2.waitKey(41): # break success, frame = videoCapture.read() # 获取下一帧 # 资源释放 cv2.destroyAllWindows() videoCapture.release() videoWriter.release()

如题 python + opencv 现可以实现播放本地视频和远程服务器的mp4视频。

放两个问题:

question 1: 我该如何打开并播放远程的流媒体视频呢?

question 2: 流媒体视频又如何搭建?

度娘了一下尝试了搭建,不成功。有知道的大佬告诉我下。

本文代码参考以下大神: python如何播放远程流媒体视频? Opencv-Python cv2.CV_CAP_PROP_FPS错误 OpenCV 用 VideoWriter 创建视频(Python 版本) opencv+python读写视频流

以上。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有