简体   繁体   English

为什么我不能在网站上显示我转换后的视频?

[英]why I can't show my converted video in web site?

I made my web app using django and it works good in local server.我使用 django 制作了我的网络应用程序,它在本地服务器上运行良好。 I uploaded slowmotion video and I could download my converted video on web However, when I use AWS or pythonanywhere to release my website, I dosen's covert uploaded video.我上传了慢动作视频,我可以在网上下载我转换后的视频 但是,当我使用 AWS 或 pythonanywhere 发布我的网站时,我上传了秘密上传的视频。 I can only show my uploaded origin video and there is nothing result.我只能显示我上传的原始视频,没有任何结果。 can you help me?你能帮助我吗?

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)

You're using Django's default uploaded files handling .您正在使用Django 的默认上传文件处理. Django stores files locally, using the MEDIA_ROOT and MEDIA_URL settings. Django 使用MEDIA_ROOTMEDIA_URL设置在本地存储文件。 On PythonAnywhere you have to set static files mapping from MEDIA_URL to MEDIA_ROOT .在 PythonAnywhere 上,您必须设置从MEDIA_URLMEDIA_ROOT静态文件映射。 You set those constants in settings.py but you'll need to configure mappings in your "Web" configuration page at the "Static files" section on PythonAnywhere as well.您可以在settings.py设置这些常量,但您还需要在 PythonAnywhere 的“静态文件”部分的“Web”配置页面中配置映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM