1

I am adding a FFREPORT command on the front of an already working ffmpeg command in python 2.7 on OSX, this is to redirect the report log file, but am getting an error and can't figure out how to fix it.

Here is the command:

command = 'FFREPORT="level=48:file=/Users/myself/Desktop/TESTFFMPEGOUTPUT.txt" /Users/myself/Desktop/Python/ffmpeg/ffmpeg -i /Volumes/GRAID/TestInput.mov /Volumes/GRAID/TestOutput.mov'

self.process1 = Popen(shlex.split(command), shell=False)

This is giving me the error:

    raise child_exception
    OSError: [Errno 2] No such file or directory

UPDATE:

I have now changed it to incorperate the answer below, but am getting another issue. I need the path of the logfile as a variable, so am trying:

ffreportCommand = 'FFREPORT=level=48:file=' + self.logFilePath
self.process1 = Popen(shlex.split(command), shell=False, env=dict(ffreportCommand))

But am getting the below error:

self.process1 = Popen(shlex.split(command), shell=False, env=dict(ffreportCommand))
ValueError: dictionary update sequence element #0 has length 1; 2 is required

UPDATE: Fixed with:

ffreportCommand = "level=48:file=" + self.logFilePath
self.process1 = Popen(shlex.split(command), shell=False, env=dict(FFREPORT='%s' % ffreportCommand))
speedyrazor
  • 3,127
  • 7
  • 33
  • 51

1 Answers1

2

FFREPORT is an environment variable. Therefore, set it using the env parameter when calling Popen:

command = '/Users/myself/Desktop/Python/ffmpeg/ffmpeg -i /Volumes/GRAID/TestInput.mov /Volumes/GRAID/TestOutput.mov'

self.process1 = Popen(
    shlex.split(command), shell=False, 
    env=dict(FFREPORT="level=48:file=/Users/myself/Desktop/TESTFFMPEGOUTPUT.txt"))

If you wish to build the dict based on a variable you could use

ffreport = "level=48:file={}".format(self.logFilePath)
self.process1 = Popen(shlex.split(command), shell=False, 
                      env=dict(FFREPORT=ffreport))

By the way, dict(A=val) is equivalent to {'A':val}. So another alternative would be

self.process1 = Popen(shlex.split(command), shell=False, 
                      env={'FFREPORT':ffreport})
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Thanks ubuntu, but I have another issue when using that method, I put an UPDATE in the above question. – speedyrazor Jan 19 '15 at 15:22
  • I now have the same sort of issue with windows: http://stackoverflow.com/questions/28048602/python-popen-env-ffmpeg-crash – speedyrazor Jan 20 '15 at 16:19