-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Play local videos #3
Comments
I also was very confused, because the landing page here suggests that "Local Files" are supported, but i could not get it working. import streamlit as st
from streamlit_player import st_player
# official video player works:
st.video('video.mp4')
# this does not work:
st_player('video.mp4') |
Seting up a local server and using it as st_player("http://localhost:8520/archery.mp4",playing=True,playback_rate=1,progress_interval=1000, controls=True, loop=True) works. |
@ajaichemmanam |
You can provide custom The following sample reads your video locally, encodes it in base64, and builds a valid data URI with the encoded data that can be played by ReactPlayer. from base64 import b64encode
from pathlib import Path
from streamlit_player import st_player
def local_video(path, mime="video/mp4"):
data = b64encode(Path(path).read_bytes()).decode()
return [{"type": mime, "src": f"data:{mime};base64,{data}"}]
st_player(local_video("path/to/video.mp4")) |
Do you recommend any media server to do this job locally? |
This works, which is the good news...but it is very slow with large media files. Need to figure a way to stream the file rather than load it the whole way. |
Using flask to serve the local files works for larger files but it is still not perfect. import os
from flask import Flask, send_file, make_response
APP = Flask(__name__)
MEDIA_PATH = 'path_to_media_folder'
@APP.route('/<path:vid_name>')
def serve_video(vid_name):
print(vid_name)
vid_path = os.path.join(MEDIA_PATH, vid_name)
resp = make_response(send_file(vid_path, 'video/mp4'))
resp.headers['Content-Disposition'] = 'inline'
return resp
if __name__ == '__main__':
APP.run() In streamlit: |
While st.video works for local videos, it is very barebones in terms of features such as getting playback time and video parameters. Adding local video support for this would be great to utilize these features.
The text was updated successfully, but these errors were encountered: