imageio: Random access of mp4 file does not yield consistent frame array for a given index
We are running imageio 2.19.3 on python 3.8. We are using reader.get_data(fr_idx) (v2 style) for random access to a frame in an mp4 video.
Unfortunately, depending on the frame index of the previously requested frame, get_data yields different arrays for the same frame index. In v3 style access with imread, it does not seem to depend on the previous frame (as it is stateless?) but the output differs from the output of the iterator.
Here is some v2 test code:
import imageio
import hashlib
from tqdm import tqdm
reader = imageio.get_reader("360_0011.MP4")
reader2 = imageio.get_reader("360_0011.MP4")
# Build up a hash library
hashes = dict()
for i_fr, img in enumerate(tqdm(reader)):
hashes[i_fr] = hashlib.md5(img).hexdigest()
# Query frame 123 after frame 0
fr_idx = 123
reader2.get_data(0)
fr_hash = hashlib.md5(reader2.get_data(fr_idx)).hexdigest()
print(fr_hash == hashes[fr_idx])
print(fr_hash in hashes.values())
list(hashes.values()).index(fr_hash)
>> True
>> True
>> 123
# Query frame 124 after frame 0
fr_idx = 124
reader2.get_data(0)
fr_hash = hashlib.md5(reader2.get_data(fr_idx)).hexdigest()
print(fr_hash == hashes[fr_idx])
print(fr_hash in hashes.values())
list(hashes.values()).index(fr_hash)
>> False
>> True
>> 125
# Query frame 125 after frame 0
fr_idx = 125
reader2.get_data(0)
fr_hash = hashlib.md5(reader2.get_data(fr_idx)).hexdigest()
print(fr_hash == hashes[fr_idx])
print(fr_hash in hashes.values())
list(hashes.values()).index(fr_hash)
>> False
>> True
>> 126
# Query frame 124
fr_idx = 124
fr_hash = hashlib.md5(reader2.get_data(fr_idx)).hexdigest()
print(fr_hash == hashes[fr_idx])
print(fr_hash in hashes.values())
list(hashes.values()).index(fr_hash)
>> False
>> True
>> 125
# Query frame 123
fr_idx = 123
fr_hash = hashlib.md5(reader2.get_data(fr_idx)).hexdigest()
print(fr_hash == hashes[fr_idx])
print(fr_hash in hashes.values())
list(hashes.values()).index(fr_hash)
>> True
>> True
>> 123
# Query frame 124
fr_idx = 124
fr_hash = hashlib.md5(reader2.get_data(fr_idx)).hexdigest()
print(fr_hash == hashes[fr_idx])
print(fr_hash in hashes.values())
list(hashes.values()).index(fr_hash)
>> True
>> True
>> 124
I would prefer to avoid posting the video publicly, but I would be happy to provide it to anyone in direct communication who would like to take the issue on.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (6 by maintainers)
That was it, thanks. Yes, I still had the pull request repo there. Sorry!