def _setup(self):
        self.input_file = self.get_input_resource(1).get('path')
        if not self.input_file:
            raise ManzanitaRewrapException(
                'No path specified for input (index = 1)')
        nb_video_frames = int(
            self.get_input_resource(1).get('nb_video_frames', 0))

        # Compute tmp output path
        filename = os.path.basename(self.input_file)
        filename, _ = os.path.splitext(filename)
        extension = '.ts'
        try:
            extension = self.get_output_resource(1).get('extension', '.ts')
        except ActionException:
            # Silent exception is file does not exist
            pass
        output_filename = '%s%s' % (filename, extension)

        self.output_file = os.path.join(self.tmp_dir, output_filename)
        self.add_output_resource(1, {'path': self.output_file})

        avinfo_action = AVInfoAction(self.log, self.base_dir, self.id)
        avinfo_action.add_input_resource(1, {'path': self.input_file})
        avinfo = avinfo_action.run()

        # Setup ffmpeg demuxer
        ffmpeg = self._new_worker(FFmpegWorker)
        ffmpeg.add_input_file(self.input_file, {}, avinfo)
        ffmpeg.set_nb_frames(nb_video_frames)
        ffmpeg.demux(self.tmp_dir)

        # Setup mp2tsms muxer
        mp2tsms = self._new_worker(ManzanitaMuxWorker,
                                   self.params['manzanita']['global'])

        indexes = {'audio': 0, 'video': 0}
        for output in ffmpeg.output_files:
            if output.type not in ['audio', 'video']:
                continue
            index = str(indexes[output.type] + 1)
            params = self.params['manzanita']['stream'][output.type].get(
                index, {})
            params['type'] = output.type
            mp2tsms.add_input_file(output.path, params)
            indexes[output.type] += 1

        mp2tsms.add_output_file(self.output_file)

        # Add demuxing and muxing workers to worker list
        self.workers.append(ffmpeg)
        self.workers.append(mp2tsms)
Пример #2
0
    def _setup(self):
        self.input_file = self.get_input_resource(1).get("path")
        if not self.input_file:
            raise ManzanitaRewrapException("No path specified for input (index = 1)")
        nb_video_frames = int(self.get_input_resource(1).get("nb_video_frames", 0))

        # Compute tmp output path
        filename = os.path.basename(self.input_file)
        filename, _ = os.path.splitext(filename)
        extension = ".ts"
        try:
            extension = self.get_output_resource(1).get("extension", ".ts")
        except ActionException:
            # Silent exception is file does not exist
            pass
        output_filename = "%s%s" % (filename, extension)

        self.output_file = os.path.join(self.tmp_dir, output_filename)
        self.add_output_resource(1, {"path": self.output_file})

        avinfo_action = AVInfoAction(self.log, self.base_dir, self.id)
        avinfo_action.add_input_resource(1, {"path": self.input_file})
        avinfo = avinfo_action.run()

        # Setup ffmpeg demuxer
        ffmpeg = self._new_worker(FFmpegWorker)
        ffmpeg.add_input_file(self.input_file, {}, avinfo)
        ffmpeg.set_nb_frames(nb_video_frames)
        ffmpeg.demux(self.tmp_dir)

        # Setup mp2tsms muxer
        mp2tsms = self._new_worker(
            ManzanitaMuxWorker, self.params["manzanita"]["global"]
        )

        indexes = {"audio": 0, "video": 0}
        for output in ffmpeg.output_files:
            if output.type not in ["audio", "video"]:
                continue
            index = str(indexes[output.type] + 1)
            params = self.params["manzanita"]["stream"][output.type].get(index, {})
            params["type"] = output.type
            mp2tsms.add_input_file(output.path, params)
            indexes[output.type] += 1

        mp2tsms.add_output_file(self.output_file)

        # Add demuxing and muxing workers to worker list
        self.workers.append(ffmpeg)
        self.workers.append(mp2tsms)
Пример #3
0
    def _setup(self):
        self.input_file = self.get_input_resource(1).get('path')
        if not self.input_file:
            raise ManzanitaRewrapException('No path specified for input (index = 1)')
        nb_video_frames = int(self.get_input_resource(1).get('nb_video_frames', 0))

        # Compute tmp output path
        filename = os.path.basename(self.input_file)
        filename, _ = os.path.splitext(filename)
        extension = '.ts'
        try:
            extension = self.get_output_resource(1).get('extension', '.ts')
        except ActionException:
            # Silent exception is file does not exist
            pass
        output_filename = '%s%s' % (filename, extension)

        self.output_file = os.path.join(self.tmp_dir, output_filename)
        self.add_output_resource(1, {'path': self.output_file})

        avinfo_action = AVInfoAction(self.log, self.base_dir, self.id)
        avinfo_action.add_input_resource(1, {'path': self.input_file})
        avinfo = avinfo_action.run()

        # Setup ffmpeg demuxer
        ffmpeg = self._new_worker(FFmpegWorker)
        ffmpeg.add_input_file(self.input_file, {}, avinfo)
        ffmpeg.set_nb_frames(nb_video_frames)
        ffmpeg.demux(self.tmp_dir)

        # Setup mp2tsms muxer
        mp2tsms = self._new_worker(ManzanitaMuxWorker, self.params['manzanita']['global'])

        indexes = {'audio': 0, 'video': 0}
        for output in ffmpeg.output_files:
            if output.type not in ['audio', 'video']:
                continue
            index = str(indexes[output.type] + 1)
            params = self.params['manzanita']['stream'][output.type].get(index, {})
            params['type'] = output.type
            mp2tsms.add_input_file(output.path, params)
            indexes[output.type] += 1

        mp2tsms.add_output_file(self.output_file)

        # Add demuxing and muxing workers to worker list
        self.workers.append(ffmpeg)
        self.workers.append(mp2tsms)
Пример #4
0
    def _setup(self):
        self.input_file = self.get_input_resource(1).get("path")
        nb_video_frames = int(
            self.get_input_resource(1).get("nb_video_frames", 0))
        self.input_basename = os.path.splitext(
            os.path.basename(self.input_file))[0]

        avinfo_action = AVInfoAction(self.log, self.base_dir, self.id)
        avinfo_action.add_input_resource(1, {"path": self.input_file})
        avinfo = avinfo_action.run()

        ffmpeg = self._new_worker(FFmpegWorker)
        ffmpeg.add_input_file(self.input_file, {}, avinfo)
        ffmpeg.set_nb_frames(nb_video_frames)
        ffmpeg.set_audio_min_streams(self.audio_min_streams)
        ffmpeg.set_timecode(avinfo.timecode)
        ffmpeg.set_threads(self.decoding_threads, self.encoding_threads)
        ffmpeg.set_channels_per_stream(self.audio_channels_per_stream)

        if self.video_codec_options["pix_fmt"] == "default":
            self.video_codec_options["pix_fmt"] = avinfo.pix_fmt

        if self.audio_format == "default":
            if avinfo.audio_format:
                self.audio_format = avinfo.audio_format
            else:
                self.audio_format = "s16le"
            self.audio_codec_options["format"] = self.audio_format

        if self.seek > 0:
            ffmpeg.set_seek(self.seek)

        if self.single_frame:
            self.container = "jpg"
            self.video_codec = "mjpeg"
            self.container_hinting = False
            ffmpeg.set_single_frame()

        ffmpeg.transcode(self.video_codec, self.video_codec_options)
        ffmpeg.transcode(self.audio_codec, self.audio_codec_options, "audio")

        if self.video_aspect_ratio == "default":
            if avinfo.video_is_HD():
                ffmpeg.set_aspect_ratio("16:9")
            else:
                num, den = avinfo.video_dar.split(":")
                dar = float(num) / float(den)
                if dar > 1.5:
                    ffmpeg.set_aspect_ratio("16:9")
                else:
                    ffmpeg.set_aspect_ratio("4:3")
        elif self.video_aspect_ratio == "copy":
            ffmpeg.set_aspect_ratio(avinfo.video_dar)
        else:
            ffmpeg.set_aspect_ratio(self.video_aspect_ratio)

        if self.video_letterbox:
            ffmpeg.letterbox()

        if self.video_burn:
            ffmpeg.drawtext(self.tmp_dir, self.burn_options)

        # FFmpeg muxer
        if self.muxer == "ffmpeg":
            ffmpeg.mux(self.tmp_dir, self.container, self.container_options)
            self.workers.append(ffmpeg)
            if not self.container_hinting:
                for index, output_file in enumerate(ffmpeg.output_files):
                    self.add_output_resource(index + 1,
                                             {"path": output_file.path})
            else:
                if self.container in ["flv"]:
                    for index, output_file in enumerate(ffmpeg.output_files):
                        hinting_worker = self._new_worker(FLVTool2Worker)
                        hinting_worker.params = {"-U": ""}
                        hinting_worker.add_input_file(output_file.path)
                        self.workers.append(hinting_worker)
                        self.add_output_resource(index + 1,
                                                 {"path": output_file.path})

                elif self.container in ["mp4", "mov"]:
                    for index, output_file in enumerate(ffmpeg.output_files):
                        base, ext = os.path.splitext(output_file.path)
                        hinting_output_path = "%s-hint%s" % (base, ext)
                        hinting_worker = self._new_worker(QtFastStartWorker)
                        hinting_worker.add_input_file(output_file.path)
                        hinting_worker.add_output_file(hinting_output_path)
                        self.workers.append(hinting_worker)
                        self.add_output_resource(index + 1,
                                                 {"path": hinting_output_path})

        # Omneon muxer
        elif self.muxer == "omneon":
            ffmpeg.demux(self.container_abs_essence_dir)

            ommcp = self._new_worker(OmneonCopyWorker)
            for output_file in ffmpeg.output_files:
                params = {}
                if self.video_codec == "copy" and output_file.path.endswith(
                        ".dv"):
                    params["srctrack"] = 0
                ommcp.add_input_file(output_file.path, params)

            base_path = os.path.join(self.tmp_dir, self.input_basename)
            ommcp.mux(base_path, self.container, self.container_options)

            ommq = self._new_worker(OmneonQueryWorker)
            for output_file in ommcp.output_files:
                ommq.add_input_file(output_file.path)

            ommq.set_timecode(avinfo.timecode)

            index = 0
            for output_file in ommcp.output_files:
                self.add_output_resource(index + 1, {"path": output_file.path})
                index += 1

            if self.container_reference:
                for output_file in ffmpeg.output_files:
                    self.add_output_resource(index + 1,
                                             {"path": output_file.path})
                    index += 1

            self.workers.append(ffmpeg)
            self.workers.append(ommcp)
            self.workers.append(ommq)

        # BMX muxer
        elif self.muxer == "bmx":
            ffmpeg.demux(self.container_abs_essence_dir)

            raw2bmx = self._new_worker(Raw2BmxWorker)
            for output_file in ffmpeg.output_files:
                params = {}
                if output_file.type == "video":
                    params["codec"] = self.video_codec
                elif output_file.type == "audio":
                    params["codec"] = self.audio_codec
                raw2bmx.add_input_file(output_file.path, params)

            base_path = os.path.join(self.tmp_dir, self.input_basename)
            raw2bmx.set_timecode(avinfo.timecode)
            raw2bmx.mux(base_path, self.container_options)
            index = 0
            for output_file in raw2bmx.output_files:
                self.add_output_resource(index + 1, {"path": output_file.path})
                index += 1

            self.workers.append(ffmpeg)
            self.workers.append(raw2bmx)

        # Unsupported muxer
        else:
            raise TranscodeException("Unsupported muxer: %s" % self.muxer)
