Ejemplo n.º 1
0
    def _parse_parallel_tasks_queue(
            self, worker_id):  # Unused parameter required for this function
        try:
            while True:
                active_row = self.parallel_tasks_queue.get()
                if not active_row:
                    break

                try:
                    self.encoder_queue.wait_for_standard_tasks()

                    self.encoder_queue.add_to_running_tasks(active_row)
                    self._run_parallel_encode_task(active_row)
                except:
                    logging.exception(
                        '--- FAILED TO RUN PARALLEL TASK PROCESS ---')
                finally:
                    if active_row.ffmpeg.folder_state and not active_row.ffmpeg.watch_folder:
                        GLib.idle_add(active_row.set_finished_state)
                    if not active_row.ffmpeg.watch_folder:
                        self.encoder_queue.remove_from_running_tasks(
                            active_row)

                    self.parallel_tasks_queue.task_done()
        except:
            logging.exception('--- PARALLEL TASKS THREAD FAILED ---')
    def _apply_ffmpeg_template_to_all_inputs(self):
        ffmpeg_template = self.main_window_handlers.ffmpeg_template

        for row in self.inputs_page_handlers.get_rows():
            row_ffmpeg = row.ffmpeg
            row_ffmpeg.output_container = ffmpeg_template.output_container
            row_ffmpeg.general_settings.ffmpeg_args = ffmpeg_template.general_settings.ffmpeg_args.copy(
            )

            if ffmpeg_template.video_settings:
                row_ffmpeg.video_settings = copy.deepcopy(
                    ffmpeg_template.video_settings)
            else:
                row_ffmpeg.video_settings = None

            if row_ffmpeg.input_file_info['audio_streams']:
                if ffmpeg_template.audio_settings:
                    row_ffmpeg.audio_settings = copy.deepcopy(
                        ffmpeg_template.audio_settings)
                else:
                    row.ffmpeg.audio_settings = None

            if row_ffmpeg.is_video_settings_2_pass():
                row_ffmpeg.video_settings.stats = self.application_preferences.temp_directory \
                                                  + '/' \
                                                  + row_ffmpeg.temp_file_name \
                                                  + '.log'

            GLib.idle_add(row.setup_labels)
Ejemplo n.º 3
0
    def _run_watch_folder_encode_task(self, active_row, parent_ffmpeg, folder_path):
        while True:
            if active_row.stopped:
                break

            if self.watch_folder.is_instance_empty(folder_path):
                GLib.idle_add(active_row.set_idle_state)
            active_row.started = False

            file_path = self.watch_folder.get_instance(folder_path)
            if not file_path:
                break

            if self.application_preferences.is_watch_folder_wait_for_tasks_enabled:
                self.encoder_queue.wait_for_all_tasks()
            if not self.application_preferences.is_concurrent_watch_folder_enabled:
                self.encoder_queue.wait_for_watch_folder_tasks()

            child_ffmpeg = self._generate_child_ffmpeg_from_watch_folder_task(parent_ffmpeg, file_path)
            if self._is_folder_task_valid(child_ffmpeg):
                directory_helper.fix_same_name_occurences(child_ffmpeg, self.application_preferences)

                if parent_ffmpeg.folder_auto_crop:
                    auto_crop_helper.process_auto_crop(child_ffmpeg)

                if active_row.ffmpeg.is_video_settings_nvenc():
                    self.encoder_queue.parallel_nvenc_encode_task.wait_until_nvenc_available(active_row)

                self.encoder_queue.run_folder_encode_task(active_row, child_ffmpeg, watch_folder=True)

                if self.application_preferences.is_watch_folder_move_tasks_to_done_enabled:
                    self._move_input_file_to_done_folder(child_ffmpeg.input_file)
Ejemplo n.º 4
0
 def _setup_importing_files_widgets(self, file_path, input_index,
                                    length_of_input_files):
     GLib.idle_add(self.inputs_page_handlers.set_importing_file_path_text,
                   file_path)
     GLib.idle_add(
         self.inputs_page_handlers.set_importing_progress_fraction,
         (input_index / length_of_input_files))
Ejemplo n.º 5
0
 def setup_preview_thumbnail(self):
     """
     Generates and applies a preview thumbnail.
     """
     output_file = preview.generate_crop_preview_file(
         self.ffmpeg, self.application_preferences, preview_height=96)
     GLib.idle_add(self.inputs_listbox_row_preview_icon.set_from_file,
                   output_file)
Ejemplo n.º 6
0
    def update_settings(self):
        for row in self.inputs_page_handlers.get_selected_rows():
            ffmpeg = row.ffmpeg
            self.apply_settings(ffmpeg)

            GLib.idle_add(row.setup_labels)

        GLib.idle_add(self.inputs_page_handlers.update_preview_page)
    def toggle_settings_sidebar(self, is_closing_settings_sidebar=False):
        if is_closing_settings_sidebar:
            is_toggled_settings_sidebar_visible = False
        else:
            is_toggled_settings_sidebar_visible = not self.settings_sidebar_box.get_visible()

        if is_toggled_settings_sidebar_visible:
            GLib.idle_add(self.inputs_page_paned.set_position,
                          (self.main_window.get_size().width - self.inputs_page_paned_position))

        self.settings_sidebar_box.set_visible(is_toggled_settings_sidebar_visible)
Ejemplo n.º 8
0
    def setup_autocrop(self):
        """
        Detects and applies a crop to remove "black bars" if applicable.
        """
        ffmpeg = self.crop_page_handlers.ffmpeg

        if auto_crop_helper.process_auto_crop(ffmpeg):
            ffmpeg.picture_settings.auto_crop_enabled = True

            self.crop_page_handlers.set_crop_thumbnail()
        else:
            GLib.idle_add(self._show_autocrop_not_needed_dialog)
            GLib.idle_add(self.crop_page_handlers.set_auto_crop_state, False)
Ejemplo n.º 9
0
    def _add_inputs(self, inputs, file_chooser_response, file_inputs_enabled):
        filtered_inputs = self._get_filtered_inputs(inputs,
                                                    file_inputs_enabled)
        output_dir = self.main_window_handlers.get_output_chooser_dir()

        if file_chooser_response == Gtk.ResponseType.OK and filtered_inputs:
            GLib.idle_add(
                lambda: self.main_window_handlers.set_processing_inputs_state(
                    True, filtered_inputs[0]))

            threading.Thread(target=self._process_inputs,
                             args=(filtered_inputs, output_dir,
                                   file_inputs_enabled),
                             daemon=True).start()
Ejemplo n.º 10
0
    def _parse_standard_tasks_queue(self):
        while True:
            active_row = self.standard_tasks_queue.get()
            if not active_row:
                break

            self.encoder_queue.wait_for_parallel_tasks()
            self.encoder_queue.add_to_running_tasks(active_row)
            self._run_standard_encode_task(active_row)

            if active_row.ffmpeg.folder_state and not active_row.ffmpeg.watch_folder:
                GLib.idle_add(active_row.set_finished_state)
            if not active_row.ffmpeg.watch_folder:
                self.encoder_queue.remove_from_running_tasks(active_row)

            self.standard_tasks_queue.task_done()
Ejemplo n.º 11
0
    def update_settings(self):
        codec_settings = None

        for row in self.inputs_page_handlers.get_selected_rows():
            ffmpeg = row.ffmpeg
            self.get_settings(ffmpeg)

            if codec_settings is None:
                codec_settings = ffmpeg.video_settings

            GLib.idle_add(row.setup_labels)

        threading.Thread(target=NvidiaHelper.is_codec_settings_valid,
                         args=(codec_settings,
                               self.main_window_handlers.main_window)).start()
        GLib.idle_add(self.inputs_page_handlers.update_preview_page)
Ejemplo n.º 12
0
    def is_codec_settings_valid(video_codec_settings, main_window):
        from render_watch.ffmpeg.settings import Settings

        ffmpeg_args = Settings.FFMPEG_INIT_ARGS.copy()
        ffmpeg_args.append('-f')
        ffmpeg_args.append('lavfi')
        ffmpeg_args.append('-i')
        ffmpeg_args.append('nullsrc=s=256x256:d=5')
        ffmpeg_args.extend(Settings.generate_video_settings_args(video_codec_settings.ffmpeg_args))
        ffmpeg_args.extend(Settings.generate_video_settings_args(video_codec_settings.get_ffmpeg_advanced_args()))
        ffmpeg_args.append('-f')
        ffmpeg_args.append('null')
        ffmpeg_args.append('-')

        if not NvidiaHelper._run_test_process(ffmpeg_args):
            GLib.idle_add(NvidiaHelper._show_codec_settings_not_supported_message, main_window)
Ejemplo n.º 13
0
def _run_vid_preview_encode_process(ffmpeg, preview_duration,
                                    preview_page_handlers, stop_preview):
    ffmpeg_args = _get_vid_preview_ffmpeg_args(ffmpeg)
    process_return_code = -1

    for encode_pass, args in enumerate(ffmpeg_args):
        with subprocess.Popen(args,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT,
                              universal_newlines=True,
                              bufsize=1) as vid_preview_encode_process:
            while True:
                if stop_preview():
                    vid_preview_encode_process.terminate()
                    break

                process_stdout = vid_preview_encode_process.stdout.readline(
                ).strip()
                if process_stdout == '' and vid_preview_encode_process.poll(
                ) is not None:
                    break

                try:
                    current_timecode = re.search(
                        'time=\d+:\d+:\d+\.\d+|time=\s+\d+:\d+:\d+\.\d+',
                        process_stdout).group().split('=')[1]
                    current_time_in_seconds = format_converter.get_seconds_from_timecode(
                        current_timecode)

                    if encode_pass == 0:
                        progress = (current_time_in_seconds /
                                    preview_duration) / len(ffmpeg_args)
                    else:
                        progress = .5 + (
                            (current_time_in_seconds / preview_duration) /
                            len(ffmpeg_args))

                    GLib.idle_add(preview_page_handlers.set_progress_fraction,
                                  progress)
                except:
                    continue

            process_return_code = vid_preview_encode_process.wait()
        if process_return_code != 0:
            LoggingHelper.log_encoder_error(
                ffmpeg, '--- VIDEO PREVIEW ENCODE PROCESS FAILED ---')
    return process_return_code == 0
Ejemplo n.º 14
0
    def _add_active_page_task_chunks_to_encoder(self, active_page_task):
        chunks = encoder_helper.get_chunks(self.ffmpeg,
                                           self.application_preferences)

        if chunks:
            for index, ffmpeg in enumerate(chunks):
                chunk_row = ChunkRow(ffmpeg, (index + 1), active_page_task)

                if (index + 1) == len(chunks):
                    GLib.idle_add(active_page_task.add_audio_chunk_row,
                                  chunk_row)
                else:
                    GLib.idle_add(active_page_task.add_chunk_row, chunk_row)

                self.encoder_queue.add_active_row(chunk_row)
        else:
            self.encoder_queue.add_active_row(active_page_task)
    def _parse_parallel_nvenc_tasks_queue(
            self, worker_id):  # Unused parameter required for this function
        while True:
            active_row = self.parallel_nvenc_tasks_queue.get()
            if not active_row:
                break

            self.wait_until_nvenc_available(active_row)
            self.encoder_queue.wait_for_standard_tasks()

            self.encoder_queue.add_to_running_tasks(active_row)
            self._run_parallel_nvenc_encode_task(active_row)

            if active_row.ffmpeg.folder_state and not active_row.ffmpeg.watch_folder:
                GLib.idle_add(active_row.set_finished_state)
            if not active_row.ffmpeg.watch_folder:
                self.encoder_queue.remove_from_running_tasks(active_row)

            self.parallel_nvenc_tasks_queue.task_done()
Ejemplo n.º 16
0
    def _process_inputs(self, inputs, output_dir, file_inputs_enabled):
        self._setup_settings_sidebar_ffmpeg_template()

        length_of_input_files = len(inputs)

        for index, file_path in enumerate(inputs):
            self._setup_importing_files_widgets(file_path, index,
                                                length_of_input_files)

            ffmpeg = Settings()
            self._setup_input_file_paths(ffmpeg, file_path, output_dir,
                                         file_inputs_enabled)

            if self._input_exists(ffmpeg):
                GLib.idle_add(self._show_input_exists_dialog, ffmpeg)

                continue

            if InputInformation.generate_input_information(ffmpeg):
                if self.inputs_page_handlers.is_apply_all_selected():
                    self._apply_ffmpeg_template_settings(ffmpeg)

                self._setup_picture_settings(ffmpeg, file_inputs_enabled)
                ffmpeg.setup_subtitles_settings()

                GLib.idle_add(self._add_to_inputs_page, ffmpeg)

        GLib.idle_add(lambda: self.main_window_handlers.
                      set_processing_inputs_state(False, None))
Ejemplo n.º 17
0
    def _set_preview_thumbnail(self):
        GLib.idle_add(self.preview_icon.set_opacity, 0.5)
        output_file = preview.generate_preview_file(
            self.ffmpeg, self._preview_queue.get(),
            self.application_preferences)

        if not self._preview_queue.empty():
            return

        if output_file is None:
            GLib.idle_add(self.preview_stack.set_visible_child,
                          self.preview_wrong_codec_label)
            GLib.idle_add(self.preview_selection_box.set_sensitive, False)

            return

        self.image_buffer = GdkPixbuf.Pixbuf.new_from_file(output_file)

        viewport_width = self.preview_viewport.get_allocated_width()
        viewport_height = self.preview_viewport.get_allocated_height()
        GLib.idle_add(self.set_thumbnail_size, viewport_width, viewport_height)
        GLib.idle_add(self.preview_icon.set_opacity, 1.0)
Ejemplo n.º 18
0
    def _resize_thumbnail(self, width, height):
        self.image_scaled_buffer = self.image_buffer.scale_simple(
            width, height, GdkPixbuf.InterpType.BILINEAR)

        GLib.idle_add(self.preview_icon.set_from_pixbuf,
                      self.image_scaled_buffer)
        GLib.idle_add(self.preview_stack.set_visible_child, self.preview_icon)
        GLib.idle_add(self.preview_icon.set_opacity, 1)
    def _parse_per_codec_queue(
            self, worker_id,
            codec_queue):  # Unused parameter required for this function
        try:
            while True:
                if codec_queue.empty():
                    self._remove_codec_queue_from_per_codec_tasks_list(
                        codec_queue)

                active_row = codec_queue.get()
                if not active_row:
                    break

                nvenc_skip = active_row.ffmpeg.is_video_settings_nvenc() \
                             and active_row.ffmpeg.folder_state \
                             and not active_row.ffmpeg.watch_folder

                try:
                    self.encoder_queue.wait_for_standard_tasks()
                    self._wait_for_current_codec_queue(codec_queue)

                    self.encoder_queue.add_to_running_tasks(active_row)
                    self._run_per_codec_encode_task(active_row, codec_queue)
                except:
                    logging.exception(
                        '--- FAILED TO RUN PER CODEC PARALLEL TASK PROCESS ---'
                    )
                finally:
                    if not nvenc_skip:
                        if active_row.ffmpeg.folder_state and not active_row.ffmpeg.watch_folder:
                            GLib.idle_add(active_row.set_finished_state)
                        if not active_row.ffmpeg.watch_folder:
                            self.encoder_queue.remove_from_running_tasks(
                                active_row)

                    codec_queue.task_done()
        except:
            logging.exception('--- PER CODEC PARALLEL TASKS THREAD FAILED ---')
Ejemplo n.º 20
0
 def _update_settings_sidebar(self):
     GLib.idle_add(self.settings_sidebar_handlers.set_settings)
Ejemplo n.º 21
0
 def process_row_input(self):
     """
     Sends task to the active page for encoding.
     """
     self._fix_same_name_occurrences()
     GLib.idle_add(self._add_task_to_active_page)
Ejemplo n.º 22
0
    def _set_active_row_finished_state(active_row, folder_state):
        active_row.progress = 1.0

        if not folder_state:
            GLib.idle_add(active_row.set_finished_state)
Ejemplo n.º 23
0
 def _update_selected_row(self):
     row = self.inputs_page_handlers.get_selected_row()
     GLib.idle_add(row.setup_labels)
     row.setup_preview_thumbnail()
