### Setup Video Upscaling Pipeline (Python) Source: https://context7.com/djdefrag/qualityscaler/llms.txt Shows the initial setup for the `upscale_video` function, which handles the complete video upscaling workflow. It includes initializing multiprocessing components like a status queue and a queue for video frames, as well as an event for stopping the process. This prepares the environment for multi-threaded frame processing and hardware-accelerated encoding. ```python from multiprocessing import Manager, Event # Setup multiprocessing infrastructure manager = Manager() process_status_q = manager.Queue(maxsize=1) video_frames_and_info_q = manager.Queue(maxsize=150) # Based on available RAM event_stop_upscale_process = manager.Event() ``` -------------------------------- ### Initialize and Use AI Upscaler (Python) Source: https://context7.com/djdefrag/qualityscaler/llms.txt Demonstrates initializing the AI_upscale class for image enhancement. It covers model selection, GPU configuration, input resizing, and max resolution for tiling. The example shows basic image reading, AI upscaling using AI_orchestration, and saving the result. It also includes manual control logic for tiling large images. ```python from QualityScaler import AI_upscale, image_read, image_write # Initialize the AI upscaler with model configuration ai_instance = AI_upscale( AI_model_name="BSRGANx4", # Model: LVAx2, RealESR_Gx4, RealESR_Animex4, BSRGANx2, BSRGANx4, MSharpx4, IRCNN_Mx1, IRCNN_Lx1 directml_gpu="Auto", # GPU selection: Auto, GPU 1, GPU 2, GPU 3, GPU 4 input_resize_factor=1.0, # Scale input before AI processing (0.0-1.0) max_resolution=400 # Max tile size in pixels (based on VRAM) ) # Read an image file image = image_read("input_photo.jpg") # Upscale the image using AI # AI_orchestration handles: resizing, tiling (if needed), inference, and merging upscaled_image = ai_instance.AI_orchestration(image) # Save the upscaled result image_write("output_photo_4x.png", upscaled_image, ".png") # For manual control over the upscaling process: # Check if image needs tiling due to size if ai_instance.image_need_tilling(image): # Large image - will be split into tiles, processed, and merged result = ai_instance.AI_upscale_with_tilling(image) else: # Small image - direct inference result = ai_instance.AI_upscale(image) ``` -------------------------------- ### Process Single Image with Upscale Function (Python) Source: https://context7.com/djdefrag/qualityscaler/llms.txt Illustrates the `upscale_image` function for a complete single image processing pipeline. This includes setting up multiprocessing for status updates, initializing the AI upscaler, and calling `upscale_image` with various parameters for input resizing, output resizing, and AI blending. The example also notes the output file naming convention. ```python from multiprocessing import Manager # Setup multiprocessing queue for status updates manager = Manager() process_status_q = manager.Queue(maxsize=1) # Initialize AI instance ai_instance = AI_upscale( AI_model_name="RealESR_Gx4", directml_gpu="Auto", input_resize_factor=0.5, # Process at 50% of original size max_resolution=400 ) # Upscale a single image with all options upscale_image( process_status_q=process_status_q, image_path="vacation_photo.jpg", file_number=1, selected_output_path="Same path as input files", # Or specify a directory path AI_instance=ai_instance, selected_AI_model="RealESR_Gx4", selected_image_extension=".png", # Output format: .png, .jpg, .bmp, .tiff input_resize_factor=0.5, # 50% of original before AI output_resize_factor=1.0, # 100% of AI output selected_blending_factor=0.3 # Low blending: 0=OFF, 0.3=Low, 0.5=Medium, 0.7=High ) # Output file naming convention: # vacation_photo_RealESR_Gx4_InputR-50_OutputR-100_Blending-Low.png ``` -------------------------------- ### Image I/O and Blending Utilities Source: https://context7.com/djdefrag/qualityscaler/llms.txt Provides functions for reading, writing, and blending images. `image_read` supports various formats including those with unicode paths. `image_write` saves images in specified formats. `blend_images_and_save` combines original and upscaled images to smooth out tiling artifacts. ```python from QualityScaler import image_read, image_write, blend_images_and_save, get_image_resolution # Read image from any supported format # Supported: .jpg, .jpeg, .png, .webp, .bmp, .tif, .tiff, .heic image = image_read("photo.png") # Get image dimensions (height, width) height, width = get_image_resolution(image) print(f"Image size: {width}x{height}") # Write image with specified format # The extension determines the encoding format image_write("output.jpg", image, ".jpg") image_write("output.png", image, ".png") image_write("output.bmp", image, ".bmp") image_write("output.tiff", image, ".tiff") # Blend original and upscaled images for quality enhancement # Useful when tiling artifacts need smoothing original_image = image_read("original.jpg") upscaled_image = image_read("upscaled.jpg") blend_images_and_save( target_path="blended_output.png", starting_image=original_image, upscaled_image=upscaled_image, starting_image_importance=0.3, # 30% original, 70% upscaled file_extension=".png" ) ``` -------------------------------- ### Upscale Video with Full Configuration Source: https://context7.com/djdefrag/qualityscaler/llms.txt Initiates video upscaling using a specified AI model and configuration. It requires queue objects for process status and frame data, an event to stop the process, and various parameters to control video path, AI model, blending, multithreading, GPU usage, resizing factors, tile resolution, video extension, codec, and frame retention. ```python upscale_video( process_status_q=process_status_q, video_frames_and_info_q=video_frames_and_info_q, event_stop_upscale_process=event_stop_upscale_process, video_path="input_video.mp4", file_number=1, selected_output_path="Same path as input files", selected_AI_model="LVAx2", # LVAx2 recommended for live-action video selected_blending_factor=0, # OFF for video (0.3=Low, 0.5=Medium, 0.7=High) selected_AI_multithreading=4, # Process 4 frames simultaneously selected_gpu="Auto", input_resize_factor=0.5, # 50% input scale output_resize_factor=1.0, # 100% output scale tiles_resolution=400, # Tile size based on VRAM selected_video_extension=".mp4", # .mp4, .mkv, .avi, .mov selected_video_codec="h264_nvenc", # x264, x265, h264_nvenc, hevc_nvenc, h264_amf, hevc_amf, h264_qsv, hevc_qsv selected_keep_frames=False # Delete extracted frames after encoding ) # To stop video upscaling gracefully: event_stop_upscale_process.set() # Output file naming: # input_video_LVAx2_InputR-50_OutputR-100.mp4 ``` -------------------------------- ### AI Model VRAM Usage and Tile Resolution Calculation (Python) Source: https://context7.com/djdefrag/qualityscaler/llms.txt Defines a dictionary mapping AI models to their VRAM usage and provides a function to calculate the tile resolution based on the selected AI model and available VRAM. This is crucial for optimizing processing performance. ```python # AI Models and their characteristics: VRAM_model_usage = { 'RealESR_Gx4': 2.5, # Real-ESRGAN General 4x - degraded live-action/animation 'RealESR_Animex4': 2.5, # Real-ESRGAN Anime 4x - animation specific 'BSRGANx4': 0.75, # BSRGAN 4x - high-quality image upscaling 'BSRGANx2': 0.8, # BSRGAN 2x - high-quality image upscaling 'IRCNN_Mx1': 4, # IRCNN Medium 1x - denoising 'IRCNN_Lx1': 4, # IRCNN Large 1x - denoising 'LVAx2': 2, # Live Video Action 2x - live-action video 'MSharpx4': 1.5 # MSharp 4x - sharpening and upscaling } # Calculate tile resolution based on VRAM (in GB) def calculate_tiles_resolution(ai_model, vram_gb): multiplier = VRAM_model_usage.get(ai_model, 1.0) return int(multiplier * vram_gb * 100) # Example: 8GB VRAM with BSRGANx4 tiles = calculate_tiles_resolution("BSRGANx4", 8) # Returns 600 ``` -------------------------------- ### Output Filename Generation Utilities Source: https://context7.com/djdefrag/qualityscaler/llms.txt Functions to generate standardized output filenames for images and videos. These functions encode processing parameters directly into the filename, aiding in identification and reproducibility of results. ```python from QualityScaler import prepare_output_image_filename, prepare_output_video_filename # Example usage (assuming relevant parameters are defined elsewhere): # output_image_name = prepare_output_image_filename(input_filename="input.jpg", ai_model="LVAx2", input_resize=0.5, output_resize=1.0) # output_video_name = prepare_output_video_filename(input_filename="input.mp4", ai_model="LVAx2", input_resize=0.5, output_resize=1.0, video_codec="h264_nvenc") ``` -------------------------------- ### Video Frame Rate and Metadata Copying Source: https://context7.com/djdefrag/qualityscaler/llms.txt Utility functions for video file handling. `get_video_fps` retrieves the frame rate of a video file. `copy_file_metadata` transfers EXIF and other metadata from an original file to a new file, utilizing ExifTool. `check_if_file_is_video` verifies if a given file is a video. ```python from QualityScaler import get_video_fps, copy_file_metadata, check_if_file_is_video # Check if a file is a video file_path = "content.mp4" if check_if_file_is_video(file_path): # Supported video formats: .mp4, .webm, .mkv, .flv, .gif, .m4v, # .avi, .mov, .qt, .3gp, .mpg, .mpeg, .vob # Get the frame rate fps = get_video_fps(file_path) print(f"Video FPS: {fps}") # Copy metadata from original to upscaled file # Preserves EXIF data, creation dates, camera info, etc. copy_file_metadata( original_file_path="original_photo.jpg", upscaled_file_path="upscaled_photo.png" ) # This uses ExifTool internally with command: # exiftool -fast -TagsFromFile original -overwrite_original -all:all -unsafe -largetags upscaled ``` -------------------------------- ### Generate Video Output Filename (Python) Source: https://context7.com/djdefrag/qualityscaler/llms.txt Creates a standardized output filename for processed videos. This function includes the input video path, output directory, AI model used, resizing factors, and video extension. It ensures consistent naming for video processing outputs. ```python video_output = prepare_output_video_filename( video_path="videos/clip.mp4", selected_output_path="/output/folder", selected_AI_model="LVAx2", input_resize_factor=0.75, # 75% output_resize_factor=1.0, # 100% selected_video_extension=".mkv", selected_blending_factor=0 # OFF ) # Result: /output/folder/clip_LVAx2_InputR-75_OutputR-100.mkv ``` -------------------------------- ### Image Resolution Scaling Source: https://context7.com/djdefrag/qualityscaler/llms.txt The `resize_with_output_factor` function scales images by a given factor, ensuring the output dimensions are always even numbers, which is crucial for video encoding compatibility. It can be used for both downscaling input images and upscaling using interpolation. ```python from QualityScaler import image_read, resize_with_output_factor, get_image_resolution # Load an image image = image_read("large_photo.jpg") original_height, original_width = get_image_resolution(image) print(f"Original: {original_width}x{original_height}") # Resize to 50% of original size resized_50 = resize_with_output_factor(image, output_resize_factor=0.5) h, w = get_image_resolution(resized_50) print(f"50% scale: {w}x{h}") # Resize to 200% (upscale using interpolation) resized_200 = resize_with_output_factor(image, output_resize_factor=2.0) h, w = get_image_resolution(resized_200) print(f"200% scale: {w}x{h}") # Note: Dimensions are automatically adjusted to be even numbers # This is required for video codec compatibility ``` -------------------------------- ### Generate Image Output Filename (Python) Source: https://context7.com/djdefrag/qualityscaler/llms.txt Generates a standardized output filename for processed images. It incorporates details about the input image, selected AI model, resizing factors, and blending settings. This function helps in organizing processed image files. ```python output_path = prepare_output_image_filename( image_path="photos/vacation.jpg", selected_output_path="Same path as input files", # Or specify directory selected_AI_model="BSRGANx4", input_resize_factor=0.5, # 50% output_resize_factor=1.0, # 100% selected_image_extension=".png", selected_blending_factor=0.5 # Medium ) # Result: photos/vacation_BSRGANx4_InputR-50_OutputR-100_Blending-Medium.png ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.