Unverified Commit fec7cd61 authored by Jintao Lin's avatar Jintao Lin Committed by GitHub
Browse files

Support reading video from url (#531)

* add url support for VideoReader

* add a comment

* add unittest

* use a connectable url for ci
parent 9769024f
...@@ -62,7 +62,9 @@ class VideoReader: ...@@ -62,7 +62,9 @@ class VideoReader:
""" """
def __init__(self, filename, cache_capacity=10): def __init__(self, filename, cache_capacity=10):
check_file_exist(filename, 'Video file not found: ' + filename) # Check whether the video path is a url
if not filename.startswith(('https://', 'http://')):
check_file_exist(filename, 'Video file not found: ' + filename)
self._vcap = cv2.VideoCapture(filename) self._vcap = cv2.VideoCapture(filename)
assert cache_capacity > 0 assert cache_capacity > 0
self._cache = Cache(cache_capacity) self._cache = Cache(cache_capacity)
......
...@@ -45,8 +45,10 @@ class TestVideoReader: ...@@ -45,8 +45,10 @@ class TestVideoReader:
def setup_class(cls): def setup_class(cls):
cls.video_path = osp.join(osp.dirname(__file__), '../data/test.mp4') cls.video_path = osp.join(osp.dirname(__file__), '../data/test.mp4')
cls.num_frames = 168 cls.num_frames = 168
cls.video_url = 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4' # noqa: E501
def test_load(self): def test_load(self):
# read from video file
v = mmcv.VideoReader(self.video_path) v = mmcv.VideoReader(self.video_path)
assert v.width == 294 assert v.width == 294
assert v.height == 240 assert v.height == 240
...@@ -57,6 +59,16 @@ class TestVideoReader: ...@@ -57,6 +59,16 @@ class TestVideoReader:
import cv2 import cv2
assert isinstance(v.vcap, type(cv2.VideoCapture())) assert isinstance(v.vcap, type(cv2.VideoCapture()))
# read from video url
v = mmcv.VideoReader(self.video_url)
assert v.width == 320
assert v.height == 240
assert v.fps == 15
assert v.frame_cnt == 1889
assert len(v) == 1889
assert v.opened
assert isinstance(v.vcap, type(cv2.VideoCapture()))
def test_read(self): def test_read(self):
v = mmcv.VideoReader(self.video_path) v = mmcv.VideoReader(self.video_path)
img = v.read() img = v.read()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment