Is it possible to embed a tiff/array video with Streamlit?

From the API it reads

data ( str , bytes , BytesIO , numpy.ndarray , or file opened with )

But it doesn’t seem to work if I load the video as a numpy array. Am I using this right?

import numpy as np
import streamlit as st

t, h, w, c = 10, 20, 20, 3
video = np.random.normal(0, 1, t*h*w*c).reshape((t, h, w, c))
1 Like

Hi @komodovaran,

Yes, Streamlit accepts numpy arrays for video, audio, and image data. However, those arrays must contain the necessary headers and image information already (streamlit doesn’t construct them for you).

There is a “Todo” in the Streamlit code about making an API through which Streamlit might construct headers on the user’s behalf. Where that might fit on the product roadmap might be a ways off though. :slight_smile:

Is this header an issue on github? I’m interested in tracking this issue.

1 Like

There wasn’t one, surprisingly, so I made one. :bow_and_arrow:

@komodovaran – I’m still researching how you would create the headers for a TIFF video; meanwhile check out this gist showing how to generate TIFF images starting from nparrays.

I tried the first snippet and it worked. pip install tifffile and then (reposting here):

from tifffile import imsave
import numpy as np

# create data
d = np.ndarray(shape=(10,20), dtype=np.float32) # also supports 64bit but ImageJ does not
d[()] = np.arange(200).reshape(10, 20)

# save 32bit float (== single) tiff
imsave('test.tif', d) #, description="hohoho")