Ejemplo n.º 24
0
def _set_benchmark_widgets_start_state(settings_sidebar_handlers):
    GLib.idle_add(settings_sidebar_handlers.set_benchmark_start_state)
Ejemplo n.º 25
0
 def _remove_burn_in_for_other_streams(self, selected_subtitle_stream_row):
     for subtitle_stream_row in self.subtitle_streams_list:
         if subtitle_stream_row is not selected_subtitle_stream_row:
             GLib.idle_add(subtitle_stream_row.remove_burn_in_method)
Ejemplo n.º 26
0
def _run_benchmark_process(ffmpeg, settings_sidebar_handlers, duration, origin_duration):
    ffmpeg_args = ffmpeg_helper.get_parsed_ffmpeg_args(ffmpeg)
    speed_value = 0
    file_size_value = None

    for encode_pass, args in enumerate(ffmpeg_args):
        with subprocess.Popen(
                args,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                universal_newlines=True,
                bufsize=1) as benchmark_process:
            while True:
                with settings_sidebar_handlers.benchmark_thread_lock:
                    if settings_sidebar_handlers.is_benchmark_thread_stopping:
                        os.kill(benchmark_process.pid, signal.SIGKILL)
                        break

                stdout = benchmark_process.stdout.readline().strip()
                if not stdout:
                    break

                try:
                    bitrate_value = _get_bitrate(stdout)
                    file_size_value = _get_current_file_size(stdout)
                    speed_value = _get_speed(stdout)
                    current_time = _get_current_time(stdout)

                    if encode_pass == 0:
                        progress = (current_time / duration) / len(ffmpeg_args)
                    else:
                        progress = .5 + ((current_time / duration) / len(ffmpeg_args))

                    GLib.idle_add(settings_sidebar_handlers.set_benchmark_progress_bar_fraction, progress)
                    GLib.idle_add(settings_sidebar_handlers.set_benchmark_bitrate_label_text,
                                  str(bitrate_value) + 'kbits/s')
                    GLib.idle_add(settings_sidebar_handlers.set_benchmark_speed_label_text, str(speed_value) + 'x')
                except:
                    continue

        benchmark_process.wait()

    try:
        if speed_value is not None:
            time_estimate = (origin_duration * len(ffmpeg_args)) / speed_value
            timecode = format_converter.get_timecode_from_seconds(time_estimate)
            GLib.idle_add(settings_sidebar_handlers.set_benchmark_process_time_label_text, timecode)
    except ZeroDivisionError:
        logging.error('--- BENCHMARK SPEED LABEL CAN\'T BE SET ---')

    if file_size_value is not None:
        total_file_size = _get_final_file_size(file_size_value, origin_duration, duration)
        GLib.idle_add(settings_sidebar_handlers.set_benchmark_file_size_label_text, total_file_size)

    process_return_code = benchmark_process.poll()

    GLib.idle_add(settings_sidebar_handlers.set_benchmark_done_state)

    if process_return_code != 0:
        with settings_sidebar_handlers.benchmark_thread_lock:
            if settings_sidebar_handlers.is_benchmark_thread_stopping:
                GLib.idle_add(settings_sidebar_handlers.set_benchmark_ready_state)
            else:
                logging.error('--- BENCHMARK PROCESS FAILED ---\n' + str(ffmpeg.get_args()))
    return process_return_code == 0
Ejemplo n.º 27
0
def _reset_vid_preview_widgets(preview_page_handlers):
    GLib.idle_add(preview_page_handlers.reset_preview_buttons)
Ejemplo n.º 28
0
 def _start_update_thumbnail_thread(self, ffmpeg):
     thumbnail_file_path = preview.generate_crop_preview_file(
         ffmpeg, self.application_preferences, 96)
     GLib.idle_add(self.completed_listbox_row_preview_icon.set_from_file,
                   thumbnail_file_path)
 def _reset_settings_sidebar(self):
     GLib.idle_add(self.settings_sidebar_handlers.reset_settings)
 def _setup_settings_sidebar(self, ffmpeg):
     GLib.idle_add(self.settings_sidebar_handlers.set_settings, ffmpeg)