如何自动播放在烧瓶应用中上传的mp4

问题描述 投票:0回答:1

我有一个烧瓶应用程序,带有用于视频(mp4)的上传按钮,并且我试图弄清楚如何在上传后使视频在屏幕上播放。当前,它会打开通用的灰色视频屏幕,但没有视频播放。我在下面包含了我的app.py和index.html文件的一部分。在视频继续播放的同时,我还具有一个可以与之交互的预测按钮。

我将不胜感激如何实现这一目标的建议。

@app.route('/', methods=['GET'])
def index():
    # Main page
    return render_template('index.html')


@app.route('/predict', methods=['GET', 'POST'])
def upload():
    if request.method == 'GET':
        return render_template('index.html')

    if request.method == 'POST':
        # Get the file from post request
        f = request.files['file']
        # Save the file to ./uploads
        basepath = os.path.dirname(__file__)
        file_path = os.path.join(
            basepath, 'static', secure_filename(f.filename))
        f.save(file_path)

        result = model_predict(file_path, model)

        return jsonify(result)

    return None



if __name__ == '__main__':
    # app.run(port=5002, debug=True)

    # Serve the app with gevent
    http_server = WSGIServer(('', 5000), app)
    http_server.serve_forever()
`

<div>
    
    <h4>
<center></center>
</h4>



    <br>
    </br>
    <center>
    <form id="upload-file" method="post" enctype="multipart/form-data">
        <center>
        <label for="imageUpload" class="upload-label">
            Upload (mp4)
        </label>
        </center>
        <input type="file" name="file" id="imageUpload" accept=".mp4">
    </form>
</center>
    

    <div class="image-section" style="display:none;">
        <div class="img-preview">
            <div id="imagePreview">
            <html>
  <head>

  </head>
  <center>
  <body>
  <center>
<video controls width="500" style="center">

    <source src="{{url_for('static', filename=f)}}" type="video/mp4" autoplay>
    Sorry, your browser doesn't support embedded videos.
</video>
</center>
  </body>

</html>

<input type="file" name="file[]" class="file_multi_video" accept="video/*">
            </div>
        </div>
        <div>
            <button type="button" class="btn btn-primary btn-lg " id="btn-predict">Identify</button>
        </div>
    </div>

    <div class="loader" style="display:none;"></div>

    <h3 id="result">
        <span> </span>
    </h3>
</div>
</center>
python html video flask mp4
1个回答
0
投票

您可以使用MJPEG在HTML中执行此操作,您可以在https://stackoverflow.com/a/61452182/10353754上查看答案以获得帮助。您应该只提取帧,并将其编码为JPEG格式后发送到标签。

© www.soinside.com 2019 - 2024. All rights reserved.