Fundamentals 6 min read

Upscaling 720p Video to 1080p with ffmpeg‑python and OpenCV in Python

The article explains how to use ffmpeg‑python and OpenCV in Python to transcode a 720p video to 1080p, discusses the limitations of simple upscaling, and provides code examples for resolution scaling as well as basic color and sharpening enhancements.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Upscaling 720p Video to 1080p with ffmpeg‑python and OpenCV in Python

In Python, the FFmpeg library (via ffmpeg‑python) or OpenCV can be used to convert a 720p video (1280×720) to 1080p (1920×1080), but this only increases pixel count without adding real detail, so the result may appear blurry because the original footage lacks the extra information.

The following ffmpeg‑python snippet demonstrates how to resize a video while preserving the aspect ratio and padding any missing area with black bars:

from ffmpeg import Input, Output
# Input video file path
input_video = 'input.mp4'
# Output video file path
output_video = 'output.mp4'
# Create FFmpeg input object
input_clip = Input(input_video)
# Set output parameters: scale to 1080p, keep aspect ratio, pad if needed
output_params = {
    '-vf': 'scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2',
    '-c:a': 'copy'
}
# Create FFmpeg output object and run
(output_video, ) = Output(output_video, **output_params).run(input=input_clip)
input_clip.run()
print("Video has been resized to 1080p.")

Before running the script, install the ffmpeg‑python package with pip install ffmpeg-python and ensure the FFmpeg executable is available on the system, as the library relies on it.

High‑quality video conversion also requires attention to frame rate, encoder settings, and possible quality assessment and parameter tuning to maintain smooth playback.

Upscaling alone does not improve visual quality; to enhance a video you can consider super‑resolution techniques, color correction, denoising, and sharpening. OpenCV can perform basic color and sharpening adjustments, while deep‑learning‑based tools such as DAIN are needed for advanced frame‑rate interpolation and enhancement.

Below is a simple OpenCV example that loads a video, applies brightness/contrast scaling and a sharpening kernel to each frame, and writes the result back to a new file:

import cv2
import numpy as np
# Load video
cap = cv2.VideoCapture('input.mp4')
fps = cap.get(cv2.CAP_PROP_FPS)
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# Define output video writer
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4', fourcc, fps, (frame_width, frame_height))
while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break
    # Simple color enhancement (adjust brightness and contrast)
    frame = cv2.convertScaleAbs(frame, alpha=1.2, beta=50)
    # Sharpening filter
    sharpen_kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
    frame = cv2.filter2D(frame, -1, sharpen_kernel)
    out.write(frame)
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
out.release()
cv2.destroyAllWindows()

This script only performs basic color boosting and sharpening; professional video quality improvement typically requires more sophisticated algorithms or dedicated video editing software.

video processingFFmpegopencvvideo enhancementresolutionupscaling
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.