Hi everybody,
first of all thank you for working on this project, i really appreciate it.
I am working on microscopical image analysis, in particular I have a set of large (2048x2048x2800 / x,y,z) ".DCIMG" (proprietary format) volumes and I want to do some performance evaluation on encoding and decoding them (with
ffmpeg).
Encoding runs quite smoothly but when it comes to decoding I'm experiencing some kind of issues:
Let's say I have an "x_y_z.mp4" file generated from the encoding of a "x_y_z.dcimg" file, now I want to decode this video file and extract every frame's numpy array from it.
I've initially used your function
imageio.mimread(*args) but it returned a "
CannotReadFrameError", reading
0 bytes against an expected
n bytes.
I've noticed that it was always the 1400th frame to cause this error (full length = 2800) so I've decided to create a Reader object and read frame by frame, for better understanding of the problem.
The first half of the file always gives no problem at all, but advancing with the index and
catching the error gives me this pattern of errors :
https://imgur.com/2f2Azkn (from frame 1400 to 2800)
Splitting the file in two parts (from frame 0 to 1400 and from frame 1400 to 2800) didn't really help, you can check yourself:
https://imgur.com/a/hMJwd (from frame 0 to 1400)
https://imgur.com/a/gQcg1 (from frame 1400 to 2800)
This is not an issue related to the file itself since
I can directly access to any frame's data ( via
imageio.get_data(*args) ), even to the ones that are impossibile to be read.
Code:
def decode_video(path, filename, format_out):
""" Decodes the selected video file and returns the corresponding tensor
as a uint8 list of numpy arrays.
Args:
path (string) : path to the directory containing the file to be decoded.
filename (string) : string containing the file name.
format_out (string) : string containing the file extension of the file to be decoded.
Returns:
list of numpy_array
"""
if filename.endswith(format_out):
vid = imageio.get_reader(path+filename,'ffmpeg')
nframes = len(vid)
list = []
for i in range(nframes):
try:
list.append(vid.get_data(i))
except:
e = sys.exc_info()[0]
print('error {0} at index {1}'.format(e,i))
else:
print('There is a non-{} file\n'.format(format_out))
return(list)
def encode_video(path, filename, format_out, codec):
""" Encodes the whole selected raw file to a `format_out` file using ffmpeg
Args:
path (string) : path to the directory containing the file to be encoded.
filename (string) : string containing the file name.
format_out (string) : video container (i.e. 'mp4')
codec (string) : codec for encoding the file (i.e. 'libx264','libx265')
"""
my_file = dc.DCIMGFile(path + filename)
whole_volume = my_file.whole()
imageio.mimwrite(filename + format_out, whole_volume,
fps=25, codec=codec)
Thank you for helping me!
Giovanni.