Frame reading errors with ffmpeg

705 Aufrufe
Direkt zur ersten ungelesenen Nachricht

GiovanniB

ungelesen,
02.10.2017, 10:21:0702.10.17
an imageio

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.


Almar Klein

ungelesen,
09.10.2017, 04:14:5109.10.17
an ima...@googlegroups.com
Hey Giovanni,

First off, is there a particular reason to use ffmpeg/mp4 to encode the files? Video file formats are optimized for temporal data, and apply all kinds of tricks that play into how our brain processes temporal images. In other words: it's not a good format to store 3D data in. I'd recommend using .npz instead.

If you do want to use ffmpeg, this issue might be related to the difficulty that imageio sometimes has to estimate the number of frames. Can you explain the figures to me?

Regards,
  Almar
--
You received this message because you are subscribed to the Google Groups "imageio" group.
To unsubscribe from this group and stop receiving emails from it, send an email to imageio+u...@googlegroups.com.
To post to this group, send email to ima...@googlegroups.com.
Visit this group at https://groups.google.com/group/imageio.
For more options, visit https://groups.google.com/d/optout.

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten