Example #1
0
    def setup_ffmpeg(self):
        """
        Configure ffmpeg object.

        :return:
        """
        settings = {
            'audio_codec':                          self.current_task.settings.audio_codec,
            'audio_codec_cloning':                  self.current_task.settings.audio_codec_cloning,
            'audio_stereo_stream_bitrate':          self.current_task.settings.audio_stereo_stream_bitrate,
            'audio_stream_encoder':                 self.current_task.settings.audio_stream_encoder,
            'cache_path':                           self.current_task.settings.cache_path,
            'debugging':                            self.current_task.settings.debugging,
            'enable_audio_encoding':                self.current_task.settings.enable_audio_encoding,
            'enable_audio_stream_stereo_cloning':   self.current_task.settings.enable_audio_stream_stereo_cloning,
            'enable_audio_stream_transcoding':      self.current_task.settings.enable_audio_stream_transcoding,
            'enable_video_encoding':                self.current_task.settings.enable_video_encoding,
            'out_container':                        self.current_task.settings.out_container,
            'remove_subtitle_streams':              self.current_task.settings.remove_subtitle_streams,
            'video_codec':                          self.current_task.settings.video_codec,
            'video_stream_encoder':                 self.current_task.settings.video_stream_encoder,
            'overwrite_additional_ffmpeg_options':  self.current_task.settings.overwrite_additional_ffmpeg_options,
            'additional_ffmpeg_options':            self.current_task.settings.additional_ffmpeg_options,
            'enable_hardware_accelerated_decoding': self.current_task.settings.enable_hardware_accelerated_decoding,
        }
        self.ffmpeg = ffmpeg.FFMPEGHandle(settings)
Example #2
0
    def file_already_in_target_format(self):
        """
        Check if file is not the correct format

        :return:
        """
        # Only run this check against video/audio/image MIME types
        mimetypes.init()
        file_type = mimetypes.guess_type(self.path)[0]
        # If the file has no MIME type then it cannot be tested
        if file_type is None:
            return False
        # Make sure the MIME type is either audio, video or image
        file_type_category = file_type.split('/')[0]
        if file_type_category not in ['audio', 'video', 'image']:
            return False

        # init FFMPEG handle
        ffmpeg_settings = self.init_ffmpeg_handle_settings()
        ffmpeg_handle = ffmpeg.FFMPEGHandle(ffmpeg_settings)
        # Reset file in
        ffmpeg_handle.file_in = {}
        # Check if file matches configured codec and format
        file_not_correct_format = ffmpeg_handle.check_file_to_be_processed(self.path, ffmpeg_settings)
        if file_not_correct_format:
            # File needs to be processed
            return False
        return True
Example #3
0
 def __init__(self, data_queues, settings):
     self.name = "EventProcessor"
     self.settings = settings
     self.logger = data_queues["logging"].get_logger(self.name)
     self.inotifytasks = data_queues["inotifytasks"]
     self.abort_flag = threading.Event()
     self.abort_flag.clear()
     self.ffmpeg = ffmpeg.FFMPEGHandle(settings)
Example #4
0
 def __init__(self, settings, data_queues):
     self.name = 'JobQueue'
     self.settings = settings
     self.data_queues = data_queues
     self.incoming = collections.deque()
     self.in_progress = collections.deque()
     self.processed = collections.deque()
     self.ffmpeg = ffmpeg.FFMPEGHandle(settings)
     self.logger = data_queues["logging"].get_logger(self.name)
Example #5
0
 def __init__(self, data_queues, settings):
     super(LibraryScanner, self).__init__(name='LibraryScanner')
     self.interval = 0
     self.firstrun = True
     self.settings = settings
     self.logger = data_queues["logging"].get_logger(self.name)
     self.scheduledtasks = data_queues["scheduledtasks"]
     self.abort_flag = threading.Event()
     self.abort_flag.clear()
     self.ffmpeg = ffmpeg.FFMPEGHandle(settings)