Пример #5
0
    def _setup(self):
        self.input_file = self.get_input_resource(1).get('path')
        nb_video_frames = int(self.get_input_resource(1).get('nb_video_frames', 0))
        self.input_basename = os.path.splitext(os.path.basename(self.input_file))[0]

        avinfo_action = AVInfoAction(self.log, self.base_dir, self.id)
        avinfo_action.add_input_resource(1, {'path': self.input_file})
        avinfo = avinfo_action.run()

        ffmpeg = self._new_worker(FFmpegWorker)
        ffmpeg.add_input_file(self.input_file, {}, avinfo)
        ffmpeg.set_nb_frames(nb_video_frames)
        ffmpeg.set_timecode(avinfo.timecode)
        ffmpeg.set_threads(self.decoding_threads, self.encoding_threads)

        if self.audio_format == 'default':
            if avinfo.audio_format:
                self.audio_format = avinfo.audio_format
            else:
                self.audio_format = 's16le'
            self.audio_codec_options['format'] = self.audio_format

        ffmpeg.transcode(self.video_codec, self.video_codec_options)
        ffmpeg.transcode(self.audio_codec, self.audio_codec_options)

        if self.video_aspect_ratio == 'default':
            if avinfo.video_dar == '16:9':
                ffmpeg.set_aspect_ratio('16:9')
            else:
                if avinfo.video_is_HD():
                    ffmpeg.set_aspect_ratio('16:9')
                else:
                    ffmpeg.set_aspect_ratio('4:3')
        else:
            ffmpeg.set_aspect_ratio(self.video_aspect_ratio)

        if self.video_letterbox:
            ffmpeg.letterbox()

        # FFmpeg muxer
        if self.muxer == 'ffmpeg':
            ffmpeg.mux(self.tmp_dir, self.container, self.container_options)
            self.workers.append(ffmpeg)
            if not self.container_hinting:
                for index, output_file in enumerate(ffmpeg.output_files):
                    self.add_output_resource(index + 1, {'path': output_file.path})
            else:
                if self.container in ['flv']:
                    for index, output_file in enumerate(ffmpeg.output_files):
                        hinting_worker = self._new_worker(FLVTool2Worker)
                        hinting_worker.params = {'-U': ''}
                        hinting_worker.add_input_file(output_file.path)
                        self.workers.append(hinting_worker)
                        self.add_output_resource(index + 1, {'path': output_file.path})

                elif self.container in ['mp4', 'mov']:
                    for index, output_file in enumerate(ffmpeg.output_files):
                        base, ext = os.path.splitext(output_file.path)
                        hinting_output_path = '%s-hint%s' % (base, ext)
                        hinting_worker = self._new_worker(QtFastStartWorker)
                        hinting_worker.add_input_file(output_file.path)
                        hinting_worker.add_output_file(hinting_output_path)
                        self.workers.append(hinting_worker)
                        self.add_output_resource(index + 1, {'path': hinting_output_path})

        # Omneon muxer
        elif self.muxer == 'omneon':
            ffmpeg.demux(self.container_abs_essence_dir, self.demux_channels_per_stream)

            ommcp = self._new_worker(OmneonCopyWorker)
            for output_file in ffmpeg.output_files:
                params = {}
                if self.video_codec == 'copy' and output_file.path.endswith('.dv'):
                    params['srctrack'] = 0
                ommcp.add_input_file(output_file.path, params)

            base_path = os.path.join(self.tmp_dir, self.input_basename)
            ommcp.mux(base_path, self.container, self.container_options)

            ommq = self._new_worker(OmneonQueryWorker)
            for output_file in ommcp.output_files:
                ommq.add_input_file(output_file.path)

            ommq.set_timecode(avinfo.timecode)

            index = 0
            for output_file in ommcp.output_files:
                self.add_output_resource(index + 1, {'path': output_file.path})
                index += 1

            if self.container_reference:
                for output_file in ffmpeg.output_files:
                    self.add_output_resource(index + 1, {'path': output_file.path})
                    index += 1

            self.workers.append(ffmpeg)
            self.workers.append(ommcp)
            self.workers.append(ommq)

        # BMX muxer
        elif self.muxer == 'bmx':
            ffmpeg.demux(self.container_abs_essence_dir, self.demux_channels_per_stream)

            raw2bmx = self._new_worker(Raw2BmxWorker)
            for output_file in ffmpeg.output_files:
                params = {}
                if output_file.type == 'video':
                    params['codec'] = self.video_codec
                elif output_file.type == 'audio':
                    params['codec'] = self.audio_codec
                raw2bmx.add_input_file(output_file.path, params)

            base_path = os.path.join(self.tmp_dir, self.input_basename)
            raw2bmx.set_timecode(avinfo.timecode)
            raw2bmx.mux(base_path, self.container_options)
            index = 0
            for output_file in raw2bmx.output_files:
                self.add_output_resource(index + 1, {'path': output_file.path})
                index += 1

            self.workers.append(ffmpeg)
            self.workers.append(raw2bmx)

        # Unsupported muxer
        else:
            raise TranscodeException('Unsupported muxer: %s' % self.muxer)
Пример #6
0
    def _setup(self):
        self.input_file = self.get_input_resource(1).get('path')
        nb_video_frames = int(self.get_input_resource(1).get('nb_video_frames', 0))
        self.input_basename = os.path.splitext(os.path.basename(self.input_file))[0]

        avinfo_action = AVInfoAction(self.log, self.base_dir, self.id)
        avinfo_action.add_input_resource(1, {'path': self.input_file})
        avinfo = avinfo_action.run()

        ffmpeg = self._new_worker(FFmpegWorker)
        ffmpeg.add_input_file(self.input_file, {}, avinfo)
        ffmpeg.set_nb_frames(nb_video_frames)
        ffmpeg.set_audio_min_streams(self.audio_min_streams)
        ffmpeg.set_timecode(avinfo.timecode)
        ffmpeg.set_threads(self.decoding_threads, self.encoding_threads)
        ffmpeg.set_channels_per_stream(self.audio_channels_per_stream)

        if self.video_codec_options['pix_fmt'] == 'default':
            self.video_codec_options['pix_fmt'] = avinfo.pix_fmt

        if self.audio_format == 'default':
            if avinfo.audio_format:
                self.audio_format = avinfo.audio_format
            else:
                self.audio_format = 's16le'
            self.audio_codec_options['format'] = self.audio_format

        if self.seek > 0:
            ffmpeg.set_seek(self.seek)

        if self.single_frame:
            self.container = 'jpg'
            self.video_codec = 'mjpeg'
            self.container_hinting = False
            ffmpeg.set_single_frame()

        ffmpeg.transcode(self.video_codec, self.video_codec_options)
        ffmpeg.transcode(self.audio_codec, self.audio_codec_options, 'audio')

        if self.video_aspect_ratio == 'default':
            if avinfo.video_is_HD():
                ffmpeg.set_aspect_ratio('16:9')
            else:
                num, den = avinfo.video_dar.split(':')
                dar = float(num) / float(den)
                if dar > 1.5:
                    ffmpeg.set_aspect_ratio('16:9')
                else:
                    ffmpeg.set_aspect_ratio('4:3')
        elif self.video_aspect_ratio == 'copy':
            ffmpeg.set_aspect_ratio(avinfo.video_dar)
        else:
            ffmpeg.set_aspect_ratio(self.video_aspect_ratio)

        if self.video_letterbox:
            ffmpeg.letterbox()

        if self.video_burn:
            ffmpeg.drawtext(self.tmp_dir, self.burn_options)

        # FFmpeg muxer
        if self.muxer == 'ffmpeg':
            ffmpeg.mux(self.tmp_dir, self.container, self.container_options)
            self.workers.append(ffmpeg)
            if not self.container_hinting:
                for index, output_file in enumerate(ffmpeg.output_files):
                    self.add_output_resource(index + 1, {'path': output_file.path})
            else:
                if self.container in ['flv']:
                    for index, output_file in enumerate(ffmpeg.output_files):
                        hinting_worker = self._new_worker(FLVTool2Worker)
                        hinting_worker.params = {'-U': ''}
                        hinting_worker.add_input_file(output_file.path)
                        self.workers.append(hinting_worker)
                        self.add_output_resource(index + 1, {'path': output_file.path})

                elif self.container in ['mp4', 'mov']:
                    for index, output_file in enumerate(ffmpeg.output_files):
                        base, ext = os.path.splitext(output_file.path)
                        hinting_output_path = '%s-hint%s' % (base, ext)
                        hinting_worker = self._new_worker(QtFastStartWorker)
                        hinting_worker.add_input_file(output_file.path)
                        hinting_worker.add_output_file(hinting_output_path)
                        self.workers.append(hinting_worker)
                        self.add_output_resource(index + 1, {'path': hinting_output_path})

        # Omneon muxer
        elif self.muxer == 'omneon':
            ffmpeg.demux(self.container_abs_essence_dir)

            ommcp = self._new_worker(OmneonCopyWorker)
            for output_file in ffmpeg.output_files:
                params = {}
                if self.video_codec == 'copy' and output_file.path.endswith('.dv'):
                    params['srctrack'] = 0
                ommcp.add_input_file(output_file.path, params)

            base_path = os.path.join(self.tmp_dir, self.input_basename)
            ommcp.mux(base_path, self.container, self.container_options)

            ommq = self._new_worker(OmneonQueryWorker)
            for output_file in ommcp.output_files:
                ommq.add_input_file(output_file.path)

            ommq.set_timecode(avinfo.timecode)

            index = 0
            for output_file in ommcp.output_files:
                self.add_output_resource(index + 1, {'path': output_file.path})
                index += 1

            if self.container_reference:
                for output_file in ffmpeg.output_files:
                    self.add_output_resource(index + 1, {'path': output_file.path})
                    index += 1

            self.workers.append(ffmpeg)
            self.workers.append(ommcp)
            self.workers.append(ommq)

        # BMX muxer
        elif self.muxer == 'bmx':
            ffmpeg.demux(self.container_abs_essence_dir)

            raw2bmx = self._new_worker(Raw2BmxWorker)
            for output_file in ffmpeg.output_files:
                params = {}
                if output_file.type == 'video':
                    params['codec'] = self.video_codec
                elif output_file.type == 'audio':
                    params['codec'] = self.audio_codec
                raw2bmx.add_input_file(output_file.path, params)

            base_path = os.path.join(self.tmp_dir, self.input_basename)
            raw2bmx.set_timecode(avinfo.timecode)
            raw2bmx.mux(base_path, self.container_options)
            index = 0
            for output_file in raw2bmx.output_files:
                self.add_output_resource(index + 1, {'path': output_file.path})
                index += 1

            self.workers.append(ffmpeg)
            self.workers.append(raw2bmx)

        # Unsupported muxer
        else:
            raise TranscodeException('Unsupported muxer: %s' % self.muxer)