fixing issue #249 by @GitGerby

This commit is contained in:
k4yt3x 2020-05-12 19:25:39 -04:00
parent 1be2c1ead7
commit 0c3c136458

View File

@ -4,7 +4,7 @@
Name: Video2X Upscaler Name: Video2X Upscaler
Author: K4YT3X Author: K4YT3X
Date Created: December 10, 2018 Date Created: December 10, 2018
Last Modified: May 11, 2020 Last Modified: May 12, 2020
Description: This file contains the Upscaler class. Each Description: This file contains the Upscaler class. Each
instance of the Upscaler class is an upscaler on an image or instance of the Upscaler class is an upscaler on an image or
@ -584,24 +584,33 @@ class Upscaler:
# if failed to copy streams # if failed to copy streams
# use file with only video stream # use file with only video stream
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
traceback.print_exc()
Avalon.error(_('Failed to migrate streams')) Avalon.error(_('Failed to migrate streams'))
Avalon.warning(_('Trying to output video without additional streams')) Avalon.warning(_('Trying to output video without additional streams'))
if input_file_mime_type == 'image/gif': if input_file_mime_type == 'image/gif':
(self.upscaled_frames / self.ffmpeg_object.intermediate_file_name).replace(output_path) # copy will overwrite destination content if exists
shutil.copy(self.upscaled_frames / self.ffmpeg_object.intermediate_file_name, output_path)
else: else:
# construct output file path # construct output file path
output_video_path = output_path.parent / f'{output_path.stem}{self.ffmpeg_object.intermediate_file_name.suffix}' output_file_name = f'{output_path.stem}{self.ffmpeg_object.intermediate_file_name.suffix}'
output_video_path = output_path.parent / output_file_name
# if output file already exists, cancel # if output file already exists
# create temporary directory in output folder
# temporary directories generated by tempfile are guaranteed to be unique
# and won't conflict with other files
if output_video_path.exists(): if output_video_path.exists():
Avalon.error(_('Output video file exists, aborting')) Avalon.error(_('Output video file exists'))
# otherwise, rename intermediate file to the output file temporary_directory = pathlib.Path(tempfile.mkdtemp(dir=output_path.parent))
else: output_video_path = temporary_directory / output_file_name
Avalon.info(_('Writing intermediate file to: {}').format(output_video_path.absolute())) Avalon.info(_('Created temporary directory to contain file'))
(self.upscaled_frames / self.ffmpeg_object.intermediate_file_name).rename(output_video_path)
# copy file to new destination
Avalon.info(_('Writing intermediate file to: {}').format(output_video_path.absolute()))
shutil.copy(self.upscaled_frames / self.ffmpeg_object.intermediate_file_name, output_video_path)
# increment total number of files processed # increment total number of files processed
self.cleanup_temp_directories() self.cleanup_temp_directories()