当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Streamlit st.video用法及代码示例


显示视频播放器。

函数签名

st.video(data, format="video/mp4", start_time=0)
参数说明

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

io.open()。指向要加载的视频的原始视频数据、文件名或 URL。包括对YouTube URL 的支持。 Numpy 数组和原始数据格式必须包含所有必要的文件头以匹配指定的文件格式。

format (str)

视频文件的 MIME 类型。默认为'video/mp4'。有关详细信息,请参阅https://tools.ietf.org/html/rfc4281

start_time (int)

该元素应该开始播放的时间。

示例

video_file = open('myvideo.mp4', 'rb')
video_bytes = video_file.read()

st.video(video_bytes)

注意

如果使用 MP4V(OpenCV 中的导出选项)对某些视频进行编码,则某些视频可能无法显示,因为浏览器并未广泛支持此编解码器。将您的视频转换为 H.264 将允许视频在 Streamlit 中显示。有关详细信息,请参阅此 StackOverflow post 或此 Streamlit forum post

相关用法


注:本文由纯净天空筛选整理自streamlit.io大神的英文原创作品 st.video。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。