【发布时间】:2020-10-08 03:37:35
【问题描述】:
我使用 django 制作了我的网络应用程序,它在本地服务器上运行良好。 我上传了慢动作视频,我可以在网上下载转换后的视频 但是,当我使用 AWS 或 pythonanywhere 发布我的网站时,我会偷偷上传视频。我只能显示我上传的原始视频,没有任何结果。你能帮帮我吗?
from django.shortcuts import render, redirect
from django.core.files.storage import FileSystemStorage
import cv2
def upload(request):
context = {}
if request.method == 'POST':
uploaded_file = request.FILES['videoname']
fs = FileSystemStorage()
name = fs.save(uploaded_file.name, uploaded_file)
context['url'] = fs.url(name)
tujuan = context['url'][1:]
modfile = tujuan + '.mp4'
context['modurl'] = context['url']+'.mp4'
cap = cv2.VideoCapture(tujuan)
# 재생할 파일의 넓이와 높이
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
print("재생할 파일 넓이, 높이 : %d, %d" % (width, height))
# fourcc = cv2.VideoWriter_fourcc(*'mp4v')
fourcc = 0x31637661
out = cv2.VideoWriter(modfile, fourcc, 30.0, (int(height), int(width)))
ret, pos_frame = cap.read()
while (cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break;
result = cv2.addWeighted(pos_frame, 0.5, frame, 0.5, 0)
result = cv2.transpose(result)
result = cv2.flip(result, 1)
out.write(result)
pos_frame = frame
cap.release()
out.release()
return render(request,'index.html', context)
【问题讨论】:
标签: python django amazon-web-services opencv pythonanywhere