Search code examples
pythondjangobashpythonanywhereavconv

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!


Solution

  • 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