You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there is a discrepancy between what our FFmpeg plugin can actually read and what it claims it can read. It claims to be able to read less than it actually does. The cause of this is that _can_read makes a decision based on the file's extension alone instead of querying the file's metadata/header (e.g., via ffprobe). This is problematic because it will reject reading from bytes/BytesIO or reading any format that we have not manually registered.
Reacted by Pavel Kulikov, Eva Maxfield Brown and Yoshiharu Hirose
Note, however, that this will not work in all cases, because it will also accept resources that aren't supported by ffmpeg. For example iio.imread("some.jpg", format="ffmpeg") will be accepted by FFMPEG, but produce a cryptic error message from somewhere deep in the library.
Additionally, it will prevent any plugins/backends with a priority lower than the priority of FFMPEG to be tested when searching for a format that can read a request with an unknown or unspecified extension. For example, FreeImage has a lower priority than FFMPEG, and - when using this workaround - it will never be tested. Instead, reading such files will potentially break somewhere deep in the library again, because FFMPEG will accept the request, but may not be able to actually read it.
This also affects us over at aicsimageio. Until one of our own users requires a change it is a lower priority for us but will update this issue if something comes up.
On older versions of ImageIO, a workaround is to set the extension for the stream manually. Note, however, that this is more of a hack, because there is no guarantee that the (private) _extension will be around forever:
importimageioasiioreq=iio.core.Request(video_bytes, "r")
req._extension=".mkv"# your format extension hereframe=iio.imread(req)
Activity
Kulikovpavel commentedon Nov 24, 2021
Temporary fix
FirefoxMetzger commentedon Nov 24, 2021
Thanks for adding this workaround @Kulikovpavel.
Note, however, that this will not work in all cases, because it will also accept resources that aren't supported by ffmpeg. For example
iio.imread("some.jpg", format="ffmpeg")will be accepted by FFMPEG, but produce a cryptic error message from somewhere deep in the library.Additionally, it will prevent any plugins/backends with a priority lower than the priority of FFMPEG to be tested when searching for a format that can read a request with an unknown or unspecified extension. For example, FreeImage has a lower priority than FFMPEG, and - when using this workaround - it will never be tested. Instead, reading such files will potentially break somewhere deep in the library again, because FFMPEG will accept the request, but may not be able to actually read it.
evamaxfield commentedon Dec 17, 2021
Bumping this after your comment @FirefoxMetzger!
This also affects us over at
aicsimageio. Until one of our own users requires a change it is a lower priority for us but will update this issue if something comes up.FirefoxMetzger commentedon Feb 7, 2022
For future readers, you can use the new (v2.15.0)
format_hint=kwarg in v3 to help the FFmpeg backend and read the bytes/BytesIO:On older versions of ImageIO, a workaround is to set the extension for the stream manually. Note, however, that this is more of a hack, because there is no guarantee that the (private)
_extensionwill be around forever: