【问题标题】:Run linux command from django view script从 django 视图脚本运行 linux 命令
【发布时间】:2017-06-20 12:56:54
【问题描述】:

我尝试将 avconv 用于我的网络应用程序(pythonanywhere 上的 Django)。我必须从视频文件中提取缩略图。 使用 bash 控制台,我可以运行:

avconv -ss 00:01:00 -i myapp/myapp/media/inputvide.mp4 -vsync 1 -t 0.01 myapp/myapp/media/videothumb.png

这很好用。 当我想通过脚本(view.py)使用这个命令时,我试过:

cmd = 'avconv -ss 00:01:00 -i '+inputfile+' -vsync 1 -t 0.01 '+outputfile
os.system(cmd)

inputfile 是我的视频的路径,而 outputile 是我的视频的路径 + '.png' 没有抛出任何错误,但我在文件夹中的任何位置都找不到输出文件?

有什么想法吗?

谢谢!

【问题讨论】:

  • 尝试使用绝对路径?例如/home/yourusername/foldername/filename.thing,不只是filename.thing...
  • 变量输入文件包含绝对路径!

标签: python django bash pythonanywhere avconv


【解决方案1】:

您可以尝试使用子流程库:

from subprocess import call

success = call('avconv -ss 00:01:00 -i '+inputfile+' -vsync 1 -t 0.01'+outputfile, shell=True)

if success != 0:
    //The command has failed

【讨论】:

    猜你喜欢
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 2011-09-28
    • 2016-02-20
    • 2019-07-04
    • 1970-01-01
    相关资源
    最近更新 更多