【问题标题】:Subprocess.call() not running on my django view , Why the view code runs perfectly in the manage.py shellSubprocess.call() 没有在我的 django 视图上运行,为什么视图代码在 manage.py shell 中完美运行
【发布时间】:2013-10-04 19:00:58
【问题描述】:

我正在尝试在服务器上使用ffmpeg 进行视频裁剪,一旦用户上传的视频文件被保存,然后我对其运行ffmpeg 命令来裁剪视频并进一步将上传的文件替换为裁剪后的文件文件使用mv 命令。尽管此代码在manage.py 控制台中逐步运行时运行良好,但在测试时上传的文件没有被裁剪。

new_video.save()
url=new_video.video_file.url
real_path = "/home/chanceapp/webapps/chanceapp/chanceapp"+url
fake_crop_path = "/home/chanceapp/webapps/chanceapp/chanceapp/fake1"+url
rotate_crop = "ffmpeg -i %s -vf "%(real_path)+r'"transpose=2 , crop=480:480:0:0" '+\
    "-vcodec libx264 -strict -2 -crf 18 %s"%(fake_crop_path)
move_cropped = "mv"+" %s"%(fake_crop_path)+" %s"%(real_path)
commands = [rotate_crop,move_cropped]
for command in commands:
    subprocess.call(command,shell=True ) 

谢谢。

【问题讨论】:

  • 这不是你的问题,但请注意他的代码极易受到 shell 注入的攻击。您应该切勿shell=True 与来自互联网的未经处理的输入一起使用。
  • 你为什么还要使用shell=True

标签: python django subprocess


【解决方案1】:

你应该多调试一下:

from subprocess import Popen, PIPE

for command in commands:
    result = Popen(command, shell=True, stdout=PIPE).stdout.read()
    if len(result) > 0:
        raise Exception(result)

它会引发任何异常吗?

【讨论】:

    猜你喜欢
    • 2021-09-20
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 2012-03-23
    相关资源
    最近更新 更多