Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling incorrect when using SCALE_NONE and scale_x / scale_y #754

Closed
jeffski opened this issue Oct 8, 2021 · 6 comments
Closed

Scaling incorrect when using SCALE_NONE and scale_x / scale_y #754

jeffski opened this issue Oct 8, 2021 · 6 comments
Labels
stale This issue has not had any activity in 90 days :(

Comments

@jeffski
Copy link
Contributor

jeffski commented Oct 8, 2021

When using SCALE_NONE and then applying scale_x and/or scale_y it appears as if images and videos are scaled twice. For example an image that is 1000px x 500px with a scale of 0.5 will result in an image displaying in the rendered video at 250px x 125px, not 500px x 250px.

The code below demonstrates:

Clip clip1(new QtImageReader("wave-1000x500.jpg"));
clip1.Position(0);
clip1.Layer(1);
clip1.Start(0);
clip1.End(5);
clip1.scale = openshot::SCALE_NONE;

Clip clip2(new QtImageReader("wave-1000x500.jpg"));
clip2.Position(5);
clip2.Layer(1);
clip2.Start(0);
clip2.End(5);
clip2.scale = openshot::SCALE_NONE;
clip2.scale_x.AddPoint(0.5);
clip2.scale_y.AddPoint(0.5);

Timeline timeline(1280, 720, Fraction(25,1), 44100, 2, LAYOUT_STEREO);
timeline.AddClip(&clip1);
timeline.AddClip(&clip2);
timeline.Open();

FFmpegWriter writer("output.mp4");
writer.SetAudioOptions(true, "aac", 44100, 2, LAYOUT_STEREO, 128000);
writer.SetVideoOptions(true, "libx264", Fraction(25, 1), 1280, 720, Fraction(1,1), false, false, 0);
writer.PrepareStreams();
writer.SetOption(VIDEO_STREAM, "crf", "23" );
writer.WriteHeader();
writer.Open();
freopen("/dev/null", "w", stderr);
writer.WriteFrame(&timeline, 1, 10 * 25);

writer.Close();
timeline.Close();

This is the test image used (1000px x 500px)
wave-1000x500.jpg

The output video is here (1280px x 720px):
output.mp4

  • The first clip renders at a size of 1000 x 500px as expected.
  • The second clip renders at 1/4 the size at 250 x 125px - I would expect the video to be half the size of the original (scale: 0.5) at 500 x 250px

I have tested this with FFMpegReader and the issue is the same.

Somewhere the scale must be being run twice.

@JacksonRG
Copy link
Collaborator

@jeffski You might try setting scale to best_fit. I'm looking for an explanation for another user as to why the scale options are labeled as such, but under scale:none, changing the scale of one axis can affect the other.

@jeffski
Copy link
Contributor Author

jeffski commented Oct 12, 2021

@JacksonRG I don't think that makes sense. If I scale the X axis, why would it scale the Y axis as well - unless you are maintaining aspect ratios. Scaling something by 50% should make it half the size, not quarter the size. Also this is a breaking change, it used to work as described. On upgrading to the latest version all our videos started rendering with elements smaller than they should be.

@jeffski
Copy link
Contributor Author

jeffski commented Oct 13, 2021

Played about with this a bit more. It is definitely being scaled twice. If I comment out this code in QtImageReader.cpp (L249 - L257) then the image is scaled as expected to 50% of the original:

float preview_ratio = 1.0;
if (parent->ParentTimeline()) {
Timeline *t = (Timeline *) parent->ParentTimeline();
preview_ratio = t->preview_width / float(t->info.width);
}
float max_scale_x = parent->scale_x.GetMaxPoint().co.Y;
float max_scale_y = parent->scale_y.GetMaxPoint().co.Y;
max_width = info.width * max_scale_x * preview_ratio;
max_height = info.height * max_scale_y * preview_ratio;

This is for the QtImageReader which is easier to understand but something similar must be happening in the FFMpegReader too.

@jeffski
Copy link
Contributor Author

jeffski commented Oct 13, 2021

Actually it doesn't seem correct with the code commented out. It does look like the image is scaled by 50% but the original image which is not scaled fills the viewport and the scaled image is 50% of that.

@alexzk1
Copy link

alexzk1 commented Jan 9, 2022

2 things look suspicious here:
co.Y at float max_scale_x = parent->scale_x.GetMaxPoint().co.Y;
shouldn't it be like co.X? if no - then just weird naming...
and second thing preview_ratio = t->preview_width / float(t->info.width); is depend on X but used for X and Y while you try to scale separated. Maybe you need 2 separated ratios for X and Y.

@stale
Copy link

stale bot commented Apr 16, 2022

Thank you so much for submitting an issue to help improve OpenShot Video Editor. We are sorry about this, but this particular issue has gone unnoticed for quite some time. To help keep the OpenShot GitHub Issue Tracker organized and focused, we must ensure that every issue is correctly labelled and triaged, to get the proper attention.

This issue will be closed, as it meets the following criteria:

  • No activity in the past 90 days
  • No one is assigned to this issue

We'd like to ask you to help us out and determine whether this issue should be reopened.

  • If this issue is reporting a bug, please can you attempt to reproduce on the latest daily build to help us to understand whether the bug still needs our attention.
  • If this issue is proposing a new feature, please can you verify whether the feature proposal is still relevant.

Thanks again for your help!

@stale stale bot added the stale This issue has not had any activity in 90 days :( label Apr 16, 2022
@stale stale bot closed this as completed Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue has not had any activity in 90 days :(
Projects
None yet
Development

No branches or pull requests

3 participants