Skip to content

Commit

Permalink
FEAT: enable HTTP based streams in pyav (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
FirefoxMetzger committed Jul 22, 2022
1 parent cd721d9 commit fb1150d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion imageio/plugins/pyav.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,14 @@ def __init__(

if request.mode.io_mode == IOMode.read:
try:
self._container = av.open(request.get_file())
if request._uri_type == 5: # 5 is the value of URI_HTTP
# pyav should read from HTTP by itself. This enables reading
# HTTP-based streams like DASH. Note that solving streams
# like this is temporary until the new request object gets
# implemented.
self._container = av.open(request.raw_uri)
else:
self._container = av.open(request.get_file())
self._video_stream = self._container.streams.video[0]
self._decoder = self._container.decode(video=0)
except av.AVError:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_pyav.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,19 @@ def test_sequential_reading(test_images):
actual_imgs = [first_read, second_read]

np.allclose(actual_imgs, expected_imgs)


def test_uri_reading(test_images):
uri = "https://dash.akamaized.net/dash264/TestCases/2c/qualcomm/1/MultiResMPEG2.mpd"

with av.open(uri) as container:
for idx, frame in enumerate(container.decode(video=0)):
if idx < 250:
continue

expected = frame.to_ndarray(format="rgb24")
break

actual = iio.imread(uri, plugin="pyav", index=250)

np.allclose(actual, expected)

0 comments on commit fb1150d

Please sign in to comment.