Search code examples
pythonsubprocessvlcpopen

Error when calling cvlc through Popen in Python


I'm trying to pipe h264 to vlc in python. I'm having trouble opening the cvlc program while calling it in Popen. This is the code.

    self.vlc = subprocess.Popen([
    "cvlc", "-vvv", "stream:///dev/stdin", "--sout \'#rtp{sdp=rtsp://:8554/}\' :demux=h264"
    ], stdin=subprocess.PIPE)

This is the vlc error

vlc: unknown option or missing mandatory argument `--sout '#rtp{sdp=rtsp://:8554/}' :demux=h264'

I've been trying to figure this out for hours with different types of string formatting.


Solution

  • Question: I'm having trouble opening the cvlc program while calling it in Popen.

    Use shlex.quote(... to get a shell-escaped version of your Parameters.

    Python 3.6 Documentation:shlex.quote

    shlex.quote(s)
    Return a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line, for cases where you cannot use a list