Example #6
0
 def file_not_target_format(self, pathname):
     # init FFMPEG handle
     ffmpeg_settings = self.init_ffmpeg_handle_settings()
     ffmpeg_handle = ffmpeg.FFMPEGHandle(ffmpeg_settings)
     # Reset file in
     ffmpeg_handle.file_in = {}
     # Check if file matches configured codec and format
     if not ffmpeg_handle.check_file_to_be_processed(
             pathname, ffmpeg_settings):
         if self.settings.DEBUGGING:
             self._log(
                 "File does not need to be processed - {}".format(pathname))
         return False
     return True
Example #7
0
    def __init__(self, settings, data_queues):
        self.name = 'Task'
        self.settings = settings
        self.ffmpeg = ffmpeg.FFMPEGHandle(settings)
        self.logger = data_queues["logging"].get_logger(self.name)
        self.source = None
        self.destination = None
        self.success = False
        self.cache_path = None
        self.statistics = {}
        self.errors = []
        self.ffmpeg_log = []

        # Reset all ffmpeg info
        self.ffmpeg.set_info_defaults()
Example #8
0
    def setup_class(self):
        """
        Setup the class state for pytest.

        :return:
        """
        self.project_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
        self.tests_videos_dir = os.path.join(self.project_dir, 'tests', 'support_', 'videos')
        self.tests_tmp_dir = os.path.join(self.project_dir, 'tests', 'tmp', 'py_test_env')
        # sys.path.append(self.project_dir)
        unmanic_logging = unlogger.UnmanicLogger.__call__(False)
        unmanic_logging.get_logger()
        # import config
        from unmanic import config
        self.settings = config.CONFIG(config_path=tempfile.mkdtemp(prefix='unmanic_tests_'))
        self.settings.set_config_item('debugging', True, save_settings=False)
        ffmpeg_settings = build_ffmpeg_handle_settings(self.settings)
        self.ffmpeg = ffmpeg.FFMPEGHandle(ffmpeg_settings)
Example #9
0
    def setup_class(self):
        """
        Setup the class state for pytest.

        :return:
        """
        self.project_dir = os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
        self.tests_videos_dir = os.path.join(self.project_dir, 'tests',
                                             'support_', 'videos')
        self.tests_tmp_dir = os.path.join(self.project_dir, 'tests', 'tmp',
                                          'py_test_env')
        # sys.path.append(self.project_dir)
        unmanic_logging = unlogger.UnmanicLogger.__call__(False)
        unmanic_logging.get_logger()
        # import config
        from unmanic import config
        self.settings = config.CONFIG()
        self.settings.DEBUGGING = True
        self.ffmpeg = ffmpeg.FFMPEGHandle(self.settings)
