parameters: (source, destvideofile, video, audio1, audio2, aspectratio, profile)
docstring: Encodes an unknown video source file eg. AVI to MPEG2 video and AC3 audio, use mythffmpeg
docstring_summary: Encodes an unknown video source file eg. AVI to MPEG2 video and AC3 audio, use mythffmpeg
docstring_tokens: Encodes an unknown video source file eg . AVI to MPEG2 video and AC3 audio use mythffmpeg
function: def encodeVideoToMPEG2(source, destvideofile, video, audio1, audio2, aspectratio, profile):
      """Encodes an unknown video source file eg. AVI to MPEG2 video and AC3 audio, use mythffmpeg"""
  
      profileNode = findEncodingProfile(profile)
  
      passes = int(getText(profileNode.getElementsByTagName("passes")[0]))
  
      command = "mythffmpeg"
  
      if cpuCount > 1:
          command += " -threads %d" % cpuCount
  
      parameters = profileNode.getElementsByTagName("parameter")
  
      for param in parameters:
          name = param.attributes["name"].value
          value = param.attributes["value"].value
  
          # do some parameter substitution
          if value == "%inputfile":
              value = quoteCmdArg(source)
          if value == "%outputfile":
              value = quoteCmdArg(destvideofile)
          if value == "%aspect":
              value = aspectratio
  
          # only re-encode the audio if it is not already in AC3 format
          if audio1[AUDIO_CODEC] == "AC3":
              if name == "-acodec":
                  value = "copy"
              if name == "-ar" or name == "-b:a" or name == "-ac":
                  name = ""
                  value = ""
  
          if name != "":
              command += " " + name
  
          if value != "":
              command += " " + value
  
  
      #add second audio track if required
      if audio2[AUDIO_ID] != -1:
          for param in parameters:
              name = param.attributes["name"].value
              value = param.attributes["value"].value
  
              # only re-encode the audio if it is not already in AC3 format
              if audio1[AUDIO_CODEC] == "AC3":
                  if name == "-acodec":
                      value = "copy"
                  if name == "-ar" or name == "-b:a" or name == "-ac":
                      name = ""
                      value = ""
  
              if name == "-acodec" or name == "-ar" or name == "-b:a" or name == "-ac":
                      command += " " + name + " " + value
  
      #make sure we get the correct stream(s) that we want
      command += " -map 0:%d -map 0:%d " % (video[VIDEO_INDEX], audio1[AUDIO_INDEX])
      if audio2[AUDIO_ID] != -1:
          command += "-map 0:%d" % (audio2[AUDIO_INDEX])
  
      if passes == 1:
          write(command)
          result = runCommand(command)
          if result!=0:
              fatalError("Failed while running mythffmpeg to re-encode video.\n"
                         "Command was %s" % command)
  
      else:
          passLog = os.path.join(getTempPath(), 'pass')
  
          pass1 = command.replace("%passno","1")
          pass1 = pass1.replace("%passlogfile", quoteCmdArg(passLog))
          write("Pass 1 - " + pass1)
          result = runCommand(pass1)
  
          if result!=0:
              fatalError("Failed while running mythffmpeg (Pass 1) to re-encode video.\n"
                         "Command was %s" % command)
  
          if os.path.exists(destvideofile):
              os.remove(destvideofile)
  
          pass2 = command.replace("%passno","2")
          pass2 = pass2.replace("%passlogfile", passLog)
          write("Pass 2 - " + pass2)
          result = runCommand(pass2)
  
          if result!=0:
              fatalError("Failed while running mythffmpeg (Pass 2) to re-encode video.\n"
                         "Command was %s" % command)
function_tokens: def encodeVideoToMPEG2 ( source , destvideofile , video , audio1 , audio2 , aspectratio , profile ) : profileNode = findEncodingProfile ( profile ) passes = int ( getText ( profileNode . getElementsByTagName ( "passes" ) [ 0 ] ) ) command = "mythffmpeg" if cpuCount > 1 : command += " -threads %d" % cpuCount parameters = profileNode . getElementsByTagName ( "parameter" ) for param in parameters : name = param . attributes [ "name" ] . value value = param . attributes [ "value" ] . value # do some parameter substitution if value == "%inputfile" : value = quoteCmdArg ( source ) if value == "%outputfile" : value = quoteCmdArg ( destvideofile ) if value == "%aspect" : value = aspectratio # only re-encode the audio if it is not already in AC3 format if audio1 [ AUDIO_CODEC ] == "AC3" : if name == "-acodec" : value = "copy" if name == "-ar" or name == "-b:a" or name == "-ac" : name = "" value = "" if name != "" : command += " " + name if value != "" : command += " " + value #add second audio track if required if audio2 [ AUDIO_ID ] != - 1 : for param in parameters : name = param . attributes [ "name" ] . value value = param . attributes [ "value" ] . value # only re-encode the audio if it is not already in AC3 format if audio1 [ AUDIO_CODEC ] == "AC3" : if name == "-acodec" : value = "copy" if name == "-ar" or name == "-b:a" or name == "-ac" : name = "" value = "" if name == "-acodec" or name == "-ar" or name == "-b:a" or name == "-ac" : command += " " + name + " " + value #make sure we get the correct stream(s) that we want command += " -map 0:%d -map 0:%d " % ( video [ VIDEO_INDEX ] , audio1 [ AUDIO_INDEX ] ) if audio2 [ AUDIO_ID ] != - 1 : command += "-map 0:%d" % ( audio2 [ AUDIO_INDEX ] ) if passes == 1 : write ( command ) result = runCommand ( command ) if result != 0 : fatalError ( "Failed while running mythffmpeg to re-encode video.\n" "Command was %s" % command ) else : passLog = os . path . join ( getTempPath ( ) , 'pass' ) pass1 = command . replace ( "%passno" , "1" ) pass1 = pass1 . replace ( "%passlogfile" , quoteCmdArg ( passLog ) ) write ( "Pass 1 - " + pass1 ) result = runCommand ( pass1 ) if result != 0 : fatalError ( "Failed while running mythffmpeg (Pass 1) to re-encode video.\n" "Command was %s" % command ) if os . path . exists ( destvideofile ) : os . remove ( destvideofile ) pass2 = command . replace ( "%passno" , "2" ) pass2 = pass2 . replace ( "%passlogfile" , passLog ) write ( "Pass 2 - " + pass2 ) result = runCommand ( pass2 ) if result != 0 : fatalError ( "Failed while running mythffmpeg (Pass 2) to re-encode video.\n" "Command was %s" % command )