WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Rotation may need an overhaul #322

@ferdnyc

Description

@ferdnyc

Given the issues reported in OpenShot/openshot-qt#2969 (and others), and based on my own tests, it seems like the current rotation support in OpenShot is... insufficient.

The problem arises when you have a video rotated in a way that changes its dimensions (which, you know, is most rotation effectively, except for 0° and 180°.) Because libopenshot still processes the video as though it has the width and height of its original dimensions, things don't go well.

This can be seen by creating a vertical video profile, then importing a video in true vertical aspect, vs. a video with standard wide aspect and an initial rotation. The true-upright video loads in just fine, and formats correctly to the output frame. The rotated widescreen video is loaded shrunken down (with "Best Fit" scaling) in the center of the output frame, only about half of its full size. This seems to be because libopenshot is scaling it as if it needs to fit a 1920px wide image inside a 1080px wide frame.

My guess is that what's missing, for starters, is a post-rotation coordinate mapping of the QTransform:

QTransform transform;
// Transform source image (if needed)
ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Build QTransform - if needed)", "source_frame->number", source_frame->number, "x", x, "y", y, "r", r, "sx", sx, "sy", sy);
if (!isEqual(r, 0)) {
// ROTATE CLIP
float origin_x = x + (scaled_source_width / 2.0);
float origin_y = y + (scaled_source_height / 2.0);
transform.translate(origin_x, origin_y);
transform.rotate(r);
transform.translate(-origin_x,-origin_y);
transformed = true;
}

QTransform has all sorts of map() and mapRect() functions to translate spatial data into the transformation's coordinate system. mapRect() is even documented to return the bounding box, for rotating or shearing transforms, which sounds like exactly what we'd want. (A full-HD video rotated to 45° isn't actually 1920px × 1080px, after all — it's somewhat narrower, but significantly taller than that.)

And for initial rotation, like in vertical video (most of which is stored at horizontal dimensions with a 90° initial rotation), ideally we'd want libopenshot to consider that video's width to be 1080, and its height to be 1920. Which may not be possible with the current rotation logic, as it simply applies the in-built rotation as a default initial value of OpenShot's Rotation property. That doesn't seem good enough, if we even need to translate the dimensions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions