def test_ensure_we_can_convert_subtitles_from_mkv_to_avi_in_args(self):
     # Get the destination container object by it's name
     destination_container = self.get_container('avi')
     # Fetch a list of args from the unffmpeg subtitle handler
     subtitle_handle = unffmpeg.SubtitleHandle(
         mkv_ffprobe.mkv_multiple_subtitles_ffprobe, destination_container)
     subtitle_args = subtitle_handle.args()
     # Assert the streams to map array is not empty
     assert subtitle_args['streams_to_map']
     # Assert the streams to encode array is not empty
     assert subtitle_args['streams_to_encode']
 def test_ensure_we_can_remove_subtitles_in_args(self):
     # Get the destination container object by it's name
     destination_container = self.get_container('matroska')
     # Fetch a list of args from the unffmpeg subtitle handler
     subtitle_handle = unffmpeg.SubtitleHandle(
         mkv_ffprobe.mkv_multiple_subtitles_ffprobe, destination_container)
     # Remove the subtitles for this (even though the destination supports subtitles)
     subtitle_handle.remove_subtitle_streams = True
     subtitle_args = subtitle_handle.args()
     # Assert the streams to map array is not empty
     assert not subtitle_args['streams_to_map']
     # Assert the streams to encode array is not empty
     assert not subtitle_args['streams_to_encode']
示例#3
0
    def generate_ffmpeg_args(self,):
        # ffmpeg -i /library/XXXXX.mkv \
        #     -c:v libx265 \
        #     -map 0:0 -map 0:1 -map 0:1 \
        #     -c:a:0 copy \
        #     -c:a:1 libmp3lame -b:a:0 192k -ac 2 \
        #     -y /cache/XXXXX.mkv
        #

        # Read video information for the input file
        file_probe = self.file_in['file_probe']
        if not file_probe:
            return False

        # current_container = unffmpeg.containers.grab_module(self.settings.OUT_CONTAINER)
        destination_container = unffmpeg.containers.grab_module(self.settings.OUT_CONTAINER)

        # Suppress printing banner. (-hide_banner)
        # Set loglevel to info ("-loglevel", "info")
        # Allow experimental encoder config ("-strict", "-2")
        #
        command = ["-hide_banner", "-loglevel", "info", "-strict", "-2", "-max_muxing_queue_size", "512"]

        # Read stream data
        streams_to_map = []
        streams_to_encode = []

        # Set video encoding args
        video_codec_handle = unffmpeg.VideoCodecHandle(file_probe)
        if not self.settings.ENABLE_VIDEO_ENCODING:
            video_codec_handle.disable_video_encoding = True
        # Set video codec and encoder
        video_codec_handle.video_codec = self.settings.VIDEO_CODEC
        video_codec_handle.video_encoder = self.settings.VIDEO_STREAM_ENCODER
        video_codec_args = video_codec_handle.args()
        streams_to_map = streams_to_map + video_codec_args['streams_to_map']
        streams_to_encode = streams_to_encode + video_codec_args['streams_to_encode']

        # Set audio encoding args
        audio_codec_handle = unffmpeg.AudioCodecHandle(file_probe)
        if not self.settings.ENABLE_AUDIO_ENCODING:
            audio_codec_handle.disable_audio_encoding = True
        # Are we transcoding audio streams to a configured codec?
        audio_codec_handle.enable_audio_stream_transcoding = self.settings.ENABLE_AUDIO_STREAM_TRANSCODING
        audio_codec_handle.audio_codec_transcoding = self.settings.AUDIO_CODEC
        audio_codec_handle.audio_encoder_transcoding = self.settings.AUDIO_STREAM_ENCODER
        # Are we cloning audio streams to stereo streams?
        audio_codec_handle.enable_audio_stream_stereo_cloning = self.settings.ENABLE_AUDIO_STREAM_STEREO_CLONING
        audio_codec_handle.set_audio_codec_with_default_encoder_cloning(self.settings.AUDIO_CODEC_CLONING)
        audio_codec_handle.audio_stereo_stream_bitrate = self.settings.AUDIO_STEREO_STREAM_BITRATE
        # Fetch args
        audio_codec_args = audio_codec_handle.args()
        streams_to_map = streams_to_map + audio_codec_args['streams_to_map']
        streams_to_encode = streams_to_encode + audio_codec_args['streams_to_encode']

        # Set subtitle encoding args
        subtitle_handle = unffmpeg.SubtitleHandle(file_probe, destination_container)
        if self.settings.REMOVE_SUBTITLE_STREAMS:
            subtitle_handle.remove_subtitle_streams = True
        subtitle_args = subtitle_handle.args()
        streams_to_map = streams_to_map + subtitle_args['streams_to_map']
        streams_to_encode = streams_to_encode + subtitle_args['streams_to_encode']

        # Map streams
        command = command + streams_to_map

        # Add arguments for creating streams
        command = command + streams_to_encode

        self._log(" ".join(command), level='debug')

        return command
示例#4
0
    def generate_ffmpeg_args(self, file_probe, in_file, out_file):
        # ffmpeg -i /library/XXXXX.mkv \
        #     -c:v libx265 \
        #     -map 0:0 -map 0:1 -map 0:1 \
        #     -c:a:0 copy \
        #     -c:a:1 libmp3lame -b:a:0 192k -ac 2 \
        #     -y /cache/XXXXX.mkv
        #

        # current_container = unffmpeg.containers.grab_module(self.settings['out_container'])
        destination_container = unffmpeg.containers.grab_module(
            self.settings['out_container'])

        # Suppress printing banner. (-hide_banner)
        # Set loglevel to info ("-loglevel", "info")
        # Allow experimental encoder config ("-strict", "-2")
        # Fix issue - 'Too many packets buffered for output stream 0:1' ("-max_muxing_queue_siz", "2048")
        #       REF: [https://trac.ffmpeg.org/ticket/6375]
        #
        main_options = ["-hide_banner", "-loglevel", "info", "-strict", "-2"]
        # Configure Advanced options: https://ffmpeg.org/ffmpeg.html#Advanced-options
        # These are added after the input file
        advanced_options = ["-max_muxing_queue_size", "2048"]
        command = []

        # Hardware acceleration args
        hardware_acceleration = unffmpeg.HardwareAccelerationHandle(file_probe)
        if self.settings['enable_video_encoding']:
            hardware_acceleration.video_encoder = self.settings[
                'video_stream_encoder']
        # Check if hardware decoding is enabled
        if self.settings['enable_hardware_accelerated_decoding']:
            hardware_acceleration.enable_hardware_accelerated_decoding = True
            # The "Enable HW Decoding" checkbox is selected...
            # Loop over available decoders to select the best match for the current settings...
            for hardware_device in hardware_acceleration.get_hwaccel_devices():
                # TODO: in the future perhaps add a feature to be able to select which decoder to use.

                # First select the first one in the list (if nothing else matches, this one will be used)
                if hardware_acceleration.hardware_device is None:
                    hardware_acceleration.hardware_device = hardware_device

                # If we have enabled a HW accelerated encoder, then attempt to match the decoder with it.
                hwaccel = hardware_acceleration.hardware_device.get('hwaccel')
                if "vaapi" in self.settings[
                        'video_stream_encoder'] and hwaccel == "vaapi":
                    hardware_acceleration.hardware_device = hardware_device
                    break
                elif "nvenc" in self.settings[
                        'video_stream_encoder'] and hwaccel == "cuda":
                    hardware_acceleration.hardware_device = hardware_device
                    break
                continue
        hardware_acceleration.set_hwaccel_args()
        main_options = hardware_acceleration.update_main_options(main_options)
        advanced_options = hardware_acceleration.update_advanced_options(
            advanced_options)

        # Read stream data
        streams_to_map = []
        streams_to_encode = []

        # Set video encoding args
        video_codec_handle = unffmpeg.VideoCodecHandle(file_probe)
        if not self.settings['enable_video_encoding']:
            video_codec_handle.disable_video_encoding = True
        # Set video codec and encoder
        video_codec_handle.video_codec = self.settings['video_codec']
        video_codec_handle.video_encoder = self.settings[
            'video_stream_encoder']
        video_codec_args = video_codec_handle.args()
        streams_to_map = streams_to_map + video_codec_args['streams_to_map']
        streams_to_encode = streams_to_encode + video_codec_args[
            'streams_to_encode']

        # Set audio encoding args
        audio_codec_handle = unffmpeg.AudioCodecHandle(file_probe)
        if not self.settings['enable_audio_encoding']:
            audio_codec_handle.disable_audio_encoding = True
        # Are we transcoding audio streams to a configured codec?
        audio_codec_handle.enable_audio_stream_transcoding = self.settings[
            'enable_audio_stream_transcoding']
        audio_codec_handle.audio_codec_transcoding = self.settings[
            'audio_codec']
        audio_codec_handle.audio_encoder_transcoding = self.settings[
            'audio_stream_encoder']
        # Are we cloning audio streams to stereo streams?
        audio_codec_handle.enable_audio_stream_stereo_cloning = self.settings[
            'enable_audio_stream_stereo_cloning']
        audio_codec_handle.set_audio_codec_with_default_encoder_cloning(
            self.settings['audio_codec_cloning'])
        audio_codec_handle.audio_stereo_stream_bitrate = self.settings[
            'audio_stereo_stream_bitrate']
        # Fetch args
        audio_codec_args = audio_codec_handle.args()
        streams_to_map = streams_to_map + audio_codec_args['streams_to_map']
        streams_to_encode = streams_to_encode + audio_codec_args[
            'streams_to_encode']

        # Set subtitle encoding args
        subtitle_handle = unffmpeg.SubtitleHandle(file_probe,
                                                  destination_container)
        if self.settings['remove_subtitle_streams']:
            subtitle_handle.remove_subtitle_streams = True
        subtitle_args = subtitle_handle.args()
        streams_to_map = streams_to_map + subtitle_args['streams_to_map']
        streams_to_encode = streams_to_encode + subtitle_args[
            'streams_to_encode']

        # Overwrite additional options
        if self.settings['overwrite_additional_ffmpeg_options']:
            advanced_options = self.settings[
                'additional_ffmpeg_options'].split()

        # Add main options to command
        command = command + main_options

        # Add input file
        command = command + ['-i', in_file]

        # Add advanced options to command
        command = command + advanced_options

        # Map streams
        command = command + streams_to_map

        # Add arguments for creating streams
        command = command + streams_to_encode

        # Add output file
        command = command + ['-y', out_file]

        return command