简体   繁体   English

为什么将视频上传到 azure blob 存储这么慢? [江戈]

[英]Why is uploading a video to azure blob storage this slow? [DJANGO]

I have a problem when uploading a video to the Azure blob storage with Django.使用 Django 将视频上传到 Azure blob 存储时遇到问题。 I am not sure if it has something to do with the Django framework being slow or my code.我不确定它是否与 Django 框架缓慢或我的代码有关。

btw, it is a project from me and my friend and he did the most work.顺便说一句,这是我和我朋友的一个项目,他做了最多的工作。 So it's possible that I don't know everything.所以有可能我不知道一切。 :) :)

When uploading a video of like 1GB it will take around 2/3 minutes.上传 1GB 大小的视频时,大约需要 2/3 分钟。

What I have looked into but not implemented yet:我已经研究但尚未实施的内容:

  1. AZCopy复制
  2. multithreading多线程

video model:视频模型:

    def create_file_path_video(instance, name):
    return os.path.join('sources', str(instance.pk), name)


    class Video(models.Model):
        video = models.FileField(upload_to=create_file_path_video, validators=[validate_video_file_extension], null=True)
        name = models.CharField(max_length=255, null=True)
        storage_name = models.CharField(max_length=255, null=True)
        size = models.BigIntegerField(null=True)
        fps = models.FloatField(null=True)
        frames_count = models.FloatField(null=True)
        duration = models.FloatField(null=True)
        type = models.CharField(max_length=10, null=True)
        uploaded_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=False)
        uploaded_at = models.DateTimeField(default=datetime.now, null=True, blank=True)
        deleted_at = models.DateTimeField(null=True, blank=True)

    def __duration(self):
        return int(self.frames_count/self.fps)

Form:形式:

class UploadVideoForm(forms.ModelForm):
    class Meta:
        model = Video
        fields = ['video']
        widgets = {
            'name': forms.HiddenInput(),
            'uploaded_by': forms.HiddenInput(),
            'uploaded_at': forms.HiddenInput(),
            'type': forms.HiddenInput(),
            'size': forms.HiddenInput()
        }

View:看法:

def video_create_view(request):
    context = {}
    form = UploadVideoForm(request.POST or None, request.FILES or None)

    if request.user.is_superuser or request.user.groups.filter(name="Editor").exists():
        if request.method == 'POST':
            form = UploadVideoForm(request.POST, request.FILES)
            video_obj = Video.objects.create()
            if form.is_valid():
                name = request.FILES['video'].name.split('.')[0]
                date_string = datetime.datetime.now().strftime("%Y-%m-%d")
                video_obj.name = name
                video_obj.storage_name = date_string+"_"+name
                video_obj.size = request.FILES['video'].size
                video_obj.uploaded_by = request.user
                video_obj.type = request.FILES['video'].name.split('.')[1]
                video_obj.video = request.FILES['video']
                video_obj.save()
                video_path = get_file_path(video_obj.video)
                video = cv2.VideoCapture(video_path)
                # Find OpenCV version
                (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
                if int(major_ver) < 3:
                    
                    fps = float(video.get(cv2.cv.CV_CAP_PROP_FPS))
                    frames_count = float(video.get(cv2.CAP_PROP_FRAME_COUNT))
                    video_obj.fps = fps
                    video_obj.frames_count = frames_count
                    video_obj.duration = frames_count/fps

                else:
                    fps = video.get(cv2.CAP_PROP_FPS)
                    frames_count = video.get(cv2.CAP_PROP_FRAME_COUNT)
                    video_obj.fps = fps
                    video_obj.frames_count = frames_count
                    video_obj.duration = frames_count/fps
                video_obj.save()
                video.release()
                messages.success(request, "Video uploaded!")
            return redirect('video:video-list')
    context['form'] = form
    return render(request, 'video/upload_form.html', context)

I have debugged and I noticed that the video_obj.save() is almost taking all the time it needs.我已经调试过,我注意到video_obj.save()几乎占用了它需要的所有时间。

Can someone help me with this problem?有人可以帮我解决这个问题吗? It would be very nice!那就太好了! <3 <3

You can upload your media asset to Azure Blob Storage with Shared Access Signatures .可以使用Shared Access Signatures将媒体资产上传到Azure Blob Storage

Solutions to speed up upload and download by SAS Token SAS Token加速上传下载的解决方案

For more details, pls check below blogs which is .Net .有关更多详细信息,请查看以下.Net博客。 You can search about python language.您可以搜索有关python语言的信息。

1. Uploading to Azure Blob Storage with Shared Access Signatures 1. 使用共享访问签名上传到 Azure Blob 存储

2. How to Access an Blob Container Using Shared Access Signatures 2. 如何使用共享访问签名访问 Blob 容器

Python: Python:

1. How to upload files to azure blob storage? 1.如何上传文件到azure blob存储?

2. Azure Storage - Upload File - Python (Sample Code) 2. Azure 存储 - 上传文件 - Python (示例代码)

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

相关问题 将数组作为 .jpg 图像上传到 Azure blob 存储 - Uploading array as a .jpg image to Azure blob storage 使用 python 将文件上传到 azure blob 存储 - Uploading file to azure blob storage using python Django未将图像文件上传到Azure存储容器 - Django not uploading image files to Azure storage container 使用python上载csv文件以使Blob存储蔚蓝 - Uploading csv file using python to azure blob storage Microsoft Azure 计时器功能未将文件上传到 blob 存储 - Microsoft Azure Timer Function not uploading files to blob storage 上传到 Azure Blob 存储时自动设置内容类型 - Set content type authomatically when uploading to Azure Blob Storage 在 Azure blob 存储中上传文件时出现 InvalidAuthenticationInfo 错误 - InvalidAuthenticationInfo error while uploading dcument in Azure blob storage 上传到 Azure Blob 存储时设置内容类型 - Set content type when uploading to Azure Blob Storage 使用 Databricks 将文件从 Azure Blob 存储上传到 SFTP 位置? - Uploading files from Azure Blob Storage to SFTP location using Databricks? Azure存储Python SDK:将文件上传到Azure Blob存储而不将其写在磁盘上 - Azure Storage Python SDK : Uploading file to Azure blob storage without writting it on my disk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM