简体   繁体   English

如何从 imutils 的 FileVideoStream 中的 URL 读取视频?

[英]How to read video from URL in FileVideoStream in imutils?

I have a Python program with a video file reader scenario.我有一个带有视频文件阅读器场景的 Python 程序。 To do this, I use the FileVideoStream API from the library imutils.video as follows为此,我使用库 imutils.video 中的 FileVideoStream API,如下所示

from imutils.video import FileVideoStream
import time
import numpy as np
import cv2

vs = FileVideoStream('~/Downloads/capture.webm').start()
time.sleep(1.0)

while True:
    if not vs.more():
        print("vs", vs.more())
        vs.stop()
        break
    print("vs", vs.more())
    frame = vs.read()

The problem is the location "~/Downloads/capture.webm" is not recognized by the FileVideoStream function even the video file is exists in the mentioned directory.问题是 FileVideoStream function 无法识别位置“~/Downloads/capture.webm”,即使视频文件存在于上述目录中。

ERROR: OpenCV: Couldn't read video stream from file "~/Downloads/capture.webm"

But when I save the video in the same python project directory and call as "capture.webm" it works!但是,当我将视频保存在同一个 python 项目目录中并调用为“capture.webm”时,它就可以工作了!

And also the function doesn't recognize videos from a URL. function 也无法识别来自 URL 的视频。

How can I solve this?我该如何解决这个问题?

Completion for ~ inside path ~/Downloads/capture.webm is done by bash/sh/etc. ~内部路径~/Downloads/capture.webm的完成由bash/sh/etc. . . If you are using python you have to use full path /home/username/Downloads/capture.webm .如果您使用的是 python 您必须使用完整路径/home/username/Downloads/capture.webm

You can also use os.environ.get('USER') to get current USER name and insert it inside full path.您还可以使用os.environ.get('USER')获取当前用户名并将其插入完整路径中。 For example例如

'/home/%s/Downloads/capture.webm' % os.environ.get('USER')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM