I'm building a simple Dash app, including an html.Video() component. The issue is that local video files aren't playing (videos hosted online are working fine).
import dash
from dash.dependencies import Input, Output
import os
app = dash.Dash(__name__)
app.layout = html.Video(src="/static/test.mp4", controls=True)
@app.server.route('/static/<path:path>')
def serve_static(path):
root_dir = os.getcwd()
return flask.send_from_directory(os.path.join(root_dir, 'static'), path)
if __name__ == '__main__':
app.run_server(debug=True)
Folder structure:
- app.py
- /static
- test.mp4
I use OpenCV to create the .mp4 files:
def crop_video(vid_file, start_frame, end_frame, fps=30.0):
vid_name = f"/static/test.mp4"
cap = cv2.VideoCapture(vid_file)
ret, frame = cap.read()
h, w, _ = frame.shape
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
writer = cv2.VideoWriter(vid_name, fourcc, fps, (w, h))
f = 0
while ret:
f += 1
if start_frame <= f and f <= end_frame:
writer.write(frame)
ret, frame = cap.read()
writer.release()
cap.release()
return vid_name
I've tried the solutions from here, here, here, and here, without any luck