【问题标题】:why I can't show my converted video in web site?为什么我不能在网站上显示我转换的视频?
【发布时间】: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


    【解决方案1】:

    您正在使用Django's default uploaded files handling。 Django 使用MEDIA_ROOTMEDIA_URL 设置在本地存储文件。 On PythonAnywhere 你必须设置从MEDIA_URLMEDIA_ROOT 的静态文件映射。您在 settings.py 中设置这些常量,但您还需要在 PythonAnywhere 的“静态文件”部分的“Web”配置页面中配置映射。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2013-02-25
      • 2013-03-05
      • 1970-01-01
      • 2023-01-16
      相关资源
      最近更新 更多