Example #1
0
  def remediate_audio(self, path):

    # Create our Input() object to specify file we will be transcoding
    input_file = Input(path)

    # Create variables we will be using in the following code
    codec = None
    output_path = re.match('^(.*)\.audio\.\d\.mkv$', path).group(1) + '.final.audio.' + re.match('^.*\.audio\.(\d)\.mkv$', path).group(1) + '.mkv'
    output_file = Output(output_path)

    # Check if self.finalfiles is not none and if so create a list object. This is so we don't lose files already in the list
    if self.finalfiles is None:
      self.finalfiles = []

    # Create our AudioCodec() object to define the output codec and bitrate
    codec = AudioCodec('ac3')
    codec = codec.bitrate('448k')

    # Instance our FFmpeg() object to begin processing
    remediate_audio_job = FFmpeg('/usr/bin/ffmpeg', input_file, codec, output_file)

    # Begin the transcoding operation iterating over the piped stdout from the command
    with remediate_audio_job as self._process:
      while not self.abort and self._process.running:
        for line in self._process.readlines():
          if mediamanager.VERBOSE:
            logger.log(line, logger.DEBUG)
      if self._process.failed:
        return False
      elif self._process.successful:
        self.finalfiles.append(output_path)
        return True
      else:
        return False
Example #2
0
  def demux_file(self):

    # Return if we couldn't get the base file name without extension from the self._file.basename
    if not self._outfile_base:
      logger.log("Unable to get base file name; %s" % self._file.path, logger.DEBUG)
      return False

    # Create our Input() object to specify the file we will be demuxing
    input_file = Input(self._file.path)

    # Create a list of the codecs with maps or input stream to output file
    codecs = []

    # Create a list to contain the paths of all the output files
    self.demuxfiles = []

    # Iterate over self._file.videoStreams and create codecs for each video stream with 'copy' specified so no transcoding is done
    for i, stream in enumerate(self._file.videoStreams):
      stream_id = int(stream['track_id']) - 1
      outfile_path = os.path.join(mediamanager.TRANSCODER_TEMPDIR, self._outfile_base + '.video.' + str(stream_id) + '.mkv')
      video_codec = VideoCodec('copy')
      video_codec = video_codec.mapstream("0:%d" % stream_id, outfile_path)
      self.demuxfiles.append(outfile_path)
      codecs.append(video_codec)

    # Iterate over self._file.audioStreams and create codecs for each audio stream with 'copy' specified so no transcoding is done
    for i, stream in enumerate(self._file.audioStreams):
      stream_id = int(stream['track_id']) - 1
      outfile_path = os.path.join(mediamanager.TRANSCODER_TEMPDIR, self._outfile_base + '.audio.' + str(stream_id) + '.mkv')
      audio_codec = AudioCodec('copy')
      audio_codec = audio_codec.mapstream("0:%d" % stream_id, outfile_path)
      self.demuxfiles.append(outfile_path)
      codecs.append(audio_codec)

    # Create FFmpeg() object to begin demux operation
    demux_job = FFmpeg('/usr/bin/ffmpeg', input_file)

    # Iterate over items in codecs list and insert them at the end of the FFmpeg() object's list
    for codec in codecs:
      demux_job.insert(len(demux_job), codec)

    # Begin demux operation and iterate over piped stdout from the popen process
    logger.log("demux_job: %s" % demux_job, logger.DEBUG)
    with demux_job as self._process:
      while  not self.abort and self._process.running:
        for line in self._process.readlines():
          if mediamanager.VERBOSE:
            logger.log(line, logger.DEBUG)
      if self._process.failed:
        return False
      elif self._process.successful:
        return True
      else:
        return False