I am creating a python class to process videos received from a http post. The videos can be from a wide range of sizes, 10 seconds up to 10 hours. I am looking for a way to get video metadata such as fps, height, width etc. without having to store the whole video in memory.
The class is initialized like:
class VideoToolkit:
def __init__(self,video,video_name,media_type,full_video=True,frame_start=None,frame_stop=None):
self._frames = iio.imiter(video,format_hint=''.join(['.',media_type.split('/')[1]])) # Generator
self._meta = iio.immeta(video,exclude_applied=False)
The line of self._meta
doesn't work giving an error:
OSError: Could not find a backend to open `<bytes>`` with iomode `r`.
Is there a similar way to get metadata using imageio.v3 and not storing the whole video in memory?
Just as an example, it is possible to get the metadata directly opening a video from a file:
import imageio.v3 as iio
metadata = iio.immeta('./project.mp4',exclude_applied=False)
print(metadata)
Output:
{'plugin': 'ffmpeg', 'nframes': inf, 'ffmpeg_version': '4.2.2-static https://johnvansickle.com/ffmpeg/ built with gcc 8 (Debian 8.3.0-6)', 'codec': 'mpeg4', 'pix_fmt': 'yuv420p', 'fps': 14.25, 'source_size': (500, 258), 'size': (500, 258), 'rotate': 0, 'duration': 1.69}
But opening the same file as bytes, this didn't work:
import imageio.v3 as iio
with open('./project.mp4', 'rb') as vfile:
vbytes = vfile.read()
metadata = iio.immeta(vbytes,exclude_applied=False)
print(metadata)
Output:
OSError: Could not find a backend to open `<bytes>`` with iomode `r`.
PS: One way could be doing next(self._frames)
to get the first frame and then get its shape, but the video fps would be still missing.