stouputils.applications.upscaler.video module#

This module provides utility functions for upscaling videos using waifu2x-ncnn-vulkan.

It extracts frames from videos, upscales them individually, and then recombines them into a high-quality output video. The process preserves audio from the original video and handles configuration of video encoding parameters like bitrate and framerate.

Main functionalities:

  • Extracting frames from videos using FFmpeg

  • Upscaling frames using waifu2x-ncnn-vulkan

  • Recombining frames into videos with optimized bitrates

  • Handling partially processed videos to resume interrupted operations

  • Calculating recommended bitrates based on resolution and framerate

The module includes YouTube’s recommended bitrate settings for different resolutions, framerates, and HDR/SDR content types, ensuring optimal quality for various outputs.

Example usage: .. code-block:: python

# Imports import stouputils.applications.upscaler as app from stouputils.io import get_root_path

# Constants ROOT: str = get_root_path(__file__) + “/upscaler” INPUT_FOLDER: str = f”{ROOT}/input” PROGRESS_FOLDER: str = f”{ROOT}/progress” OUTPUT_FOLDER: str = f”{ROOT}/output”

# Main if __name__ == “__main__”:

app.video_upscaler_cli(INPUT_FOLDER, PROGRESS_FOLDER, OUTPUT_FOLDER)

Get the recommended bitrate (in kbps) for the output video based on the video resolution.

Parameters:
  • resolution (tuple[int, int]) – Video resolution (width, height).

  • frame_rate (int) – Frame rate of the video, default is 60.

  • upload_type (Literal["SDR","HDR"]) – Upload type from which the recommendation is made, default is “SDR”.

Returns:

The recommended bitrate for the output video (in kbps)

Return type:

int

Source: https://support.google.com/youtube/answer/1722171?hl=en#zippy=%2Cbitrate

Examples

>>> # Valid examples
>>> get_recommended_bitrate((3840, 2160), 60, "SDR")
68000
>>> get_recommended_bitrate((1920, 1080), 60, "HDR")
15000
>>> get_recommended_bitrate((1920, 1080), 60, "SDR")
12000
>>> get_recommended_bitrate((1920, 1080), 30, "SDR")
8000
>>> # Invalid examples
>>> get_recommended_bitrate((1920, 1080), 60, "Ratio")
Traceback (most recent call last):
        ...
AssertionError: Invalid upload type: 'Ratio'
>>> get_recommended_bitrate("1920x1080", 60, "SDR")
Traceback (most recent call last):
        ...
AssertionError: Invalid resolution: 1920x1080, must be a tuple of two integers
>>> get_recommended_bitrate((1920, 1080), -10, "SDR")
Traceback (most recent call last):
        ...
AssertionError: Invalid frame rate: -10, must be a positive integer
upscale_video(video_file: str, input_folder: str, progress_folder: str, output_folder: str) None[source]#

Handles a video file.

video_upscaler_cli(input_folder: str, progress_folder: str, output_folder: str) None[source]#

Upscales videos from an input folder and saves them to an output folder.

Uses intermediate folders for extracted and upscaled frames within the progress folder. Handles resuming partially processed videos.

Parameters:
  • input_folder (str) – Path to the folder containing input videos.

  • progress_folder (str) – Path to the folder for storing intermediate files (frames).

  • output_folder (str) – Path to the folder where upscaled videos will be saved.