decord icon indicating copy to clipboard operation
decord copied to clipboard

DECORDError for certain video files

Open kyamagu opened this issue 3 years ago • 1 comments

Hi, thanks for the great package.

I just encountered the following error when decoding a small video file (attached below). I am using decord 0.52.0 on mac.

vr = decord.VideoReader('encoded.mp4')
video = vr[:].asnumpy()
del vr
---------------------------------------------------------------------------
DECORDError                               Traceback (most recent call last)
<ipython-input-33-b6e831ff59b0> in <module>
      1 vr = decord.VideoReader('../transcoded.mp4')
----> 2 video = vr[:].asnumpy()
      3 del vr

~/.pyenv/versions/3.7.10/lib/python3.7/site-packages/decord/video_reader.py in __getitem__(self, idx)
     94         """
     95         if isinstance(idx, slice):
---> 96             return self.get_batch(range(*idx.indices(len(self))))
     97         if idx < 0:
     98             idx += self._num_frame

~/.pyenv/versions/3.7.10/lib/python3.7/site-packages/decord/video_reader.py in get_batch(self, indices)
    170         assert self._handle is not None
    171         indices = _nd.array(self._validate_indices(indices))
--> 172         arr = _CAPI_VideoReaderGetBatch(self._handle, indices)
    173         return bridge_out(arr)
    174 

~/.pyenv/versions/3.7.10/lib/python3.7/site-packages/decord/_ffi/_ctypes/function.py in __call__(self, *args)
    173         check_call(_LIB.DECORDFuncCall(
    174             self.handle, values, tcodes, ctypes.c_int(num_args),
--> 175             ctypes.byref(ret_val), ctypes.byref(ret_tcode)))
    176         _ = temp_args
    177         _ = args

~/.pyenv/versions/3.7.10/lib/python3.7/site-packages/decord/_ffi/base.py in check_call(ret)
     76                 err_str = err_str.split('Stack trace')[0].strip()
     77             raise DECORDLimitReachedError(err_str)
---> 78         raise DECORDError(err_str)
     79 
     80 

DECORDError: [16:23:03] /Users/runner/work/decord/decord/src/runtime/ndarray.cc:171: Check failed: from_size == to_size (36864 vs. 27648) DECORDArrayCopyFromTo: The size must exactly match

The following succeeds, but strangely the resulting video has 4 channels instead of 3.

vr = decord.VideoReader('encoded.mp4')
video = np.stack([vr.next().asnumpy() for _ in range(len(vr))], axis=0)
del vr

Here is the failing video file. Perhaps the video file has unknown color space?

https://user-images.githubusercontent.com/1190780/116515453-46a4c200-a907-11eb-916a-debdd0435cdc.mp4

kyamagu avatar Apr 29 '21 07:04 kyamagu

Yep, from_size == to_size (36864 vs. 27648) is 4:3, so currently I believe 4 channel video have to be converted to 3 channel inside of ffmpeg mapping, this seems to be a bug in color space conversion.

zhreshold avatar Jun 15 '21 01:06 zhreshold