DEV Community

S I D D A R T H
S I D D A R T H

Posted on • Originally published at Medium on

Real -ESGRAN | Enhance your videos.

Hey there, in this article we are going to have a exposure on a open-sourced video enhancer tool Real-ESGRAN. This tool is not advanced as Topaz Ai, but more over it gives a satisfying result.

This is the frame before enhance.


Before enhance.

I will show the result that i got on Real-ESGRAN. Due to limitations in medium, I will share the result as link.

For sample view.

Enhanced Quality : Link Unavailable

Really I impressed that i got a more smooth images after enhancing. At the same time i got frustrated due to its rendering time. I really rendered a 30 seconds video for a whole night with my RTX 3050 4GB.

The actual problem you can’t render this quality with this 4BG VRAM. It says VRAM is out of memory. So i rendered the video by 200 pixel by pixel. Makes the process slower.

You laptop will start to burn like hot flames in the dragon dungeon. So I created a python script to create a break time between each frame render and a additional break time between each 10 frames. This helped me to maintain my laptop GPU at gradually at 81°C.

Coming to the point, How to do?

Get Real-ESGRAN files at download it as zip.

Video version of the process will be available soon.

Enhancing Video Quality with Real-ESRGAN: A Step-by-Step Guide

High-quality video enhancement has become easier with tools like Real-ESRGAN. This guide explains how to extract frames from a video, enhance them using Real-ESRGAN, and merge them back into a high-resolution video with the original audio.

Step 1: Extract Frames from Video

To begin, create a directory for storing frames and extract images from the video file using FFmpeg:

mkdir frames
ffmpeg -i input.mp4 -q:v 1 frames/frame_%04d.png
Enter fullscreen mode Exit fullscreen mode

This command ensures high-quality frame extraction while maintaining the sequence of images.

Step 2: Enhance Frames Using Real-ESRGAN

Once the frames are extracted, create an output directory and process them using Real-ESRGAN:

mkdir enhanced_frames
python inference_realesrgan.py -n RealESRGAN_x4plus -i frames --outscale 1.2 -o enhanced_frames
Enter fullscreen mode Exit fullscreen mode

The --outscale 1.2 parameter upscales the frames by 20% , adding 200 pixels to the resolution, I used this command:

python inference_realesrgan.py -n RealESRGAN_x4plus -i frames/ -o upscaled_frames/ --tile 200
Enter fullscreen mode Exit fullscreen mode

Step 3: Reconstruct Video from Enhanced Frames

After enhancement, convert the processed frames back into a video:

ffmpeg -framerate 30 -i enhanced_frames/frame_%04d.png -c:v libx264 -pix_fmt yuv420p enhanced_video.mp4
Enter fullscreen mode Exit fullscreen mode

Here, -framerate 30 maintains smooth playback, and libx264 ensures compatibility with most devices.

Step 4: Extract Audio from Original Video

Since the enhanced video lacks audio, extract the original sound from the input video:

ffmpeg -i input.mp4 -q:a 0 -map a audio.aac
Enter fullscreen mode Exit fullscreen mode

Step 5: Merge Audio with Enhanced Video

Finally, combine the extracted audio with the upscaled video:

ffmpeg -i enhanced_video.mp4 -i audio.aac -c:v copy -c:a aac -strict experimental final_output.mp4
Enter fullscreen mode Exit fullscreen mode

This command merges the video and audio streams without re-encoding the video, ensuring the best quality.

To be noted.

Ensure to create a frame and upscaled_frame folder before processing.

Store all the before enhance frames in the frame folder.

Every commands should be typed on cmd.

Ensure you download all the requirements.txt.

To download, go inside of the folder Real-ESGRAN type cmd in address bar and type the following in cmd:

pip install requirements.txt
Enter fullscreen mode Exit fullscreen mode

Y ou can also use my python script to create a break time between frames.

import os
import time
import glob

# Path to input and output folders
input_folder = "frames/"
output_folder = "upscaled_frames/"

# List all frames
frames = sorted(glob.glob(os.path.join(input_folder, "*.png")))

# Process each frame with a break
for i, frame in enumerate(frames):
    print(f"Processing {i+1}/{len(frames)}: {frame}")

    # Run Real-ESRGAN on one frame at a time
    os.system(f'python inference_realesrgan.py -n RealESRGAN_x4plus -i "{frame}" -o "{output_folder}" --tile 200')

    # Add a longer delay after each frame (adjust as per your requirement)
    time.sleep(10) # Increased to 10 seconds after each frame

    # Optional: Take a longer break every 10 frames
    if (i + 1) % 10 == 0:
        print("Cooling down for 60 seconds...") # Increased cooldown time
        time.sleep(60) # Extended break time to 60 seconds after every 10 frames

print("✅ All frames processed!")
Enter fullscreen mode Exit fullscreen mode

To use type “python batch_processor.py” in cmd.

ERROR ENCOUNTER.

If you receive error expect this feel free contact me soozuo@yandex.ru

  1. If you receive module not found error! Ensure that you have downloaded all the modules in the requirements.txt founded to be in the extracted folder.
  2. If you receive realesgran version not found. you have create that manually.

Go to \Real-ESRGAN\realesrgan and create a python file named version.py contain the following :

__version__ = '0.3.0'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)