【问题标题】:handling subprocess file output处理子进程文件输出
【发布时间】:2019-06-08 17:08:52
【问题描述】:

我正在开发一个项目,在该项目中,用户有时会上传视频,而在后端我必须为该视频生成缩略图。为此,我更喜欢 ffmpeg,并且系统处于 django 环境中。 这是我的视图函数

def upload(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            filename = str(request.FILES['docfile'].name)
            newdoc.save()
            op = subprocess.call(['ffmpeg', '-i',"media/private/"+up, '-ss', '00:00:03.000', '-vframes', '1', 'abc.jpg']) // Generates thumbnail
            newdoc.thumbnail = op
            newdoc.save()
            return HttpResponseRedirect(reverse('list'))
    else:
        form = DocumentForm()

文档有缩略图字段。我知道 subprocess.call() 返回的返回码不是任何对象,所以使用 op 变量是没用的。所以我的查询是如何在模型中保存生成的缩略图。

【问题讨论】:

    标签: django ffmpeg django-views subprocess


    【解决方案1】:

    FieldFiledjango documentation 中所述,您可以从保存文件的路径打开文件并将其包装到File 对象中。

    另一个考虑是不要调用子进程,而是使用 python 库。还有用于 ffmpeg 的 python 绑定,例如ffmpeg-python.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-20
      • 1970-01-01
      相关资源
      最近更新 更多