Black Lives Matter. Please consider donating to Black Girls Code today.

Dash video player to play local videos


I am making an app and I need to play locally stored .mp4 videos in the app. Is this possible with dash ? Is there any recipe or example to do this.


You could use technic based on openCV provided here by replacing using cv2.VideoCapture with your video filename as arguement

Try this. You can put the video in your ./static/ directory (or where-ever, just specify the correct path).

import os
import dash
import dash_html_components as html

from flask import Flask, Response

server = Flask(__name__)
app = dash.Dash(__name__, server=server)

app.layout = html.Video(src='/static/',controls=True)  # or .mp4, or .avi ..etc

def serve_static(path):
    root_dir = os.getcwd()
    return flask.send_from_directory(os.path.join(root_dir, 'static'), path)