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

It seems that MaskSubMod() does not support VSFilterMod? #3

Closed
mojie126 opened this issue Nov 13, 2023 · 11 comments
Closed

It seems that MaskSubMod() does not support VSFilterMod? #3

mojie126 opened this issue Nov 13, 2023 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@mojie126
Copy link

It seems that MaskSubMod() does not support VSFilterMod
LoadPlugin("D:/afd/DGCube.dll") LoadPlugin("D:/afd/VSFilterMod.dll") MaskSubMod("D:/afd/a-mmrq14.ass", 1920, 1080, 23.97599983215332, 51424) ConvertBits(16) ConvertToPlanarRGBA() DGCube("D:/afd/BT709_to_PQ.cube")

@FranceBB
Copy link
Owner

The issue here is that Cube() along with DGCube() only accept RGB planar 16bit, without the alpha channel.
Luckily there's a "trick" or rather a "workaround" shall I say.
Essentially the alpha channel is literally just one additional channel on top of the normal RGB, which means that it can absolutely be treated separately as if it was just a normal, fake, RGB, and then added back.
I actually had to do something similar when I had to convert the logos coming from the graphics department from BT709 SDR to BT2020 HLG (you're going to PQ but it's the same thing for all intents and purposes).
Anyway, long story short, this is what I've done when I had to encode the RGBA stills:

FFImageSource("\\mibctvan000\Ingest\MEDIA\temp\LUT conversion for stills\MicrosoftTeams-image (1).png")

my_alpha=ShowAlpha(pixel_type="RGB24")


RemoveAlphaPlane()

ConvertBits(16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)

Cube("\\mibctvan000\Ingest\MEDIA\temp\LUT conversion for stills\3a_BT709_HLG_Type1_Display_DirectMapping_nocomp-v1_5 1.cube", interp=1, fullrange=1)

my_HLG=last

ConvertBits(my_alpha, 16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)

Cube("\\mibctvan000\Ingest\MEDIA\temp\LUT conversion for stills\3a_BT709_HLG_Type1_Display_DirectMapping_nocomp-v1_5 1.cube", interp=1, fullrange=1)

ConverttoY(matrix="PC.2020")


my_alpha_HLG=last


AddAlphaPlane(my_HLG, my_alpha_HLG)

So, by re-arranging what I've done to your use case, your script would become:

MaskSubMod("D:/afd/a-mmrq14.ass", 1920, 1080, 23.97599983215332, 51424)

#Save alpha channel
my_alpha=ShowAlpha(pixel_type="RGB24")

