FFMpeg-Compressor: Add ForceCompress parameter

This commit is contained in:
OleSTEEP 2024-01-15 22:20:23 +03:00
parent c1b57bddf2
commit 248f08c7d9
4 changed files with 17 additions and 12 deletions

View file

@ -10,6 +10,7 @@ Python utility uses ffmpeg to compress Visual Novel Resources
### Configuration
#### FFMPEG section
* CopyUnprocessed - Copy all files that failed to compress by ffmpeg to destination folder. In can helps to recreate original folder, but with compressed files.
* ForceCompress - Force try to compress all files in directory via ffmpeg. (default: `false`)
* MimicMode - Rename compressed file to it original name and extension. VN engines determine the file type by its header, so for example PNG file named file.jpg will be loaded as PNG file. (default: `false`)
* HideErrors - Hide some errors about compression. (default: `false`)
* WebpRGBA - Alpha channel in webp. If false switches extension to png. (default: `true`)

View file

@ -1,5 +1,6 @@
[FFMPEG]
CopyUnprocessed = false
ForceCompress = false
MimicMode = false
HideErrors = false
WebpRGBA = true

View file

@ -86,16 +86,19 @@ def compress_image(folder, file, target_folder, extension):
def compress(folder, file, target_folder):
printer.unknown_file(file)
try:
(ffmpeg
.input(f'{folder}/{file}')
.output(f'{target_folder}/{file}')
.run(quiet=True)
)
except ffmpeg._run.Error as e:
if configloader.config["FFMPEG"]["ForceCompress"]:
printer.unknown_file(file)
try:
(ffmpeg
.input(f'{folder}/{file}')
.output(f'{target_folder}/{file}')
.run(quiet=True)
)
except ffmpeg._run.Error as e:
utils.add_unprocessed_file(f'{folder}/{file}', f'{target_folder}/{file}')
utils.errors_count += 1
if not configloader.config['FFMPEG']['HideErrors']:
printer.error(f"File {file} can't be processed! Error: {e}")
else:
utils.add_unprocessed_file(f'{folder}/{file}', f'{target_folder}/{file}')
utils.errors_count += 1
if not configloader.config['FFMPEG']['HideErrors']:
printer.error(f"File {file} can't be processed! Error: {e}")
return f'{target_folder}/{file}'

View file

@ -38,7 +38,7 @@ def files(source, dest, dest_ext, comment):
def unknown_file(file):
print(clean_str(f"\r* \033[0;33m{file}\033[0m (Not recognized)"))
print(clean_str(f"\r* \033[0;33m{file}\033[0m (File will be force compressed wia ffmpeg)"))
bar.next()