gpt4 book ai didi

python - 从 django 查看脚本运行 linux 命令

转载 作者:行者123 更新时间:2023-12-01 03:20:00 25 4
gpt4 key购买 nike

我尝试在我的网络应用程序中使用avconv(Django on pythonanywhere)。我必须从视频文件中提取缩略图。使用 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' 的路径没有抛出任何错误,但我在文件夹中的任何位置都找不到输出文件?

有什么想法吗?

谢谢!

最佳答案

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

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

关于python - 从 django 查看脚本运行 linux 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42019413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com