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