For a viewer, I am trying to randomly access frame in an mp4 file. Unfortunately, depending on where I start off, I am getting different frames from the same index, in my case for any frame after frame 123:
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
It seems like as long as I am querying in series it works for all subsequent frames (I checked multiple ranges):
reader2.get_data(0)
for i in range(1130,1140):
fr_hash = hashlib.md5(reader2.get_data(i)).hexdigest()
print(f"{i} - {fr_hash == hashes[i]} - {list(hashes.values()).index(fr_hash)}")
>> 1130 - False - 1131
>> 1131 - True - 1131
>> 1132 - True - 1132
>> 1133 - True - 1133
>> 1134 - True - 1134
>> 1135 - True - 1135
>> 1136 - True - 1136
>> 1137 - True - 1137
>> 1138 - True - 1138
>> 1139 - True - 1139
Is this somehow intended/expected? is this a bug? Is there a way to work around it except for always querying 2 frames?