ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Topics
    2. Alexis
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 3
    • Groups 0

    Alexis

    @Alexis

    3
    Reputation
    509
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Alexis Unfollow Follow

    Best posts made by Alexis

    • RE: Calling Complex System Commands from Python

      @Alexis said:

      cmdstr2 = """ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/., (.) fp.*/\1/p'"""

      Okay, I forgot to escape one of the backslashes in the sed string. The proper python-fu is:

      cmdstr3 = "\"\"ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/.*, \(.*\) fp.*/\\1/p'\"\""
      

      ...which properly returns the FPS of the movie file.

      Thanks so much for getting me started on this! I'm converting my bash scripts to python and learning the language in the process!

      posted in Developer Discussion
      A
      Alexis
    • RE: Calling Complex System Commands from Python

      [My editor changed the simple quotes into “smart” quotes for the posting, sorry.]

      Anyway, the code below works to obtain the movie resolution. It returns the string “640x480” for the moviespec var I’m using:

      cmdstr1 = "\"\"ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/.*, \(.*\) \[.*/\\1/p'\"\""
      stdoutstr1 = subprocess.check_output(
          cmdstr1,
          shell=True, universal_newlines=True)
      

      However, in translating the following bash line to obtain the frames/second:

      fps=$(/opt/local/bin/ffmpeg -i $moviespec 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p")
      

      The above line, translated into pythonese, returns null:

      cmdstr2 = "\"\"ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/.*, \(.*\) fp.*/\1/p'\"\""
      stdoutstr2 = subprocess.check_output(
          cmdstr2,
          shell=True, universal_newlines=True)
      

      I can’t spot what my error might be here.

      posted in Developer Discussion
      A
      Alexis

    Latest posts made by Alexis

    • RE: Calling Complex System Commands from Python

      @Alexis said:

      cmdstr2 = """ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/., (.) fp.*/\1/p'"""

      Okay, I forgot to escape one of the backslashes in the sed string. The proper python-fu is:

      cmdstr3 = "\"\"ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/.*, \(.*\) fp.*/\\1/p'\"\""
      

      ...which properly returns the FPS of the movie file.

      Thanks so much for getting me started on this! I'm converting my bash scripts to python and learning the language in the process!

      posted in Developer Discussion
      A
      Alexis
    • RE: Calling Complex System Commands from Python

      [My editor changed the simple quotes into “smart” quotes for the posting, sorry.]

      Anyway, the code below works to obtain the movie resolution. It returns the string “640x480” for the moviespec var I’m using:

      cmdstr1 = "\"\"ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/.*, \(.*\) \[.*/\\1/p'\"\""
      stdoutstr1 = subprocess.check_output(
          cmdstr1,
          shell=True, universal_newlines=True)
      

      However, in translating the following bash line to obtain the frames/second:

      fps=$(/opt/local/bin/ffmpeg -i $moviespec 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p")
      

      The above line, translated into pythonese, returns null:

      cmdstr2 = "\"\"ffmpeg -i " + moviespec + " 2>&1 | sed -n 's/.*, \(.*\) fp.*/\1/p'\"\""
      stdoutstr2 = subprocess.check_output(
          cmdstr2,
          shell=True, universal_newlines=True)
      

      I can’t spot what my error might be here.

      posted in Developer Discussion
      A
      Alexis
    • RE: Calling Complex System Commands from Python

      Great examples! How about something more real-world?

      I use the following bash command to obtain the resolution of a movie file:

      /opt/local/bin/ffmpeg -i TEST.mp4 2>&1 | sed -n "s/.*, \(.*\) \[.*/\1/p"
      

      ...and it returns a string like “640x480” for the movie’s resolution. Great!

      Now, trying to do this in Python 3:

      cmd = ‘/opt/local/bin/ffmpeg -i TEST.mp4 2>&1 | sed -n "s/.*, \(.*\) \[.*/\1/p"’
      ret = subprocess.getoutput(cmd)
      

      Result: null string

      subprocess.call(cmd, shell=True)
      

      Result: null string

      stdoutstr = subprocess.getoutput(cmd)
      print("stdoutstr:” + stdoutstr.split()[0])
      

      Result: null string

      Surely, there MUST be a way!

      posted in Developer Discussion
      A
      Alexis