parameters: (chanid, starttime, mediafile, destvideofile, folder, profile, usecutlist)
docstring: Encodes a nuv video source file to MPEG2 video and AC3 audio, using mythtranscode & mythffmpeg
docstring_summary: Encodes a nuv video source file to MPEG2 video and AC3 audio, using mythtranscode & mythffmpeg
docstring_tokens: Encodes a nuv video source file to MPEG2 video and AC3 audio using mythtranscode & mythffmpeg
function: def encodeNuvToMPEG2(chanid, starttime, mediafile, destvideofile, folder, profile, usecutlist):
      """Encodes a nuv video source file to MPEG2 video and AC3 audio, using mythtranscode & mythffmpeg"""
  
      # make sure mythtranscode hasn't left some stale fifos hanging around
      if ((doesFileExist(os.path.join(folder, "audout")) or doesFileExist(os.path.join(folder, "vidout")))):
          fatalError("Something is wrong! Found one or more stale fifo's from mythtranscode\n"
                     "Delete the fifos in '%s' and start again" % folder)
  
      profileNode = findEncodingProfile(profile)
      parameters = profileNode.getElementsByTagName("parameter")
  
      # default values - will be overriden by values from the profile
      outvideobitrate = "5000k"
      if videomode == "ntsc":
          outvideores = "720x480"
      else:
          outvideores = "720x576"
  
      outaudiochannels = 2
      outaudiobitrate = 384
      outaudiosamplerate = 48000
      outaudiocodec = "ac3"
      deinterlace = 0
      filter = ""
      qmin = 5
      qmax = 31
      qdiff = 31
  
      for param in parameters:
          name = param.attributes["name"].value
          value = param.attributes["value"].value
  
          # we only support a subset of the parameter for the moment
          if name == "-acodec":
              outaudiocodec = value
          if name == "-ac":
              outaudiochannels = value
          if name == "-ab":
              outaudiobitrate = value
          if name == "-ar":
              outaudiosamplerate = value
          if name == "-b":
              outvideobitrate = value
          if name == "-s":
              outvideores = value
          if name == "-deinterlace":
              deinterlace = 1
          if name == "-filter:v":
              filter = " -filter:v " + quoteCmdArg(value) + " "
          if name == "-qmin":
             qmin = value
          if name == "-qmax":
             qmax = value
          if name == "-qdiff":
             qdiff = value
  
      if chanid != -1:
          utcstarttime = datetime.duck(starttime).utcisoformat()
          if (usecutlist == True):
              PID=os.spawnlp(os.P_NOWAIT, "mythtranscode", "mythtranscode",
                          '--profile', '27',
                          '--chanid', chanid,
                          '--starttime', utcstarttime,
                          '--honorcutlist',
                          '--fifodir', folder)
              write("mythtranscode started (using cut list) PID = %s" % PID)
          else:
              PID=os.spawnlp(os.P_NOWAIT, "mythtranscode", "mythtranscode",
                          '--profile', '27',
                          '--chanid', chanid,
                          '--starttime', utcstarttime,
                          '--fifodir', folder)
  
              write("mythtranscode started PID = %s" % PID)
      elif mediafile != -1:
          PID=os.spawnlp(os.P_NOWAIT, "mythtranscode", "mythtranscode",
                  '--profile', '27',
                  '--infile', mediafile,
                  '--fifodir', folder)
          write("mythtranscode started (using file) PID = %s" % PID)
      else:
          fatalError("no video source passed to encodeNuvToMPEG2.\n")
  
  
      samplerate, channels = getAudioParams(folder)
      videores, fps, aspectratio = getVideoParams(folder)
  
      command =  "mythffmpeg -y "
  
      if cpuCount > 1:
          command += "-threads %d " % cpuCount
  
      command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, quoteCmdArg(os.path.join(folder, "audout")))
      command += "-f rawvideo -pix_fmt yuv420p -s %s -aspect %s -r %s " % (videores, aspectratio, fps)
      command += "-i %s " % quoteCmdArg(os.path.join(folder, "vidout"))
      command += "-aspect %s -r %s " % (aspectratio, fps)
      if (deinterlace == 1):
          command += "-deinterlace "
      command += "%s" % filter
      command += "-s %s -b %s -vcodec mpeg2video " % (outvideores, outvideobitrate)
      command += "-qmin %s -qmax %s -qdiff %s " % (qmin, qmax, qdiff)
      command += "-ab %s -ar %s -acodec %s " % (outaudiobitrate, outaudiosamplerate, outaudiocodec)
      command += "-f dvd %s" % quoteCmdArg(destvideofile)
  
      #wait for mythtranscode to create the fifos
      tries = 30
      while (tries and not(doesFileExist(os.path.join(folder, "audout")) and
                           doesFileExist(os.path.join(folder, "vidout")))):
          tries -= 1
          write("Waiting for mythtranscode to create the fifos")
          time.sleep(1)
  
      if (not(doesFileExist(os.path.join(folder, "audout")) and doesFileExist(os.path.join(folder, "vidout")))):
          fatalError("Waited too long for mythtranscode to create the fifos - giving up!!")
  
      write("Running mythffmpeg")
      result = runCommand(command)
      if result != 0:
          os.kill(PID, signal.SIGKILL)
          fatalError("Failed while running mythffmpeg to re-encode video.\n"
                     "Command was %s" % command)
function_tokens: def encodeNuvToMPEG2 ( chanid , starttime , mediafile , destvideofile , folder , profile , usecutlist ) : # make sure mythtranscode hasn't left some stale fifos hanging around if ( ( doesFileExist ( os . path . join ( folder , "audout" ) ) or doesFileExist ( os . path . join ( folder , "vidout" ) ) ) ) : fatalError ( "Something is wrong! Found one or more stale fifo's from mythtranscode\n" "Delete the fifos in '%s' and start again" % folder ) profileNode = findEncodingProfile ( profile ) parameters = profileNode . getElementsByTagName ( "parameter" ) # default values - will be overriden by values from the profile outvideobitrate = "5000k" if videomode == "ntsc" : outvideores = "720x480" else : outvideores = "720x576" outaudiochannels = 2 outaudiobitrate = 384 outaudiosamplerate = 48000 outaudiocodec = "ac3" deinterlace = 0 filter = "" qmin = 5 qmax = 31 qdiff = 31 for param in parameters : name = param . attributes [ "name" ] . value value = param . attributes [ "value" ] . value # we only support a subset of the parameter for the moment if name == "-acodec" : outaudiocodec = value if name == "-ac" : outaudiochannels = value if name == "-ab" : outaudiobitrate = value if name == "-ar" : outaudiosamplerate = value if name == "-b" : outvideobitrate = value if name == "-s" : outvideores = value if name == "-deinterlace" : deinterlace = 1 if name == "-filter:v" : filter = " -filter:v " + quoteCmdArg ( value ) + " " if name == "-qmin" : qmin = value if name == "-qmax" : qmax = value if name == "-qdiff" : qdiff = value if chanid != - 1 : utcstarttime = datetime . duck ( starttime ) . utcisoformat ( ) if ( usecutlist == True ) : PID = os . spawnlp ( os . P_NOWAIT , "mythtranscode" , "mythtranscode" , '--profile' , '27' , '--chanid' , chanid , '--starttime' , utcstarttime , '--honorcutlist' , '--fifodir' , folder ) write ( "mythtranscode started (using cut list) PID = %s" % PID ) else : PID = os . spawnlp ( os . P_NOWAIT , "mythtranscode" , "mythtranscode" , '--profile' , '27' , '--chanid' , chanid , '--starttime' , utcstarttime , '--fifodir' , folder ) write ( "mythtranscode started PID = %s" % PID ) elif mediafile != - 1 : PID = os . spawnlp ( os . P_NOWAIT , "mythtranscode" , "mythtranscode" , '--profile' , '27' , '--infile' , mediafile , '--fifodir' , folder ) write ( "mythtranscode started (using file) PID = %s" % PID ) else : fatalError ( "no video source passed to encodeNuvToMPEG2.\n" ) samplerate , channels = getAudioParams ( folder ) videores , fps , aspectratio = getVideoParams ( folder ) command = "mythffmpeg -y " if cpuCount > 1 : command += "-threads %d " % cpuCount command += "-f s16le -ar %s -ac %s -i %s " % ( samplerate , channels , quoteCmdArg ( os . path . join ( folder , "audout" ) ) ) command += "-f rawvideo -pix_fmt yuv420p -s %s -aspect %s -r %s " % ( videores , aspectratio , fps ) command += "-i %s " % quoteCmdArg ( os . path . join ( folder , "vidout" ) ) command += "-aspect %s -r %s " % ( aspectratio , fps ) if ( deinterlace == 1 ) : command += "-deinterlace " command += "%s" % filter command += "-s %s -b %s -vcodec mpeg2video " % ( outvideores , outvideobitrate ) command += "-qmin %s -qmax %s -qdiff %s " % ( qmin , qmax , qdiff ) command += "-ab %s -ar %s -acodec %s " % ( outaudiobitrate , outaudiosamplerate , outaudiocodec ) command += "-f dvd %s" % quoteCmdArg ( destvideofile ) #wait for mythtranscode to create the fifos tries = 30 while ( tries and not ( doesFileExist ( os . path . join ( folder , "audout" ) ) and doesFileExist ( os . path . join ( folder , "vidout" ) ) ) ) : tries -= 1 write ( "Waiting for mythtranscode to create the fifos" ) time . sleep ( 1 ) if ( not ( doesFileExist ( os . path . join ( folder , "audout" ) ) and doesFileExist ( os . path . join ( folder , "vidout" ) ) ) ) : fatalError ( "Waited too long for mythtranscode to create the fifos - giving up!!" ) write ( "Running mythffmpeg" ) result = runCommand ( command ) if result != 0 : os . kill ( PID , signal . SIGKILL ) fatalError ( "Failed while running mythffmpeg to re-encode video.\n" "Command was %s" % command )