Skip to content

Rewrite descaling guide from scratch - #56

Closed
LightArrowsEXE wants to merge 6 commits into
Irrational-Encoding-Wizardry:masterfrom
LightArrowsEXE:master
Closed

LightArrowsEXE wants to merge 6 commits into
Irrational-Encoding-Wizardry:masterfrom
LightArrowsEXE:master

Conversation

@LightArrowsEXE

Copy link
Copy Markdown
Member

I hated my old write-up, so here's an updated one!

@FichteFoll FichteFoll added the content We can do better! label Mar 2, 2020
I hated my old write-up, so here's an updated one!
@OrangeChannel

OrangeChannel commented Mar 3, 2020 •

Copy link
Copy Markdown
Collaborator

Okay, so this was a bit weird to do since it's coming from @LightArrowsEXE 's master branch, but I've rebased this onto the current upstream master, as well as got rid of the back-up folder I assume created by pingo or some compression app. Some images weren't fully compressed so I've also went back and compressed those.

  • Original (with back-up folder): 71225520 B
  • Original (without folder): 19175192 B
  • Current (no folder, new compression): 14956763 B 79% saved total, 22% saved with new compression

EDIT: not sure how to give Light back the ownership of that commit (if that's even possible)
Here's a backup of the original commit https://github.com/OrangeChannel/guide.encode.moe/tree/descale-rewrite-backup

@FichteFoll

FichteFoll commented Mar 6, 2020 •

Copy link
Copy Markdown
Member

FWIW, you can set the author of a commit with git commit --author="FichteFoll <fichtefoll2@googlemail.com>". I'll do that before merging.

@OrangeChannel OrangeChannel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only gone through this up until the Handling native 1080p content since I know too little of how the credit stuff is done.

Comment thread encoding/descaling.md
Comment on lines +14 to +15
What the difference between downscaling and descaling is
is a question that gets asked fairly frequently.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this fits here. Just explaining it directly works.

Comment thread encoding/descaling.md
Comment on lines +17 to +18
downscaling is the act of resizing an image
to a smaller resolution than the original image,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have some mention of how downscaling uses the same kernels as upscaling, while de-scaling reverses the kernel's logic. We can reference the resampling page here as well.

@FichteFoll FichteFoll Mar 7, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how downscaling uses the same kernels as upscaling

That's … a pretty general thing to say and doesn't exactly provide more information than what we have currently.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... 🤔 I guess you're right, a more detailed explanation wouldn't belong here I guess but maybe a ## Descaling section on the resampling page may be something to consider in the future (that better explains the difference mathematically).

Comment thread encoding/descaling.md Outdated
while with descaling you are actively reversing the math
applied to an upscale,
reconstructing the original image before upscaling
(which coincidentally also means you get a smaller image).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably unnecessary to write this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely unnecessary, but the "coincidentally" is too strong. It was our intention all along to go back to the original information and reduce the amount of superficial information that needs to be included in an encode, or provide better such superficial information.

Actually, I'm missing this kind of explanation for the motivation of descaling. You say that it's better than downscaling, but never mention why we want to do it in the first place, particularly why it's always a good idea to do so (before applying your filter chain), provided it's possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for why you should descale gets mentioned in the next paragraph. I'll build onto that a bit further.

Comment thread encoding/descaling.md Outdated
Comment thread encoding/descaling.md
Comment thread encoding/descaling.md Outdated
Comment thread encoding/descaling.md Outdated
Comment thread encoding/descaling.md
Comment on lines +155 to +168
```py
import lvsfunc as lvf

This picture is also very dark
and has even more effects over it.
clip = core.lsmas.LWLibavSource(r"PATH/TO/VIDEO.m2ts")
clip = fvf.Depth(clip, 32) # Important to note: descale requires a GRAYS clip (or 444, but don't do that).

![Manaria Friends — 01 (frame 3)](images/descale_manaria03.png)
clip_y = core.std.ShufflePlanes(clip, 0, vs.GRAY)
descaled = core.descale.Debicubic(clip_y, width=1280, height=720, b=1/3, c=1/3)
reupscaled = core.resize.Bicubic(descaled, width=1920, height=1080, filter_param_a=1/3, filter_param_b=1/3)
merged = core.std.ShufflePlanes([reupscaled, clip], [0, 1, 2], vs.YUV)

Heavy dynamic grain will almost always give bad results.
comp = lvf.compare(clip, merged)
comp.set_output()
```

@OrangeChannel OrangeChannel Mar 7, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import descale

src = core.lsmas.LWLibavSource(r'/path/to/file.m2ts')

descaled = descale.Debicubic(src, width=1280, height=720, b=1/3, c=1/3)
reupscaled = core.resize.Bicubic(descaled, width=1920, height=1080, filter_param_a=1/3, filter_param_b=1/3)

core.std.Interleave(clips=[src.text.Text('src'), reupscaled.text.Text('scaled', 9)]).set_output()

Is there a reason here for changing the bitdepth? And using the python wrapper for descale you don't need to convert the clip or merge the planes back.

@LightArrowsEXE LightArrowsEXE Mar 7, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, my bad. These are examples of the plugin, not the wrapper. Will update.

Comment thread encoding/descaling.md Outdated
Comment thread encoding/descaling.md Outdated

@FichteFoll FichteFoll left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the flow in the rewrite a lot better than in the previous. Good job on that.

Please address the comments I added and also what I didn't comment on in Dave's review.

Comment thread encoding/descaling.md Outdated
Comment thread encoding/descaling.md Outdated
Comment on lines +71 to +73
![](images/descale/descale_owari_01_frame.png)

![getnative.py -k bicubic -b 0 -c 1/2](images/descale/descale_owari_01_graph.png)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add descriptive captions for these two. For the latter, do something like The result of …. I'm not going to repeat this for the cases below.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally find that rather annoying to do when a lot of it is mostly repeats of the same thing and is already pretty evident just by reading the accompanying text. Maybe the first time around, but for others? Ehhh...

Comment thread encoding/descaling.md Outdated
Comment thread encoding/descaling.md
Comment on lines +17 to +18
downscaling is the act of resizing an image
to a smaller resolution than the original image,

@FichteFoll FichteFoll Mar 7, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how downscaling uses the same kernels as upscaling

That's … a pretty general thing to say and doesn't exactly provide more information than what we have currently.

Comment thread encoding/descaling.md Outdated
while with descaling you are actively reversing the math
applied to an upscale,
reconstructing the original image before upscaling
(which coincidentally also means you get a smaller image).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely unnecessary, but the "coincidentally" is too strong. It was our intention all along to go back to the original information and reduce the amount of superficial information that needs to be included in an encode, or provide better such superficial information.

Actually, I'm missing this kind of explanation for the motivation of descaling. You say that it's better than downscaling, but never mention why we want to do it in the first place, particularly why it's always a good idea to do so (before applying your filter chain), provided it's possible.

Comment thread encoding/descaling.md
Comment thread encoding/descaling.md
Comment thread encoding/descaling.md Outdated
Comment thread encoding/descaling.md Outdated
![Akanesasu Shoujo — 01 (src)](images/descale_akanesasu_src.png)

![Akanesasu Shoujo — 01 (rescaled)](images/descale_akanesasu_rescaled.png)
![Merge the original credits with a re-upscaled frame (using nnedi3_resample)](images/descale/descaled_symphoxv_credits_frame_masked.png)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the image here, but is it a composition or the final frame? In the latter case, the caption can't use imperative.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite get what you mean by this. Could you elaborate?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Fichte means the caption should sound more like Original credits merged with a re-upscaled (nnedi3_resample) frame instead of using a command-like phrase.

Comment thread encoding/descaling.md
@LightArrowsEXE

Copy link
Copy Markdown
Member Author

Have updated it with the comments in mind. I may have missed one or two, so another double-check would be appreciated. I've also replied to some comments that I either wanted elaboration on or don't agree with.

@OrangeChannel

Copy link
Copy Markdown
Collaborator

@FichteFoll I caught light up with the changes so any further changes shouldn't be a problem (sorry for the double push, git deleted+added files instead of renaming them and i didn't notice).

Before merging, just make Light author of 03732ab and 9f0eed5 .

Comment thread encoding/descaling.md
Comment on lines +30 to +36
This offers a multitude of advantages,
like for example when dealing with artifacting
that was a result of a poor upscale.
You could instead undo the scaling
and use a better scaler to upscale it instead,
or keep it at its native resolution and
have less artifacting to worry about.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This offers a multitude of advantages,
like for example when dealing with artifacting
that was a result of a poor upscale.
You could instead undo the scaling
and use a better scaler to upscale it instead,
or keep it at its native resolution and
have less artifacting to worry about.
This offers many advantages,
one example being the ability to fix artifacting
that was a result of a poor upscale.
You could undo the scaling
and use a better scaler to upscale it instead,
or keep it at its native resolution and
have less artifacting to worry about.

Are there any other benefits worth mentioning?

Comment thread encoding/descaling.md
what the native resolution of a frame is.
One way to do this is by descaling to all potential resolutions,
upscaling the descaled image with the same kernel,
and comparing the two.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and comparing the two.
and comparing this result with the original.

Comment thread encoding/descaling.md
[getnative.py][getnative] is a common tool
used for figuring out the native resolution of an image.
It will return a graph showcasing all the resolutions
it tried to descale to,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe adding a footnote mentioning:

