简体   繁体   中英

Run linux command from django view script

I try to use avconv for my web-app (Django on pythonanywhere). I have to extract a thumbnail from a video file. Using the bash console, I can run:

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

This works fine. When I want to use this command by script (view.py) I tried:

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

inputfile is the path to my video and outputile is the path to my video + '.png' There are no errors thrown, but I can not find the output file anywhere in my folders?

Any ideas?

Thanks!

You could try with the subprocess library:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM