From 99abb4f6df616f698655e7f530ba682e8dd502e9 Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Thu, 14 May 2020 19:56:06 -0400 Subject: [PATCH] 2.1.0: added FFmpeg Settings tab --- src/video2x_gui.py | 129 ++++- src/video2x_gui.pyproject.user | 2 +- src/video2x_gui.ui | 900 ++++++++++++++++++++++++++++++--- 3 files changed, 955 insertions(+), 76 deletions(-) diff --git a/src/video2x_gui.py b/src/video2x_gui.py index f285a8e..2bdf2f1 100755 --- a/src/video2x_gui.py +++ b/src/video2x_gui.py @@ -4,7 +4,7 @@ Creator: Video2X GUI Author: K4YT3X Date Created: May 5, 2020 -Last Modified: May 12, 2020 +Last Modified: May 14, 2020 """ # local imports @@ -30,7 +30,7 @@ from PyQt5.QtWidgets import * import magic # QObject, pyqtSlot, pyqtSignal, QRunnable, QThreadPool, QAbstractTableModel, Qt -VERSION = '2.0.0' +VERSION = '2.1.0' LEGAL_INFO = f'''Video2X GUI Version: {VERSION}\\ Author: K4YT3X\\ @@ -345,7 +345,38 @@ class Video2XMainWindow(QMainWindow): self.anime4kcpp_gpu_mode_check_box = self.findChild(QCheckBox, 'anime4kCppGpuModeCheckBox') # FFmpeg settings - pass + # global options + self.ffmpeg_path_line_edit = self.findChild(QLineEdit, 'ffmpegPathLineEdit') + self.enable_line_edit_file_drop(self.ffmpeg_path_line_edit) + self.ffmpeg_path_select_button = self.findChild(QPushButton, 'ffmpegPathSelectButton') + self.ffmpeg_path_select_button.clicked.connect(lambda: self.select_driver_binary_path(self.ffmpeg_path_line_edit)) + self.ffmpeg_intermediate_file_name_line_edit = self.findChild(QLineEdit, 'ffmpegIntermediateFileNameLineEdit') + + # extract frames + self.ffmpeg_extract_frames_output_options_pixel_format_line_edit = self.findChild(QLineEdit, 'ffmpegExtractFramesOutputOptionsPixelFormatLineEdit') + self.ffmpeg_extract_frames_hardware_acceleration_check_box = self.findChild(QCheckBox, 'ffmpegExtractFramesHardwareAccelerationCheckBox') + + # assemble video + self.ffmpeg_assemble_video_input_options_force_format_line_edit = self.findChild(QLineEdit, 'ffmpegAssembleVideoInputOptionsForceFormatLineEdit') + self.ffmpeg_assemble_video_output_options_video_codec_line_edit = self.findChild(QLineEdit, 'ffmpegAssembleVideoOutputOptionsVideoCodecLineEdit') + self.ffmpeg_assemble_video_output_options_pixel_format_line_edit = self.findChild(QLineEdit, 'ffmpegAssembleVideoOutputOptionsPixelFormatLineEdit') + self.ffmpeg_assemble_video_output_options_crf_spin_box = self.findChild(QSpinBox, 'ffmpegAssembleVideoOutputOptionsCrfSpinBox') + self.ffmpeg_assemble_video_output_options_bitrate_line_edit = self.findChild(QLineEdit, 'ffmpegAssembleVideoOutputOptionsBitrateLineEdit') + self.ffmpeg_assemble_video_hardware_acceleration_check_box = self.findChild(QCheckBox, 'ffmpegAssembleVideoHardwareAccelerationCheckBox') + + # migrate_streams + self.ffmpeg_migrate_streams_output_options_mapping_video_check_box_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsMappingVideoCheckBox') + self.ffmpeg_migrate_streams_output_options_mapping_audio_check_box_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsMappingAudioCheckBox') + self.ffmpeg_migrate_streams_output_options_mapping_subtitle_check_box_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsMappingSubtitleCheckBox') + self.ffmpeg_migrate_streams_output_options_mapping_data_check_box_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsMappingDataCheckBox') + self.ffmpeg_migrate_streams_output_options_mapping_font_check_box_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsMappingFontCheckBox') + self.ffmpeg_migrate_streams_output_options_pixel_format_line_edit = self.findChild(QLineEdit, 'ffmpegMigrateStreamsOutputOptionsPixelFormatLineEdit') + self.ffmpeg_migrate_streams_output_options_copy_codec_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsCopyCodecCheckBox') + self.ffmpeg_migrate_streams_output_options_copy_known_metadata_tags_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsOtherCopyKnownMetadataTagsCheckBox') + self.ffmpeg_migrate_streams_output_options_copy_arbitrary_metadata_tags_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsOutputOptionsOtherCopyArbitraryMetadataTagsCheckBox') + self.ffmpeg_migrate_streams_hardware_acceleration_check_box = self.findChild(QCheckBox, 'ffmpegMigrateStreamsHardwareAccelerationCheckBox') + + # Gifski settings # Tools self.ffprobe_plain_text_edit = self.findChild(QPlainTextEdit, 'ffprobePlainTextEdit') @@ -491,6 +522,28 @@ class Video2XMainWindow(QMainWindow): self.anime4kcpp_post_processing_check_box.setChecked(settings['postprocessing']) self.anime4kcpp_gpu_mode_check_box.setChecked(settings['GPUMode']) + # ffmpeg + # global options + settings = self.config['ffmpeg'] + self.ffmpeg_path_line_edit.setText(str(pathlib.Path(os.path.expandvars(settings['ffmpeg_path'])).absolute())) + self.ffmpeg_intermediate_file_name_line_edit.setText(settings['intermediate_file_name']) + + # extract frames + settings = self.config['ffmpeg']['extract_frames'] + self.ffmpeg_extract_frames_output_options_pixel_format_line_edit.setText(settings['output_options']['-pix_fmt']) + + # assemble video + settings = self.config['ffmpeg']['assemble_video'] + self.ffmpeg_assemble_video_input_options_force_format_line_edit.setText(settings['input_options']['-f']) + self.ffmpeg_assemble_video_output_options_video_codec_line_edit.setText(settings['output_options']['-vcodec']) + self.ffmpeg_assemble_video_output_options_pixel_format_line_edit.setText(settings['output_options']['-pix_fmt']) + self.ffmpeg_assemble_video_output_options_crf_spin_box.setValue(settings['output_options']['-crf']) + self.ffmpeg_assemble_video_output_options_bitrate_line_edit.setText(settings['output_options']['-b:v']) + + # migrate streams + settings = self.config['ffmpeg']['migrate_streams'] + self.ffmpeg_migrate_streams_output_options_pixel_format_line_edit.setText(settings['output_options']['-pix_fmt']) + def resolve_driver_settings(self): # waifu2x-caffe @@ -557,6 +610,76 @@ class Video2XMainWindow(QMainWindow): self.config['anime4kcpp']['postprocessing'] = bool(self.anime4kcpp_post_processing_check_box.isChecked()) self.config['anime4kcpp']['GPUMode'] = bool(self.anime4kcpp_gpu_mode_check_box.isChecked()) + # ffmpeg + self.config['ffmpeg']['ffmpeg_path'] = os.path.expandvars(self.ffmpeg_path_line_edit.text()) + self.config['ffmpeg']['intermediate_file_name'] = self.ffmpeg_intermediate_file_name_line_edit.text() + + # extract frames + self.config['ffmpeg']['extract_frames']['output_options']['-pix_fmt'] = self.ffmpeg_extract_frames_output_options_pixel_format_line_edit.text() + if self.ffmpeg_extract_frames_hardware_acceleration_check_box.isChecked(): + self.config['ffmpeg']['extract_frames']['-hwaccel'] = 'auto' + else: + self.config['ffmpeg']['extract_frames'].pop('-hwaccel', None) + + # assemble video + self.config['ffmpeg']['assemble_video']['input_options']['-f'] = self.ffmpeg_assemble_video_input_options_force_format_line_edit.text() + self.config['ffmpeg']['assemble_video']['output_options']['-vcodec'] = self.ffmpeg_assemble_video_output_options_video_codec_line_edit.text() + self.config['ffmpeg']['assemble_video']['output_options']['-pix_fmt'] = self.ffmpeg_assemble_video_output_options_pixel_format_line_edit.text() + self.config['ffmpeg']['assemble_video']['output_options']['-crf'] = self.ffmpeg_assemble_video_output_options_crf_spin_box.value() + if self.ffmpeg_assemble_video_output_options_bitrate_line_edit.text() != '': + self.config['ffmpeg']['assemble_video']['output_options']['-b:v'] = self.ffmpeg_assemble_video_output_options_bitrate_line_edit.text() + else: + self.config['ffmpeg']['assemble_video']['output_options']['-b:v'] = None + if self.ffmpeg_assemble_video_hardware_acceleration_check_box.isChecked(): + self.config['ffmpeg']['assemble_video']['-hwaccel'] = 'auto' + else: + self.config['ffmpeg']['assemble_video'].pop('-hwaccel', None) + + # migrate streams + + self.config['ffmpeg']['migrate_streams']['output_options']['-map'] = [] + if self.ffmpeg_migrate_streams_output_options_mapping_video_check_box_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-map'].append('0:v?') + if self.ffmpeg_migrate_streams_output_options_mapping_audio_check_box_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-map'].append('1:a?') + if self.ffmpeg_migrate_streams_output_options_mapping_subtitle_check_box_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-map'].append('1:s?') + if self.ffmpeg_migrate_streams_output_options_mapping_data_check_box_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-map'].append('1:d?') + if self.ffmpeg_migrate_streams_output_options_mapping_font_check_box_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-map'].append('1:t?') + + # if the list is empty, delete the key + # otherwise parser will run into an error (key with no value) + if len(self.config['ffmpeg']['migrate_streams']['output_options']['-map']) == 0: + self.config['ffmpeg']['migrate_streams']['output_options'].pop('-map', None) + + self.config['ffmpeg']['migrate_streams']['output_options']['-pix_fmt'] = self.ffmpeg_migrate_streams_output_options_pixel_format_line_edit.text() + + # copy source codec + if self.ffmpeg_migrate_streams_output_options_copy_codec_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-c'] = 'copy' + else: + self.config['ffmpeg']['migrate_streams']['output_options'].pop('-c', None) + + # copy known metadata + if self.ffmpeg_migrate_streams_output_options_copy_known_metadata_tags_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-map_metadata'] = 0 + else: + self.config['ffmpeg']['migrate_streams']['output_options'].pop('-map_metadata', None) + + # copy arbitrary metadata + if self.ffmpeg_migrate_streams_output_options_copy_arbitrary_metadata_tags_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['output_options']['-movflags'] = 'use_metadata_tags' + else: + self.config['ffmpeg']['migrate_streams']['output_options'].pop('-movflags', None) + + # hardware acceleration + if self.ffmpeg_migrate_streams_hardware_acceleration_check_box.isChecked(): + self.config['ffmpeg']['migrate_streams']['-hwaccel'] = 'auto' + else: + self.config['ffmpeg']['migrate_streams'].pop('-hwaccel', None) + def update_gui_for_driver(self): current_driver = AVAILABLE_DRIVERS[self.driver_combo_box.currentText()] diff --git a/src/video2x_gui.pyproject.user b/src/video2x_gui.pyproject.user index 57ea1d7..22e63d9 100644 --- a/src/video2x_gui.pyproject.user +++ b/src/video2x_gui.pyproject.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/video2x_gui.ui b/src/video2x_gui.ui index 2588b15..54ad3ad 100644 --- a/src/video2x_gui.ui +++ b/src/video2x_gui.ui @@ -6,8 +6,8 @@ 0 0 - 667 - 768 + 671 + 802 @@ -33,7 +33,7 @@ - 3 + 0 @@ -78,6 +78,22 @@ + + + + + 16777215 + 15 + + + + **Hover over an item to see its description (if applicable).** + + + Qt::MarkdownText + + + @@ -253,6 +269,9 @@ + + Driver to use for upscaling. Waifu2x Caffe is only for Nvidia GPUs. + Waifu2X Caffe @@ -293,6 +312,9 @@ + + Number of processes/threads to launch. Going to high for Waifu2X drivers might GPU's VRAM space. + 1 @@ -311,6 +333,9 @@ + + <html><head/><body><p>Number of times to enlarge the video. Larger values will increase the time needed drastically.</p></body></html> + 0.000000000000000 @@ -329,6 +354,9 @@ + + Check this to prevent Video2X from cleaning up its cache folder containing extracted and upscaled frames. + Preserve Frames @@ -444,6 +472,9 @@ + + custom scale width (specifying this will overwrite scale_ratio) + 999999 @@ -462,6 +493,9 @@ + + custom scale height (specifying this will overwrite scale_ratio) + 999999 @@ -480,6 +514,9 @@ + + image processing mode + noise_scale @@ -515,6 +552,9 @@ + + noise reduction level + 3 @@ -536,6 +576,9 @@ + + process mode, cudnn requires CUDA and cuDNN to be installed + gpu @@ -566,6 +609,9 @@ + + name of the built-in model to use + cunet @@ -621,6 +667,9 @@ + + input image split size + 9999 @@ -642,6 +691,9 @@ + + output image quality + -1 @@ -663,6 +715,9 @@ + + output image chanel depth bit + 9999 @@ -684,6 +739,9 @@ + + input batch size + 9999 @@ -704,7 +762,11 @@ - + + + gpu device no + + @@ -712,13 +774,29 @@ + + 8x slower and slightly high quality + - TTA (Test-Time Augmentation) + TTA + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -938,12 +1016,25 @@ - TTA (Test-Time Augmentation) + TTA + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -1077,12 +1168,25 @@ - TTA (Test-Time Augmentation) + TTA + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -1209,12 +1313,25 @@ - TTA (Test-Time Augmentation) + TTA + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -1222,6 +1339,48 @@ Anime4K CPP + + + + + + Threads + + + + + + + 99999 + + + 16 + + + + + + + + + + + Passes + + + + + + + 99999 + + + 2 + + + + + @@ -1264,22 +1423,25 @@ - - + + - + - Threads + Strength Gradient - + - 99999 + 1.000000000000000 + + + 0.100000000000000 - 16 + 1.000000000000000 @@ -1364,30 +1526,6 @@ - - - - - - Post-Filters - - - - - - - 1 - - - 99999 - - - 40 - - - - - @@ -1433,27 +1571,6 @@ - - - - - - Passes - - - - - - - 99999 - - - 2 - - - - - @@ -1489,30 +1606,43 @@ - - + + - + - Strength Gradient + Post-Filters - - - 1.000000000000000 + + + 1 - - 0.100000000000000 + + 99999 - 1.000000000000000 + 40 + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -1523,6 +1653,628 @@ FFmpeg Settings + + + + + 0 + + + + Global Options + + + + + + + + + + + Select FFmpeg Binary Directory + + + + + + + + + + + Intermediate File Name + + + + + + + intermediate.mkv + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Frame Extraction + + + + + + Input Options + + + + + + There are no input options for this stage. + + + + + + + + + + Output Options + + + + + + + + Pixel Format (-pix_fmt) + + + + + + + rgba64be + + + + + + + + + + + + General + + + + + + Hardware Acceleration (-hwaccel auto) + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Video Assembly + + + + + + Input Options + + + + + + + + Force Format (-f) + + + + + + + + 0 + 0 + + + + image2 + + + + + + + + + + + + Output Options + + + + + + + + Video Codec (-vcodec) + + + + + + + + 0 + 0 + + + + libx264 + + + + + + + + + + + Pixel Format (-pix_fmt) + + + + + + + + 0 + 0 + + + + yuv444p10le + + + + + + + + + + + H.264/H.265 Constant Rate Factor (-crf) + + + + + + + 51 + + + 17 + + + + + + + + + + + Target Average Bitrate (-b:v) + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + General + + + + + + Hardware Acceleration (-hwaccel auto) + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Streams Migration + + + + + + Input Options + + + + + + There are no input options for this stage. + + + + + + + + + + Output Options + + + + + + Mapping + + + + + + Copy additional video streams (-map 0:v?) + + + true + + + + + + + Copy audio streams (-map 1:a?) + + + true + + + + + + + Copy subtitle streams (-map 1:s?) + + + true + + + + + + + Copy data streams (-map 1:d?) + + + true + + + + + + + Copy fonts (-map 1:t?) + + + true + + + + + + + + + + Other Options + + + + + + + + Pixel Format (-pix_fmt) + + + + + + + + + + + + Copy codec + + + true + + + + + + + Copy known metadata tags + + + true + + + + + + + Copy arbitrary metadata tags + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + Switches + + + + + + Hardware Acceleration (-hwaccel auto) + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Gifski Settings + + + + + + + + + + + Select Gifski Binary + + + + + + + + + + + Quality + + + + + + + 1 + + + 100 + + + 100 + + + + + + + + + + + Width + + + + + + + + + + + + + + Height + + + + + + + + + + + + Switches + + + + + + Fast + + + + + + + Once + + + + + + + Quiet + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + @@ -1540,7 +2292,11 @@ - + + + Drop a file in this box to get its FFprobe output. + + @@ -1737,7 +2493,7 @@ 0 0 - 667 + 671 21