예제 #1
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
예제 #2
0
  def remux_files(self):

    # Create our output file object for ffmpegwrapper
    if mediamanager.COMPLIANCE['Media']['Container']['Codec'] == 'Matroska':
      self._muxed_file_basename = self._outfile_base + '.' + 'mkv'
    elif mediamanager.COMPLIANCE['Media']['Container']['Codec'] == 'MPEG-4':
      self._muxed_file_basename = self._outfile_base + '.' + 'mp4'
    self._muxed_file_path = os.path.join(mediamanager.TRANSCODER_TEMPDIR, self._muxed_file_basename)
    output_file = Output(self._muxed_file_path)

    # Create our FFmpeg job object with path to ffmpeg binary
    remux_job = FFmpeg('/usr/bin/ffmpeg')

    # Iterate for self.finalfiles and create Input() objects for input files and insert at the end of the list
    for _file in self.finalfiles:
      input_file = Input(_file)
      remux_job.insert(len(remux_job), input_file)

    # Add video codec object with 'copy' as the codec specified so it just muxes the streams
    remux_job.insert(len(remux_job), VideoCodec('copy'))

    # Add audio codec object with 'copy' as the codec specified so it just muxes the streams
    remux_job.insert(len(remux_job), AudioCodec('copy'))

    # Add Output() object to specify the output path and container
    remux_job.insert(len(remux_job), output_file)

    # Begin remux job and iterate over the piped stdout from the command logging it to debug
    with remux_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