vzhd1701 / gridplayer

Play videos side-by-side
GNU General Public License v3.0
1.17k stars 91 forks source link

[Bug]: Rotate video 90 degrees or 270 degrees, resulting in distorted image #168

Open sum1game opened 1 year ago

sum1game commented 1 year ago

GridPlayer version

0.5.2

What OS are you using?

Windows

OS Version / Linux distribution

win10

What distribution channel are you using? [LINUX ONLY]

None

Bug description

90

https://github.com/vzhd1701/gridplayer/issues/90 ”there are still some issues with the display, especially in the cases of rotate90 and rotate270 (transpose, anti-transpose), where the aspect None affects the display and causes distortion. I believe this may be due to the resolution not matching the size after rotation. For example, for a 1280x720 video displayed after rotating 90/270 degrees, the new resolution should be 720x1280. Currently, the program still plays the video based on the original resolution of 1280x720, which causes the screen to be squeezed. combining the "aspect None" setting with the rotation function can cause image distortion. However, during my testing today, I found that even if the setting is changed to i.e from Fit "aspect Fit" the video is rotated 90 degrees, image distortion can still occur. If you want to discover more, you can try playing two 1080p or 3840p videos simultaneously, and the distortion will become more apparent with higher resolutions. To fix this bug, it is necessary to adjust the display resolution or aspect ratio while rotating the video.“

According to our previous discussion, we mentioned these points. Since I am not familiar with coding, I asked GPT for help and got this example. I hope it will be helpful to you.

When rotating videos using VLC, it is important to ensure that the rotated resolution matches the original resolution to avoid squeezing or distorting the video. You mentioned adapting the resolution based on the video's original resolution, which is a good approach. To achieve this, you can use the FFmpeg library to retrieve the input video's resolution and dynamically calculate the output video's resolution based on the rotation angle.

Here's an example code that utilizes the FFmpeg library to get the input video's resolution and performs adaptive rotation:

import subprocess

def get_video_resolution(input_file):
    cmd = f'ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 {_file}'
    output = subprocess.check_output(cmd, shell=True).decode('utf-8')
    width, height = output.strip().split('x')
    return int(width), int(height)

def rotate_video(input_file, output_file, rotation_angle):
    width, height = get_video_resolution(input_file)

    # Calculate the output resolution based on the rotation angle
    if rotation_angle in (90, 270):
        output_width = height
        output_height = width
    else:
        output_width = width
        output_height = height

    # Use VLC to rotate the video and save it
    vlc_args = [
        'cvlc',
        '--no-xlib',
        f'--vout="directx{{width={output_width},height={output_height}}}"',
        f'--video-filter="transform{{{rotation_angle}}}"',
        input_file
    ]
    subprocess.run(vlc_args, capture_output=True, text=True)

# Call the rotate function here
rotate_video('input.mp4', 'output.mp4', 90)

In the above example, we first define a get_video_resolution function to use FFmpeg and retrieve the input video's width and height. Then, we calculate the output video's width and height based on the rotation angle. Finally, we call VLC with the appropriate parameters to rotate and save the video.

I hope this helps you solve the issue! If you have any further questions, feel free to ask.

vzhd1701 commented 11 months ago

Should be fixed now. Please check out the new version and tell how it works for you now.

sum1game commented 11 months ago

Should be fixed now. Please check out the new version and tell how it works for you now.

@vzhd1701 Thanks to the author’s fix, after testing, all the screens after the video rotation are displayed normally, they will not be squeezed, and there will be no problems with other settings under the aspect ratio option. Zooming in and out is also normal. Please allow me a little greed, assign a shortcut key for rotating videos, it only needs to be pressed once, switch from no rotation to 90 degrees, press again to switch to 180 degrees, and then press to switch to 270 degrees. In this way, each press will increase the rotation angle by 90 until it returns to the original. This can improve work efficiency.

In addition, I noticed that the translation can now follow version updates, which is great and can help friends from all over the world use this very good player!! I want to share it with friends from other countries.

Once again, I sincerely thank the author for fixing the problem and for the persistent maintenance and improvement of the software. I visit this project website every time I turn on my computer so that I can experience the latest version of this excellent player as soon as possible. It brings me a lot of convenience!