0

Hello I can't get my script to run it is meant to steam my screen live over HTTP but it comes up with an error I can't seem to fix.

#!/bin/python
import subprocess
import threading

try:
    subprocess.Popen("rm out.mpg")
except OSError:
    pass

subprocess.Popen("ffmpeg -f x11grab -framerate 60 -video_size 1366x768 -i :0.0 out.mpg")
subprocess.Popen("python -m SimpleHTTPServer 8000 out.mpg")

The error is

Traceback (most recent call last):
  File "Streaming.py", line 11, in <module>
    subprocess.Popen("ffmpeg -f x11grab -framerate 60 -video_size 1366x768 -i :0.0 out.mpg")
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Oliver Strong
  • 415
  • 1
  • 7
  • 15

1 Answers1

5

The command arguments for Popen should be a sequence of strings. Try this:

import subprocess
subprocess.Popen(["ffmpeg", "-f", "x11grab", 
                  "-framerate", "60", "-video_size",
                  "1366x768", "-i", ":0.0", "out.mpg"])

Note that the first string that contains the name of the command should not contain any spaces! If you would use "ffmpeg " (note the space at the end) instead of "ffmpeg" it would fail again with a "no such file or directory" error because there is no command with the name "ffmpeg "!

You could also use shlex:

import subprocess
import shlex

cmd = "ffmpeg -f x11grab -framerate 60 -video_size 1366x768 -i :0.0 out.mpg"
subprocess.Popen(shlex.split(cmd))
Roland Smith
  • 42,427
  • 3
  • 64
  • 94