1

I am trying to run an ffmpeg command on Windows 7 (python 2.7) which runs on command line just fine, but the env of my Popen is not working. Here is the working command line:

SET FFREPORT=level=48:file=C\:\\temp\\TESTFFMPEGOUTPUT.txt && C:\Temp\ffmpeg\ffmpeg.exe -i “I:\somefolder\testInput.mov" "I:\somefolder\testOutput.mov"

And here is my current python code:

ffreport = "level=48:file={}".format(self.logFilePath) + " && "
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
self.process1 = Popen(command, startupinfo=startupinfo, shell=False, env={'SET FFREPORT':ffreport})

This results in windows reporting "ffmpeg has stopped working". Not sure how to fix.

speedyrazor
  • 3,127
  • 7
  • 33
  • 51

2 Answers2

0
command = r"C:\Temp\ffmpeg\ffmpeg.exe -i I:\somefolder\testInput.mov I:\somefolder\testOutput.mov"

self.process1 = Popen(
        shlex.split(command), shell=False, 
        env=dict(FFREPORT="level=48:file=C\:\\temp\\TESTFFMPEGOUTPUT.txt"))
agaust
  • 97
  • 3
  • 19
  • This gives the error - WindowsError: [Error 2] The system cannot find the file specified. I still would like to find a way to use the Popen command as is and fix the env. – speedyrazor Jan 20 '15 at 15:51
  • 1
    Windows `CreateProcess` takes a command-line string, so there's no point to creating a list with `shlex.split(command)`. Modify a copy of the current environment: `environ = os.environ.copy();` `environ['FFREPORT'] = 'level=48:file={}'.format(self.logFilePath);` `self.process1 = Popen(command, startupinfo=startupinfo, env=environ)`. It defaults to `shell=False`. – Eryk Sun Jan 21 '15 at 11:24
  • Thanks eryksun, this works great, fixed. If you could do this as an answer I will mark it up as the answer. – speedyrazor Jan 21 '15 at 16:22
  • I now have the same sort of issue once I added in another pre command: http://stackoverflow.com/questions/34879485/popen-set-env-parameter – speedyrazor Jan 19 '16 at 15:05
-1

How about this?
using os.startfile(path[, operation])
https://docs.python.org/3/library/os.html#os.startfile

agaust
  • 97
  • 3
  • 19