0

I'm trying to create a streaming capability on my site with flask. I'm sending my video in chunks, but although the video loads I can't change time.

So far I've made this route to stream the video

@app.route('/v/<filename>')
def v(filename):

    time = request.args.get('time', 0, type=int)
        
    def generate():        
        with open(os.path.join(VIDEO_FOLDER, filename), 'rb') as f:
            if time > 0:
                f.seek(time * 1024)
            data = f.read(1024)
            while data:
                yield data
                data = f.read(1024)
    return Response(generate(), mimetype='video/mp4')

I made a simple HTML page to get the video:

<video id="video" controls>
  <source id="source" src="/v/{{filename}}" type="video/mp4">

Your browser does not support the video tag.
</video>

So far the video is loading and playing fine but I can't go to a given time (let's say 8 minutes in). I've tried many things but nothing seems to work. Can anyone tell me how I can alter this code to make it so that if I click in the progress bar of the video element it skips to the right time?

Thank you in advance for your answers.

jello195
  • 111
  • 8

0 Answers0