#From BT709 to PQ without alpha
RemoveAlphaPlane()
ConvertBits(16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
DGCube("D:/afd/BT709_to_PQ.cube")
my_PQ=last

#From BT709 to PQ only alpha
ConvertBits(my_alpha, 16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
DGCube("D:/afd/BT709_to_PQ.cube")
ConverttoY(matrix="PC.2020")
my_alpha_PQ=last

#Add PQ converted alpha back to PQ converted RGB
AddAlphaPlane(my_PQ, my_alpha_PQ)

Now, I commented the code to make it easier.
It's still a bit convoluted, though, so I'll leave the issue open until I'll add it to LinearTransformation() so that I can handle it automatically and properly support RGBA 'cause I feel like this is something the function should do automatically.

I think I deserve a cappucino now. :P

@FranceBB FranceBB self-assigned this Nov 13, 2023
@mojie126
Copy link
Author

mojie126 commented Nov 13, 2023

This is my final script, which doesn't seem to work well. Even if I replace DGCube with Cube and import vscube.dll, it still doesn't work

LoadPlugin("D:/afd/DGCube.dll")
LoadPlugin("D:/afd/VSFilterMod.dll")
MaskSubMod("D:/afd/a-mmrq14.ass", 1920, 1080, 23.97599983215332, 51424)
my_alpha=ShowAlpha(pixel_type="RGB24")
RemoveAlphaPlane()
ConvertBits(16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
DGCube("D:/afd/BT709_to_PQ.cube")
my_PQ=last
ConvertBits(my_alpha, 16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
DGCube("D:/afd/BT709_to_PQ.cube")
ConverttoY(matrix="PC.2020")
my_alpha_PQ=last
AddAlphaPlane(my_PQ, my_alpha_PQ)

@FranceBB
Copy link
Owner

What's the actual error outputted?

@mojie126
Copy link
Author

Prompt 'No events detected. Cowardly reusing to write XML file.'
I am using avs2bdnXML to convert ass subtitles to BDNXML

@mojie126
Copy link
Author

win11 x64
VSFilterMod x86
AviSynth+ 3.7.3
But I don't know if DGCube.dll and vscube.dll are x86 or x64

@FranceBB
Copy link
Owner

Ok, I downloaded VSFilterMod and actually tested on a test.ass with ColorBars().
Apparently MaskSubMod() wasn't exactly doing what I expected it to be doing, so I had to change the script a bit.
Anyway, this works:

ColorBars(848, 480, pixel_type="RGB32")
ChangeFPS(23.976)


my_alpha=MaskSubMod("A:\Ingest\MEDIA\temp\Test.ass", 848, 480, 23.97599983215332, 51424).FlipVertical()

#From BT709 to PQ without alpha
RemoveAlphaPlane()
ConvertBits(16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
Cube("C:\Program Files (x86)\AviSynth+\LUTs\BT709_to_PQ.cube")
my_PQ=last

#From BT709 to PQ only alpha
ConvertBits(my_alpha, 16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
Cube("C:\Program Files (x86)\AviSynth+\LUTs\BT709_to_PQ.cube")
ConverttoY(matrix="PC.2020")
my_alpha_PQ=last

#Add PQ converted alpha back to PQ converted RGB
AddAlphaPlane(my_PQ, my_alpha_PQ)

Of course ColorBars() are just an example as I didn't want to index another content.

This is the converted colorbars in RGBA 16bit:

image

and this is the relative alpha channel (also in PQ):

image

from the script Test.ass which is here:

image

@FranceBB FranceBB added the enhancement New feature or request label Nov 14, 2023
@FranceBB
Copy link
Owner

Your request has been satisfied and I've added a preliminary support to RGB32 in version 2.6 https://github.com/FranceBB/LinearTransformation/releases/tag/2.6

As an example, let's take a look at the following fake RGB32 input:

ColorBars(848, 480, pixel_type="RGB32")
pippo=last

pluto=pippo.ConverttoY()

AddAlphaPlane(pippo, pluto)

This creates an RGB32 stream in which the first 24bit are RGB (i.e 8+8+8=24):
image

and the last 8 are the alpha channel (+8 = 32):
image

This is in BT709 SDR.
When we apply:

LinearTransformation(Input="Linear_BT709", Output="BT2100_PQ", Interpolation="Tetrahedral")

what's gonna happen is that the stream will be divided in two parts: the normal part and the alpha channel and both will be subject to the very same transformation (in this case from BT709 to BT2020 PQ) before being added back to create a proper RGB32 output:

image
image

as per your request.
I therefore consider this issue closed (it should have really been a feature request, though, but it's fine xD)

@mojie126
Copy link
Author

That's great Thank you
Is ColorBars mandatory?
Is it okay to just use these codes?

my_alpha=MaskSubMod("A:\Ingest\MEDIA\temp\Test.ass", 848, 480, 23.97599983215332, 51424).FlipVertical()

#From BT709 to PQ without alpha
RemoveAlphaPlane()
ConvertBits(16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
Cube("C:\Program Files (x86)\AviSynth+\LUTs\BT709_to_PQ.cube")
my_PQ=last

#From BT709 to PQ only alpha
ConvertBits(my_alpha, 16)
ConvertToPlanarRGB(matrix="PC.709", interlaced=false)
Cube("C:\Program Files (x86)\AviSynth+\LUTs\BT709_to_PQ.cube")
ConverttoY(matrix="PC.2020")
my_alpha_PQ=last

#Add PQ converted alpha back to PQ converted RGB
AddAlphaPlane(my_PQ, my_alpha_PQ)

@mojie126
Copy link
Author

I now suspect that it may be an issue with avs2bdnxml. I have seen that it is implemented using vfw, and may it be that vfw does not support it?
https://github.com/koroban/avs2bdnxml

@mojie126
Copy link
Author

LoadPlugin("D:/afd/VSFilterMod.dll")
LoadPlugin("D:/afd/vscube.dll")
clp=MaskSubMod("D:/afd/a-mmrq14.ass", 1920, 1080, 23.97599983215332, 51424)
my_alpha = clp.ShowAlpha(pixel_type="RGB24")
clp = clp.RemoveAlphaPlane()
clp = clp.ConvertBits(bits=16).ConvertToPlanarRGB()

ConvertBits(my_alpha, 16)
ConvertToPlanarRGB()
Cube("D:/afd/BT709_to_PQ.cube")
ConverttoY()
my_alpha=last
Cube(clp, "D:/afd/BT709_to_PQ.cube")
my_video=last
AddAlphaPlane(my_video, my_alpha)

Convert the avs script using avs2bdnxml, but still prompt "No events detected. Cowardly refusing to write XML file."

@mojie126
Copy link
Author

Tested to be an issue with vscube.dll, which seems to not support x86

Repository owner deleted a comment from mojie126 Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants