我已经在dropzone的帮助下创建了一个flask应用程序,该应用程序将视频文件作为输入,并在单击“上传”按钮时将视频文件添加/保存到我的文件夹中。 我想运行另一个烧瓶应用程序(或说一个.py文件),只要按下上传按钮,并在同一页面本身或下一页上显示此视频文件(我之前选择的那个视频文件)。 我是python和flask的新手,将需要您的帮助。请尽早回复。 这是我的app.py文件
import os
from flask import Flask, render_template, request
from flask_dropzone import Dropzone
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config.update(
UPLOADED_PATH=os.path.join(basedir, 'uploads'),
# Flask-Dropzone config:
DROPZONE_ALLOWED_FILE_TYPE='video',
DROPZONE_MAX_FILE_SIZE=1024*1024*1024,
DROPZONE_MAX_FILES=20,
DROPZONE_UPLOAD_ON_CLICK=True
)
dropzone = Dropzone(app)
@app.route('/', methods=['POST', 'GET'])
def upload():
if request.method == 'POST':
for key, f in request.files.items():
if key.startswith('file'):
f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename))
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
Here is index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flask-Dropzone Demo</title>
{{ dropzone.load_css() }}
{{ dropzone.style('border: 2px dashed #0087F7; margin: 10px 0 10px; min-height: 400px;') }}
</head>
<body>
{{ dropzone.create('/') }}
<button id="upload">Upload</button>
{{ dropzone.load_js() }}
{{ dropzone.config() }}
</body>
</html>
这是main.py文件(另一个flask应用程序文件),我希望在同一页面或下一页上显示该文件。
from flask import Flask, render_template, Response
from camera import VideoCamera
import subprocess
import os
app = Flask(__name__)
from yolo_video1 import videoname
@app.route('/')
def index():
return render_template('index.html')
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
videoname("C:/Users/320/Desktop/video-streaming/input_videos/airport.mp4", "C:/Users/320/Desktop/video-streaming/output_videos/airport.avi")
@app.route('/video_feed')
def video_feed():
return Response(gen(VideoCamera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
the index.html file for main.py is here
<html>
<head>
<title>Video Streaming Demonstration</title>
</head>
<body>
<h1>Video Streaming Demonstration</h1>
<img id="bg" src="{{ url_for('video_feed') }}">
</body>
</html>