从django视图脚本运行linux命令

时间:2017-02-03 08:00:13

标签: python django bash pythonanywhere avconv

我尝试将avconv用于我的web-app(在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' 没有抛出错误,但我在文件夹中的任何地方都找不到输出文件?

有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

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

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