dmlc / dmlc/decord

Bug report: [BytesIO]Unable to handle EOF when seeking after loading several video files

Open
#156 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
232
PR merge metrics
No merged PRs in 30d

Description

I am getting the following error with decord==0.5.2 with Python 3.7

```
with open(self.current_video_path, "rb") as video_file:
self.video_reader = decord.VideoReader(video_file, ctx=decord.cpu(0))
```

```
ERROR — 2021-05-21 19:53:53,209 — dummy_servicename — main:68 — The lambda encountered a function error
Traceback (most recent call last):
File "/ThriEntranceCounterBenchmarkingTool/benchmarking_tool/utils/patch_functions.py", line 425, in _visualise_results
frame = self.video_reader[seek_frame_index].asnumpy()
File "/miniconda/envs/benchmarking/lib/python3.7/site-packages/decord/video_reader.py", line 102, in __getitem__
return self.next()
File "/miniconda/envs/benchmarking/lib/python3.7/site-packages/decord/video_reader.py", line 114, in next
arr = _CAPI_VideoReaderNextFrame(self._handle)
File "/miniconda/envs/benchmarking/lib/python3.7/site-packages/decord/_ffi/_ctypes/function.py", line 175, in __call__
ctypes.byref(ret_val), ctypes.byref(ret_tcode)))
File "/miniconda/envs/benchmarking/lib/python3.7/site-packages/decord/_ffi/base.py", line 78, in check_call
raise DECORDError(err_str)
decord._ffi.base.DECORDError: [19:53:53] /github/workspace/src/video/video_reader.cc:438: [BytesIO]Unable to handle EOF, exit...
```
When I try to reproduce the issue by loading the same file and same seek_frame_index index, I cannot reproduce this error. The error occurs erratically on different videos when I re-run my software. My software iterates over many videos so looks something like this if it was condensed to its core logic:

```
for video_file in video_files:
with open(self.current_video_path, "rb") as video_file:
self.video_reader = decord.VideoReader(video_file, ctx=decord.cpu(0))

seek_frame_index = get_seek_index()
frame = self.video_reader[seek_frame_index].asnumpy()
```

I spotted when the error occurs, it occurs on the first time we have performed indexing for a given video suggesting a rare race condition such that the issue occurs maybe only when accessing a frame soon after a file has been opened, and only after the self.video_file reference has been used to open many video files. My guess is that the issue is related to the way decord is accessing a file after the context manager has closed, and maybe it has not cleanly closed the previous video_reader before replacing it with the new video_reader for the new video_file?

I tried:
```
with open(self.current_video_path, "rb") as video_file:
if self.video_reader is not None:
del self.video_reader # To prevent a race condition when opening new files as
# decord is multithreaded
self.video_reader = decord.VideoReader(video_file, ctx=decord.cpu(0))
```
But got the same result

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.