abhiTronix / vidgear

A High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features :fire:
https://abhitronix.github.io/vidgear
Apache License 2.0
3.33k stars 253 forks source link

[Bug]: Stabilization not good on linux environment #416

Open ronfromhp opened 1 month ago

ronfromhp commented 1 month ago

Description

Video gets even more unstable after stabilizing it on linux, while the same stabilized video looks fine on windows

Issue Checklist

Expected behaviour

i expected the stabilized video coming out like this on linux, which is what it does on windows

https://github.com/user-attachments/assets/8b20bb81-3f66-40d1-9ae6-591fac188940

Actual behaviour

the actual stabilized video looks like this

https://github.com/user-attachments/assets/0d60b6e4-04e1-48d8-a246-28484a986c8a

Steps to reproduce

I used the below python code to process the files

Terminal log output

No response

Python Code(Optional)

from vidgear.gears.stabilizer import Stabilizer
import cv2
import time
import logging

logger = logging.getLogger(__name__)
logger.setLevel(level=3)
stab = Stabilizer(border_size=10, crop_n_zoom=True, logging=True)

def stabilize_video(input_path, output_path):
    start_time = time.time()
    stream = cv2.VideoCapture(input_path)

    # Get video properties
    fps = int(stream.get(cv2.CAP_PROP_FPS))
    width = int(stream.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(stream.get(cv2.CAP_PROP_FRAME_HEIGHT))

    # Define the codec and create VideoWriter object
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))

    while True:
        # read frames from stream
        (grabbed, frame) = stream.read()

        if not grabbed:
            break
        # send current frame to stabilizer for processing
        stabilized_frame = stab.stabilize(frame)

        # wait for stabilizer which still be initializing
        if stabilized_frame is None:
            continue

        out.write(stabilized_frame)

    # clear stabilizer resources
    stab.clean()

    # safely close video stream
    stream.release()
    out.release()
    logger.info(f"Stabilization completed in {time.time() - start_time} seconds.")
    return True

VidGear Version

0.3.3

Python version

3.11.9

OpenCV version

opencv-python-headless-4.8.0.74

Operating System version

wsl Ubuntu-22.04

Any other Relevant Information?

No response

welcome[bot] commented 1 month ago

Thanks for opening this issue, a maintainer will get back to you shortly!

In the meantime:

abhiTronix commented 1 month ago

@ronfromhp This is weird. There are platform-specific changes in the Stabilizer API that I know of. I'll test it on my system and let you know. This issue mostly arises from a small error in code you write in a script, so if you could double-check, that would be great.

ronfromhp commented 1 month ago

I've double checked it and it shows no error on the logs or in the output, only issue is that the quality of the stabilization is worse on the Ubuntu enviornment