Running cmd in python

后端 未结 4 1941
南方客
南方客 2020-12-28 22:12

Atm I have this as my code, the first line seems to work well but the 2nd gives errrors.

os.chdir(\'C://Users/Alex/Dropbox/code stuff/test\')
subprocess.call(         


        
相关标签:
4条回答
  • 2020-12-28 22:36

    I know this question is old, but now there is an excellent wrapper for ffmpeg in Python : ffmpeg-python. You will find it at https://github.com/kkroening/ffmpeg-python

    With it, the command could be achieved this way:

    import ffmpeg
    ffmpeg
        .input('test*.png', pattern_type='glob')
        .output('output.avi')
        .run()
    
    0 讨论(0)
  • 2020-12-28 22:39

    What version of Python are you using? getstatusoutput() is deprecated since version 2.6. In Python 3 you can use subprocess for the same effect.

    subprocess.getoutput('cd /Users/Alex/code/pics/')
    
    0 讨论(0)
  • 2020-12-28 22:51

    For the later generations looking for the answer, this worked. (You have to separate the command by the spaces.)

    import os
    import subprocess
    os.chdir('C://Users/Alex/')
    subprocess.call(['ffmpeg', '-i', 'picture%d0.png', 'output.avi'])
    subprocess.call(['ffmpeg', '-i', 'output.avi', '-t', '5', 'out.gif'])
    
    0 讨论(0)
  • 2020-12-28 22:53

    It is better to call subprocess.call in another way.

    The preferred way is:

    subprocess.call(['ffmpeg', '-i', 'test%d0.png', 'output.avi'])
    

    Alternatively:

    subprocess.call('ffmpeg -i test%d0.png output.avi', shell=True)
    

    You can find the reasons for this in the manual. I quote:

    args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

    0 讨论(0)
提交回复
热议问题