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
Set clip in constructor to resolve scale crop issue #513
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #513 +/- ##
===========================================
- Coverage 48.25% 48.24% -0.01%
===========================================
Files 128 128
Lines 9954 9956 +2
===========================================
Hits 4803 4803
- Misses 5151 5153 +2
Continue to review full report at Codecov.
|
Here is before and after example. You can clearly see the vertical lines of the trees in the before example are pixelated and have a 'wavey' kind of effects going on. The after example is crisp and sharp. Before: https://shillitto.s3-ap-southeast-2.amazonaws.com/openshot/before.mp4 |
Hmm. My only major concern with this, on first glance, would be all of the times OpenShot (and possibly libopenshot too) does something like this: f = File(somepath)
throwaway = Clip(somepath)
dostuffwith(throwaway.Reader()) Which leaves me concerned that we could end up with reader data that references nonexistent clips, because the reader's parent was disposed of. I'm not SURE it's a problem, it's just my worry. ... Though I suppose at least in OpenShot, since the parent ref is a pointer it likely wouldn't be exposed from the Python bindings. So this may not be any kind of issue really. Great catch, though! Something's definitely out of whack, there. If setting the parent fixes it, and no other issues turn up, maybe we just do that. Clean & simple. Looking at that part of the code, though, I have to wonder how scaling everything TWICE can actually be any sort of performance improvement (as the comments there claim). I get that it's intended to keep memory consumption and cache sizes down, but the fact remains that we're scaling INPUT data that's very likely just going to be scaled again for OUTPUT. And as you discovered, we're doing it indiscriminately, even in situations where we can't tell whether it makes sense or not — which is also hurting quality. Dubious benefits there, if you ask me. Now I'm really curious to see what a libopenshot build that removed all that input scaling would look like, memory/performance-wise. |
It seems that it changes nothing in openshot-qt Export. |
Wow! That is pretty much night-and-day, agreed. To the extent that my strong inclination is just to merge this ASAP and deal with any possible fallout afterwards. |
I suspect that's because OpenShot only uses the (And therefore, arguably, maybe it's the caller's job to call The odd thing is, when |
We are just taking a look at optimising the two places where the resizing is done, to remove or only run the resizing if needed. Give us a day or two and will push an update. |
Hmm. Nothing of use. At the time, setting it was added to The else{
// No scaling, use original image size (slower)
reader->SetMaxSize(0, 0);
} but now, not only does the else {
// No scaling, use original image size (slower)
max_width = info.width;
max_height = info.height;
} (...Come to think of it, the fact that this now lives in libopenshot/src/FFmpegReader.cpp Lines 1289 to 1294 in 4e6c181
What happens will be wholly dependent on the libopenshot/src/FFmpegReader.cpp Lines 931 to 948 in 7b6eb9c
When the code lived in |
This scaling code is nutso, anyway. Like, it uses Want to know how to implement auto max = QSize(max_width, max_height);
auto frame = QSize(info.width, info.height);
auto target = frame.scaled(max, Qt::KeepAspectRatio); Done. Want to know how to implement auto target = frame.scaled(max, Qt::KeepAspectRatioByExpanding); |
As far as Like, imagine you're scaling down a video at a different aspect ratio, using But if it were using the |
Codecov Report
@@ Coverage Diff @@
## develop #513 +/- ##
===========================================
+ Coverage 48.25% 48.32% +0.07%
===========================================
Files 128 128
Lines 9954 9953 -1
===========================================
+ Hits 4803 4810 +7
+ Misses 5151 5143 -8
Continue to review full report at Codecov.
|
I misunderstood my co-developer regarding more changes to skip one of the scaling steps so please consider the pull request complete unless you have more change requests. We were wondering if scaling would be faster/more efficient using FFMPEG instead of Qt or if there is a reason for using Qt as well. More than happy for you to pick this up and optimise/fix further. |
A related issue I had a while back was using SCALE_NONE - I was trying to use a logo as a watermark and the logo was already scaled i.e. 300px x 200px - using SCALE_NONE would still stretch it to the width/height of the viewport. My expectation would be that it would remain 300px x 200px. I think there is comments in the code saying that needed fixed. |
Yeah, I would... very much expect so. What format was the file? You say "a logo", but was it an SVG file, or a bitmap image? I wouldn't be surprised if the SVG rendering always renders to the timeline frame size. (You gave the dimensions in ...I guess a workaround would be to matte the watermark onto a transparent PNG the size of the frame, so it doesn't need to be scaled. (You no doubt thought of that.) But, yeah, it'd be cool if that just worked right as-is. |
I'll let this sit for a little bit to see if anyone else takes an interest, but like I said my inclination is to merge it as quickly as possible given the clear benefits seen in those before/after videos. I don't believe it'll affect OpenShot itself anyway, the existing code was already doing the right things in the APIs it uses. I think the others were just overlooked. |
In OpenShot it works OK. No noticeable issues with the Scale set to None. At least, in now days. |
No complaints, so in it goes. Thanks @jeffski ! |
I just checked this vs the old code and it seems to fix the SCALE_NONE none issue I was having. With the old code a 400px x 103px bitmap image was stretched to the width of the video (1280px). With the new code the image is the correct size when rendered at 400px x 103px. So two birds with one stone. |
This fix resolves issue: #419
Clips are scale cropped in two places FFmpegReader.cpp and in Timeline.cpp:556.
FFmpegReader calculates the wrong size for scale with crop. It is because Timeline doesn't set clip for FFmpegReader (and for all readers) so FFmpegReader doesn't now anything about SCALE_CROP, because it is a property of Clip.
And in FFmpegReader in line 1396 (in the last version) Clip *parent = (Clip *) GetClip();
We get parent = NULL and so it doesn't check scale property and calculate sizes using default formulas which are incorrect for SCALE_CROP case (and may be for SCALE_FIT and SCALE_STRETCH too).
I'll post some before and after screen-grabs just now but this change fixes the issue with 1:1 video scaling/cropping.