Example #10
0
def generate_example_ffmpeg_args(config):
    """
    Configure ffmpeg object.

    :return:
    """
    dummy_probe = {
        "streams": [
            {
                "index":                0,
                "codec_name":           "h264",
                "codec_long_name":      "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
                "profile":              "Main",
                "codec_type":           "video",
                "codec_time_base":      "1/50",
                "codec_tag_string":     "avc1",
                "codec_tag":            "0x31637661",
                "width":                1280,
                "height":               720,
                "coded_width":          1280,
                "coded_height":         720,
                "has_b_frames":         0,
                "sample_aspect_ratio":  "1:1",
                "display_aspect_ratio": "16:9",
                "pix_fmt":              "yuv420p",
                "level":                31,
                "chroma_location":      "left",
                "refs":                 1,
                "is_avc":               "true",
                "nal_length_size":      "4",
                "r_frame_rate":         "25/1",
                "avg_frame_rate":       "25/1",
                "time_base":            "1/12800",
                "start_pts":            0,
                "start_time":           "0.000000",
                "duration_ts":          67584,
                "duration":             "5.280000",
                "bit_rate":             "1205959",
                "bits_per_raw_sample":  "8",
                "nb_frames":            "132",
                "disposition":          {
                    "default":          1,
                    "dub":              0,
                    "original":         0,
                    "comment":          0,
                    "lyrics":           0,
                    "karaoke":          0,
                    "forced":           0,
                    "hearing_impaired": 0,
                    "visual_impaired":  0,
                    "clean_effects":    0,
                    "attached_pic":     0,
                    "timed_thumbnails": 0
                },
                "tags":                 {
                    "creation_time": "1970-01-01T00:00:00.000000Z",
                    "language":      "und",
                    "handler_name":  "VideoHandler"
                }
            },
            {
                "index":            1,
                "codec_name":       "aac",
                "codec_long_name":  "AAC (Advanced Audio Coding)",
                "profile":          "LC",
                "codec_type":       "audio",
                "codec_time_base":  "1/48000",
                "codec_tag_string": "mp4a",
                "codec_tag":        "0x6134706d",
                "sample_fmt":       "fltp",
                "sample_rate":      "48000",
                "channels":         6,
                "channel_layout":   "5.1",
                "bits_per_sample":  0,
                "r_frame_rate":     "0/0",
                "avg_frame_rate":   "0/0",
                "time_base":        "1/48000",
                "start_pts":        0,
                "start_time":       "0.000000",
                "duration_ts":      254976,
                "duration":         "5.312000",
                "bit_rate":         "384828",
                "max_bit_rate":     "400392",
                "nb_frames":        "249",
                "disposition":      {
                    "default":          1,
                    "dub":              0,
                    "original":         0,
                    "comment":          0,
                    "lyrics":           0,
                    "karaoke":          0,
                    "forced":           0,
                    "hearing_impaired": 0,
                    "visual_impaired":  0,
                    "clean_effects":    0,
                    "attached_pic":     0,
                    "timed_thumbnails": 0
                },
                "tags":             {
                    "creation_time": "1970-01-01T00:00:00.000000Z",
                    "language":      "und",
                    "handler_name":  "SoundHandler"
                }
            }
        ],
        "format":  {
            "filename":         "/path/to/input/video.mkv",
            "nb_streams":       2,
            "nb_programs":      0,
            "format_name":      "mov,mp4,m4a,3gp,3g2,mj2",
            "format_long_name": "QuickTime / MOV",
            "start_time":       "0.000000",
            "duration":         "5.312000",
            "size":             "1055736",
            "bit_rate":         "1589963",
            "probe_score":      100,
            "tags":             {
                "major_brand":       "isom",
                "minor_version":     "512",
                "compatible_brands": "isomiso2avc1mp41",
                "creation_time":     "1970-01-01T00:00:00.000000Z",
                "encoder":           "Lavf53.24.2"
            }
        }
    }
    settings = {
        'audio_codec':                          config.AUDIO_CODEC,
        'audio_codec_cloning':                  config.AUDIO_CODEC_CLONING,
        'audio_stereo_stream_bitrate':          config.AUDIO_STEREO_STREAM_BITRATE,
        'audio_stream_encoder':                 config.AUDIO_STREAM_ENCODER,
        'cache_path':                           config.CACHE_PATH,
        'debugging':                            config.DEBUGGING,
        'enable_audio_encoding':                config.ENABLE_AUDIO_ENCODING,
        'enable_audio_stream_stereo_cloning':   config.ENABLE_AUDIO_STREAM_STEREO_CLONING,
        'enable_audio_stream_transcoding':      config.ENABLE_AUDIO_STREAM_TRANSCODING,
        'enable_video_encoding':                config.ENABLE_VIDEO_ENCODING,
        'out_container':                        config.OUT_CONTAINER,
        'remove_subtitle_streams':              config.REMOVE_SUBTITLE_STREAMS,
        'video_codec':                          config.VIDEO_CODEC,
        'video_stream_encoder':                 config.VIDEO_STREAM_ENCODER,
        'overwrite_additional_ffmpeg_options':  config.OVERWRITE_ADDITIONAL_FFMPEG_OPTIONS,
        'additional_ffmpeg_options':            config.ADDITIONAL_FFMPEG_OPTIONS,
        'enable_hardware_accelerated_decoding': config.ENABLE_HARDWARE_ACCELERATED_DECODING,
    }

    # Create ffmpeg object
    ffmpeg_obj = ffmpeg.FFMPEGHandle(settings)

    # Create commandline args from ffmpeg object
    ffmpeg_args = ffmpeg_obj.generate_ffmpeg_args(dummy_probe, '/path/to/input/video.mkv', '/path/to/output/video.mkv')

    # Return args
    return ffmpeg_args