Skip to content

Commit

Permalink
Merge pull request #434 from k4yt3x/black
Browse files Browse the repository at this point in the history
Formatted code with Black and updated README
  • Loading branch information
k4yt3x committed Dec 21, 2020
2 parents 0934570 + bd6690f commit 095d40b
Show file tree
Hide file tree
Showing 15 changed files with 2,122 additions and 1,145 deletions.
52 changes: 1 addition & 51 deletions README.md
Expand Up @@ -8,7 +8,7 @@
![GitHub All Releases](https://img.shields.io/github/downloads/k4yt3x/video2x/total?style=flat-square)
![GitHub](https://img.shields.io/github/license/k4yt3x/video2x?style=flat-square)
![Platforms](https://img.shields.io/badge/Platforms-Windows%20%7C%20Linux%20%7C%20macOS-blue?style=flat-square)
![Become A Patron!](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.herokuapp.com%2Fk4yt3x&style=flat-square)
![Become A Patron!](https://img.shields.io/badge/dynamic/json?color=%23e85b46&label=Patreon&query=data.attributes.patron_count&suffix=%20patrons&url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F4507807&style=flat-square)

<!--# Video2X Lossless Video Enlarger-->

Expand Down Expand Up @@ -232,56 +232,6 @@ Are you interested in how the idea of Video2X was born? Do you want to know the

---

# Full Usage

## Video2X Options

### -h, --help
show this help message and exit

### -i INPUT, --input INPUT
source video file/directory

### -o OUTPUT, --output OUTPUT
output video file/directory

### -c CONFIG, --config CONFIG
video2x config file path

### --log LOG
log file path (default: program_directory\video2x_%Y-%m-%d_%H-%M-%S.log)

### --disable_logging
disable logging (default: False)

### -v, --version
display version, lawful information and exit

## Upscaling Options

### -d DRIVER, --driver DRIVER
upscaling driver (default: waifu2x_caffe)

Available options are:

- waifu2x_caffe
- waifu2x_converter_cpp
- waifu2x_ncnn_vulkan
- srmd_ncnn_vulkan
- realsr_ncnn_vulkan
- anime4kcpp

### -r RATIO, --ratio RATIO
scaling ratio

### -p PROCESSES, --processes PROCESSES
number of processes to use for upscaling (default: 1)

### --preserve_frames
preserve extracted and upscaled frames (default: False)

---

## License

Licensed under the GNU General Public License Version 3 (GNU GPL v3)
Expand Down
9 changes: 4 additions & 5 deletions src/bilogger.py
Expand Up @@ -12,14 +12,14 @@


class BiLogger(io.TextIOWrapper):
""" A bidirectional logger that both prints the output
"""A bidirectional logger that both prints the output
and log all output to file.
Original code from: https://stackoverflow.com/a/14906787
"""

def __init__(self, terminal: io.TextIOWrapper, log_file: io.BufferedRandom):
""" initialize BiLogger
"""initialize BiLogger
Args:
terminal (_io.TextIOWrapper): original terminal IO wrapper
Expand All @@ -30,7 +30,7 @@ def __init__(self, terminal: io.TextIOWrapper, log_file: io.BufferedRandom):
self.fileno = self.log_file.fileno

def write(self, message: str):
""" write message to original terminal output and log file
"""write message to original terminal output and log file
Args:
message (str): message to write
Expand All @@ -41,6 +41,5 @@ def write(self, message: str):
self.log_file.flush()

def flush(self):
""" flush logger (for compability only)
"""
"""flush logger (for compability only)"""
pass
10 changes: 4 additions & 6 deletions src/image_cleaner.py
Expand Up @@ -22,7 +22,7 @@


class ImageCleaner(threading.Thread):
""" Video2X Image Cleaner
"""Video2X Image Cleaner
This class creates an object that keeps track of extracted
frames that has already been upscaled and are not needed
Expand All @@ -40,22 +40,20 @@ def __init__(self, input_directory, output_directory, threads):
self.running = False

def run(self):
""" Run image cleaner
"""
"""Run image cleaner"""
self.running = True

while self.running:
self.remove_upscaled_frames()
time.sleep(1)

def stop(self):
""" Stop the image cleaner
"""
"""Stop the image cleaner"""
self.running = False
self.join()

def remove_upscaled_frames(self):
""" remove frames that have already been upscaled
"""remove frames that have already been upscaled
This method compares the files in the extracted frames
directory with the upscaled frames directory, and removes
Expand Down
20 changes: 17 additions & 3 deletions src/progress_monitor.py
Expand Up @@ -17,7 +17,7 @@


class ProgressMonitor(threading.Thread):
""" progress monitor
"""progress monitor
This class provides progress monitoring functionalities
by keeping track of the amount of frames in the input
Expand All @@ -34,15 +34,29 @@ def __init__(self, upscaler, extracted_frames_directories):
def run(self):
self.running = True

with tqdm(total=self.upscaler.total_frames, ascii=True, desc=_('Processing: {} (pass {}/{})').format(self.upscaler.current_input_file.name, self.upscaler.current_pass, len(self.upscaler.scaling_jobs))) as progress_bar:
with tqdm(
total=self.upscaler.total_frames,
ascii=True,
desc=_("Processing: {} (pass {}/{})").format(
self.upscaler.current_input_file.name,
self.upscaler.current_pass,
len(self.upscaler.scaling_jobs),
),
) as progress_bar:
# tqdm update method adds the value to the progress
# bar instead of setting the value. Therefore, a delta
# needs to be calculated.
previous_cycle_frames = 0
while self.running:

with contextlib.suppress(FileNotFoundError):
upscaled_frames = [f for f in self.upscaler.upscaled_frames.iterdir() if str(f).lower().endswith(self.upscaler.extracted_frame_format.lower())]
upscaled_frames = [
f
for f in self.upscaler.upscaled_frames.iterdir()
if str(f)
.lower()
.endswith(self.upscaler.extracted_frame_format.lower())
]
if len(upscaled_frames) >= 1:
self.upscaler.last_frame_upscaled = sorted(upscaled_frames)[-1]
self.upscaler.total_frames_upscaled = len(upscaled_frames)
Expand Down

0 comments on commit 095d40b

Please sign in to comment.