dmlc / decord

An efficient video loader for deep learning with smart shuffling that's super easy to digest
Apache License 2.0
1.89k stars 161 forks source link

VideoReader hangs when going out of scope #154

Open DinoMan opened 3 years ago

DinoMan commented 3 years ago

I have just started trying this library for loading videos and it has all the features I am looking for. Unfortunately, when I run a simple script to read some video the script doesn't exit and hangs. Here is the minimal example I run:

import decord
vr = decord.VideoReader('example_vid.mp4', width=128, height=128)
vid = vr.get_batch(range(50, 125))

I have checked and it seems to hang on the del function on the _CAPI_VideoReaderFree(self._handle) call.

DinoMan commented 3 years ago

I compiled from source and the problem went away but it would still be good to get an explanation about why this happened,

zhreshold commented 3 years ago

conflicting c libs might cause the error, since deadlocks are too difficult to track I can only imagine something goes wrong in python call.

dmenig commented 1 year ago

I have the same issue after compiling from source.

MarStarck commented 1 year ago

I met the same problem

KimbingNg commented 6 months ago

Same, here

MarStarck commented 2 months ago

I figured out maybe its caused by the video file info not correct. eg, the fps * duration not match the total frame count. But opencv can handle those files. so I read and rewrite those problematic files using OpenCV.

alsmeirelles commented 3 weeks ago

In my current experiments, it seems that SeekAccurate in C++ API hangs somewhere. I'm using a workaround with asyncio, similar to this: https://stackoverflow.com/questions/34452590/timeout-handling-while-using-run-in-executor-and-asyncio.

I set a timeout of 1 s for the seek_accurate python method and than read the next frame:

        loop = asyncio.get_event_loop()
        for x in range(nframes):
            future = loop.run_in_executor(None, dc_vid.seek_accurate, idx[x])
            try:
                await asyncio.wait_for(future, timeout=1)
            except asyncio.TimeoutError:
                print(f"Timeout for frame {idx[x]}")
                continue
            fr = dc_vid.next().asnumpy()

As a result, you may not get all the frames you wanted and it's slower than native get_batch