user14210589
user14210589

Reputation:

How To Make a URL for a Video in Flask that Works with HTML?

I have a flask server that has a video file in it. How do I make it so users can watch the video using the HTML <video> tag? In the server, I have send_file:

@app.route("/movie")
def movie():
    return send_file("Images/i0.mov")

Then, in HTML I have:

<video width="90" height="90" controls>
  <source src="/movie" type="video/quicktime">
  Uh oh! Your browser doesn't support the <code>video</code> tag.
</video>

However, no video plays and I don't get the Uh oh! message. What am I doing wrong?

This is what I get:

<html>

<video width="90" height="90" controls>
  <source src="/movie" type="video/quicktime">
  Uh oh! Your browser doesn't support the <code>video</code> tag.
</video>
<br><br>
It just doesn't load!
</html>

Upvotes: 1

Views: 2578

Answers (1)

NavaneethaKrishnan
NavaneethaKrishnan

Reputation: 1318

Use send_file to download a file from the flask. I have a similar case, where I passed the video file name as a variable.

Add url_for and pass the file in your HTML file

<video width="800" height="450" controls>
  <source src="{{url_for('static', filename=file)}}" type="video/mp4">
</video>

and the backend,

@app.route('/video/<file>')
def video(file):
    return render_template('stream.html',file=file)

Upvotes: 3

Related Questions