With the default (bicubic 1/3 1/3) usually returning the correct resolution either way...

would satisfy this?

Comment thread encoding/descaling.md

![Results from "getnative.py -k bicubic -b 0 -c 1/2"](images/descale/descale_owari_01_graph.png)

What you want to look out for are very clear spikes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
What you want to look out for are very clear spikes.
What you want to look out for are very clear downward spikes.

I've seen a few awful graphs in the #bot channel that have spikes somehow going up, and we'd want to avoid these afaict.

Comment thread encoding/descaling.md
![Manaria Friends — 01 (frame 2)](images/descale_manaria02.png)
Once you've figured out the native resolution,
you can move on to the actual descaling.
There's two common ways to do this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There's two common ways to do this.
There's three common ways to do this.

Whoops, didn't notice that when I added mention of the python functions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should those even be separate entries?

Comment thread encoding/descaling.md
A fairly common practice is
to upscale the descaled clip to a standard resolution
(if it isn't already one, like for example 720p).
The following scalers are generally recommended for this task.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seems like there's going to be a list after this line, so maybe needs some rewording.

Comment thread encoding/descaling.md
This is a good result
for testing out varying kernels.

Similarly, [nnedi3_resample][] is also used by some people

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Similarly, [nnedi3_resample][] is also used by some people
Another scaler, [nnedi3_resample][], is sometimes used

Comment thread encoding/descaling.md
of some common kernels and values.
A couple more extreme examples
would be using [waifu2x][] or [upscaled_sraa][]
to upscale it back to 1080p.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to upscale it back to 1080p.
to upscale it back to the original resolution.

Comment thread encoding/descaling.md
it's important to be wary of native 1080p elements.
A common example of this is credits,
which are usually added after upscaling.
These will require being masked.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
These will require being masked.
These will need to be masked.

Comment thread encoding/descaling.md
Comment on lines +335 to +336
Since the credits will still be messed up,
you will need to replace them with a downscaled clip.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The differentiation here is that you are going to downscale the credits while descaling the rest of the frame, right? I think better wording would be as follows:

Suggested change
Since the credits will still be messed up,
you will need to replace them with a downscaled clip.
Since there is no need to *descale* native 1080p elements,
you will need to *downscale* the credits instead.

Comment thread encoding/descaling.md
![Akanesasu Shoujo — 01 (src)](images/descale_akanesasu_src.png)

![Akanesasu Shoujo — 01 (rescaled)](images/descale_akanesasu_rescaled.png)
[Here][rescaled] is a link to a comparison.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that Fichte has said before not to have a link on words like "here" and instead just link the actual thing. i.e.:

Suggested change
[Here][rescaled] is a link to a comparison.
[Slowpics comparison of the re-upscaled frame.][rescaled]

Comment thread encoding/descaling.md
![Merge downscaled credits with descaled clip](images/descale/descale_casefiles_ed_credits_frame_masked.png)

[^1]: Most, if not all, relevant VapourSynth scripts/plug-ins and their functions can be found in the [VapourSynth Database][vsdb].
[Here][downscaled] is also a link to a comparison.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous one:

Suggested change
[Here][downscaled] is also a link to a comparison.
[Slowpics comparison of the descaled frame.][downscaled]

@FichteFoll

Copy link
Copy Markdown
Member

It's nice that github added their review feature, but things quickly become a mess for larger PRs like this. It's not easy to see all unresolved discussions and compare the changes since then to determine whether they have been resolved in code.

@LightArrowsEXE

Copy link
Copy Markdown
Member Author

This PR is going to be closed now and reworked later. I have a plan for a different page to be added, and will be writing a guide for that instead now. Will revisit updating descaling at a later date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

content We can do better!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants