1.py 读取图片视频流
from flask import Flask
from flask import render_template
import os
images_path_list=[‘D:\imgs\’+filename for filename in os.listdir(‘D:\imgs\’) if filename.endswith(‘.jpg’)]
print(images_path_list)
def return_img_stream(img_local_path):
import base64
with open(img_local_path,'rb') as f:
img_stream=f.read()
img_stream = base64.b64encode(img_stream).decode()
#print(img_stream)
#print(type(img_stream))
return img_stream
page_list=range(len(images_path_list)//10+1)
app = Flask(name)
@app.route(‘/’)
def hello_world():
img_streams=[]
for img_path in images_path_list:
#img_path=‘D:\imgs\tec.jpg’
img_stream = return_img_stream(img_path)
img_streams.append(img_stream)
return render_template(‘index.html’,img_streams=img_streams,page_list=page_list)
@app.route(‘/movie’)
def movie1():
img_path=‘D:\imgs\m1.mp4’
img_stream = return_img_stream(img_path)
return render_template(‘movie.html’,img_stream=img_stream)
@app.route(‘/images/int:page’)
def show_images(page):
print(page)
img_streams = []
# page=0
for img_path in images_path_list[page10:page10+10]:
# img_path=‘D:\imgs\tec.jpg’
img_stream = return_img_stream(img_path)
img_streams.append(img_stream)
return render_template(‘images.html’, img_streams=img_streams, page_list=page_list)
if name == ‘main’:
app.run(host=(0,0,0,0),debug=True)
2.前端显示页面
index.html
movie.html
关键部分在于: