1.环境设置
一定要勾选那两行许可才能调用电脑里的包
2.把视频按帧拆分成图片
from flask import Flask, render_template
import os
import cv2
app = Flask(__name__)
def genframe():
v_path='static/video.mp4'
image_save='static/pic'
if not(os.path.exists(image_save)):
os.mkdir(image_save)
cap=cv2.VideoCapture(v_path)
fc=cap.get(cv2.CAP_PROP_frame_COUNT)
for i in range(int(fc)):
_,img=cap.read()
cv2.imwrite('static/pic/image{}.jpg'.format(i),img)
@app.route('/')
def index():
#return "Hi,Flask!"
genframe()
return render_template('index.html')
if "__main__"==__name__:
app.run(port="5008")
在这个pythonProject里面建立文件夹templates(固定名称不能改),然后在里面建立一个html文件名叫index.html。
index.html文件的内容是:
Flask分镜
111
(两个body中间是我可以自己添加的内容,会出现在最后的网页里,其他部分都是自动生成的)
运行以后就能保存到static/pic文件夹
3.把视频和截图一起放在网页上
from flask import Flask, render_template
import os
import cv2
app = Flask(__name__)
def genframe():
v_path='static/video.mp4'
image_save='static/pic'
if not(os.path.exists(image_save)):
os.mkdir(image_save)
cap=cv2.VideoCapture(v_path)
fc=cap.get(cv2.CAP_PROP_frame_COUNT)
for i in range(int(fc)):
_,img=cap.read()
cv2.imwrite('static/pic/image{}.jpg'.format(i),img)
@app.route('/')
def index():
#return "Hi,Flask!"
#genframe()
pic = 'static/pic/image'
framecount = 254
return render_template('index.html', pic1=pic, framecount=framecount)
if "__main__"==__name__:
app.run(port="5008")
然后把index.html内容更改为
Flask分镜
视频分镜
帧数:{{framecount}}
{% for i in range(framecount) %}
{pic1}}{{i}}.jpg" />
{% endfor %}
最后出来的效果就是



