Log in

View Full Version : Кe-create anaglyph with other colors with AVIsynth


McRex
5th February 2025, 10:04
I'm trying to create anaglyph from a video stereo pair using AVIsynth capabilities.
But unfortunately I don't understand how exactly to do this.
I have YUY2 binary lookup table files and ddcc.dll v1.7

About ddcc.dll I found on this forum:

rgb3dlut(string lutfile, int itype, int destcs, int threads, double b, double c)
PARAMETERS (rgb3dlut):
lutfile -
RGB lookup table file.

RGB Input:
The lookup table file should contain 256*256*256 3 byte entries (one for every possible
rgb value) stored in binary format. The table should be stored such that the offset into
the table in bytes for a given rgb value is calculated as:
((g<<16)+(b<<8)+r)*3
At that location, the new rgb values ​​should be stored in b, g, r order (one byte for each).

YUY2 Input:
The lookup table file should contain 256*256*256 3 byte entries (one for every possible
yuv value) stored in binary format. The table should be stored such that the offset into
the table in bytes for a given yuv value is calculated as:
((v<<16)+(u<<8)+y)*3
At that location, the associated rgb value should be stored in b, g, r order (one byte for each).
default: ""

itype -
For yuy2 input this sets how to compute the u/v values ​​for the second y value in each yuyv set.
Possible settings:
0 - duplicate (use u/v of first y value)
1 - linear interpolation (average u/v of first y with u/v of first y in next yuyv set)
2 - Mitchell-Netravali two-part cubic (adjustable b/c parameters to adjust blurring/ringing)
default: 1

destcs-
For yuy2 input, this sets the destination colorspace. Possible settings:
0 - rgb24
1 - rgb32
default: 1

threads -
Sets the number of threads to use for processing. If set to 0, then threads is automatically
set to the number of detected processors. Range is 0 <= threads <= 16.
default: 0

b/c-
Adjusts properties of cubic interpolation (itype=2). Same as Avisynth's BicubicResize filter.
default: 0.0,0.75

The question is how to correctly perform the following operations using MeGUI-2944-32:

LoadPlugin("C:\Users\user\megui\tools\avs\plugins\ddcc.dll")
L = crop(0, 0, 960, 0)
R = crop(960, 0, 0, 0)
R = R.rgb3dlut("C:\Users\user\megui\table1.YUV")
L = L.rgb3dlut("C:\Users\user\megui\table2.YUV)
stackhorizontal(R,L)

- Crop the video into two frames: right and left.
- Apply a separate LUT to each frame.
- Make the frame 50% transparent. (Is this necessary to create an anaglyph? Or is it possible without this?)
- Overlay the frame for the right eye on top of the frame for the left.
- Save to a separate file.

I tried to do something like this, but MeGUI gave an error when executing the "crop" command, the error text was "invalid parameter specified". Maybe I'm using the wrong version, or I should abandon MeGUI.
I ask for help from experts.

DTL
6th February 2025, 23:36
If your input 1920x1080 with 960x1080 left and right

L = crop(0, 0, 960, 1080)
R = crop(960, 0, 960, 1080)

StainlessS
7th February 2025, 11:42
I dont see anything wrong with either of the crop lines for the OP.
What does

# BlankClip(length=1,width=1920,height=1080,pixel_type="YUY2")
info

show ? [no other original lines]

Also, which original line throws the error ?

Additionally in future, when posting problem, try to reduce the problem space, eg

# BlankClip(length=1,width=1920,height=1080,pixel_type="YUY2")
L = crop(0, 0, 960, 0)
R = crop(960, 0, 0, 0)
stackhorizontal(R,L)

no point in complicating things.

EDIT: Also, if the error line is L = etc, then try

# BlankClip(length=1,width=1920,height=1080,pixel_type="YUY2")
crop(0, 0, 960, 0)


Or if error line is R= etc, then try

# BlankClip(length=1,width=1920,height=1080,pixel_type="YUY2")
crop(960, 0, 0, 0)


EDIT: Also, what is your source filter, I presume that you have one somewhere not shown.
EDIT: Wild guess, forgot a source filter :)

McRex
9th February 2025, 08:59
EDIT: Also, what is your source filter, I presume that you have one somewhere not shown.
EDIT: Wild guess, forgot a source filter :)
Thanks! I forgot sourse filter.
Here is full script


LoadPlugin("C:\Users\[]\Desktop\megui\tools\lsmash\LSMASHSource.dll")
LoadPlugin("C:\Users\[]\Desktop\megui\tools\avs\plugins\ddcc.dll")
LWLibavVideoSource("C:\Users\[]\Desktop\megui\vid.mkv")
yv12toyuy2(2, false, 0, 0.0, 0.75)
L = crop(0, 0, -960, 0)
R = crop(960, 0, 0, 0)
L = L.rgb3dlut("C:\Users\[]\Desktop\megui\table(1).YUV", 1, 1, 0, 0.0, 0.75)
R = R.rgb3dlut("C:\Users\[]\Desktop\megui\table(2).YUV", 1, 1, 0, 0.0, 0.75)
Overlay(L, R, mode="blend", opacity=0.5)
BilinearResize(1920, 1080)
info


It works. but next problem is BLACK color is dirty yellow. no more black colors after color correction. Don't understand why. Screenshots before and after attached:

StainlessS
10th February 2025, 19:20
Sorry McRex, I know nothing of 3D stereo stuff, no idea what its supposed to do.
Perhaps someone else can help. {I also dont really have a working avs setup at present, and not done any real processing for at least 6 months, probably longer}

ALSO,

Perhaps a moderator an approve above post attachments.

{or use Postimages.org for free, and post links to the images in your post, Postimage instructions:- https://forum.doom9.org/showthread.php?p=1959414&highlight=postimage#post1959414 }

McRex
13th February 2025, 05:26
Thanks for info. I see my attachments did not get moderator attention so here is the images:
Before
https://i.postimg.cc/G3JZpfgq/before.jpg

After
https://i.postimg.cc/BnyzyftQ/after.jpg

I did some tests with code above to see where the problem starts. First 6 lines of code works fine and did not change black color. Problem starts with 7th line.
I also did some tests with LUT bin files (YUV and RGB), and ALL of them replace BLACK color.
I really don't know what to do now...

StainlessS
13th February 2025, 12:09
Well,
from Wiki (YV12To422) :- http://avisynth.nl/index.php/YV12To422

YV12To422 (clip, bool "interlaced", int "itype", int "cplace", bool "lshift", bool "yuy2", bool "avx2", bool "threads", float "b", float "c")

However,

yv12toyuy2(2, false, 0, 0.0, 0.75)

that dont look right, suggest you use the named style to set arguements eg
YV12To422 (interlaced=false,itype=, ..., etc)
and retry, and repost if probs

EDIT: When giving un-named arguments to a function, they MUST be given in correct order up until the last one that you provide,
you cannot just skip some that you think are unimportant.
Using Named arguements, you can omit some of the named arguments where they will take default values.
Optional arguments always have defaults, non optional ones DO NOT.
After your first use of an NAMED Optional arg, ALL further args MUST also be named.
(I dont know how/why your arguments are accepted at all, ie initially, 2,false, for bool, int.)

Above mentioned YV12To422 has ALL NAMED optional args (except clip), so you can use just the NAMED ones you want to use (and in any order) and others will default.

EDIT: All arguments to YV12To422 (except clip, which is NOT optional) are optional named arguements, ie are enclosed in DOUBLE QUOTES {""}.

EDIT: Here the function prototype given in an alternative style including the optional arg defaults in BLUE.

YV12To422 (clip,
bool "interlaced"=FALSE,
int "itype"=2,
int "cplace"=((interlaced)?TRUE:FALSE),
bool "lshift"=FALSE,
bool "yuy2"=TRUE,
bool "avx2"=FALSE,
bool "threads"=FALSE,
float "b"=0.0,
float "c"=0.75)

Note for cplace, default depends upon previous Interlaced arg setting.

After correcting for above, if still probs I'll look at rgb3dlut stuff.

EDIT: also

LoadPlugin("C:\Users\[]\Desktop\megui\tools\lsmash\LSMASHSource.dll")
LoadPlugin("C:\Users\[]\Desktop\megui\tools\avs\plugins\ddcc.dll")
LWLibavVideoSource("C:\Users\[]\Desktop\megui\vid.mkv")
yv12toyuy2(2, false, 0, 0.0, 0.75)
RETURN LAST # to view output of yv12toyuy2
# ...

wonkey_monkey
13th February 2025, 12:56
Problem starts with 7th line.

I'm suspicious of a filter called rgb3dlut being used on YUV video. Or maybe the YUV files are just wrong.

StainlessS
13th February 2025, 13:10
Me too, but from OP

YUY2 Input:
The lookup table file should contain 256*256*256 3 byte entries (one for every possible
yuv value) stored in binary format. The table should be stored such that the offset into
the table in bytes for a given yuv value is calculated as:
((v<<16)+(u<<8)+y)*3
At that location, the associated rgb value should be stored in b, g, r order (one byte for each).
default: ""


and

R = R.rgb3dlut("C:\Users\user\megui\table1.YUV")
L = L.rgb3dlut("C:\Users\user\megui\table2.YUV)

wonkey_monkey
13th February 2025, 13:28
Try this:

function Anaglyph(clip c, float "red_weight") {
red_weight = Default(red_weight, 0.5)
left = c.Crop(0, 0, c.width / 2, 0).ConvertBits(32).ConvertToPlanarRGB()
right = c.Crop(c.width / 2, 0, 0, 0).ConvertBits(32).ConvertToPlanarRGB()

red = Expr(left.ExtractR, left.ExtractG, left.ExtractB, "x x y z + + 3 / x - " + String(1 - red_weight) + " * +")
anaglyph = MergeRGB(red, right, right).BicubicResize(c.width, c.height, b = 0, c = 0.5)
return anaglyph.ConvertToYUV420().ConvertBits(8)
}

src = LWLibavVideoSource("C:\Users\[]\Desktop\megui\vid.mkv")
Anaglyph(src)

The optional red_weight parameter decides how "pure red" the red side should be. If you set it to zero it becomes an average of RGB. Set it to 1 and it's just the original red channel, but you will get more binocular rivalry.

You could also take out the ConvertToYUV420() if you want an RGB result, but in that case you should specify a matrix for both ConvertToPlanarRGB()s (probably rec709).

McRex
15th February 2025, 12:01
Thank you for the guidance, it helps me learn more.
As for
yv12toyuy2

Unoptimized yv12 to yuy2 conversion, provides point/linear/adjustable cubic interpolation options.

SYNTAX: yv12toyuy2(int itype, bool interlaced, int threads, double b, double c)

PARAMETERS (yv12toyuy2):

itype -
Sets interpolation method. Possible settings:
0 - duplicate
1 - linear interpolation
2 - Mitchell-Netravali two-part cubic (adjustable b/c parameters to adjust blurring/ringing)
default: 2

interlaced -
Sets whether or not the input video is interlaced or progressive.
default: false

threads -
Sets the number of threads to use for processing. If set to 0, then threads is automatically
set to the number of detected processors. Range is 0 <= threads <= 16.
default: 0

b/c -
Adjusts properties of cubic interpolation (itype=2). Same as Avisynth's BicubicResize filter.
default: 0.0,0.75


I see it has only optional args, so I can use even yv12toyuy2() , which is what I actually did.

LoadPlugin("D:\megui\tools\lsmash\LSMASHSource.dll")
LoadPlugin("D:\megui\tools\avs\plugins\ddcc.dll")
LWLibavVideoSource("D:\megui\video2.mkv")
yv12toyuy2()
BilinearResize(1920, 1080)
info


And see this picture:
https://i.postimg.cc/wTwPj9Yp/yuy2-conv.jpg
All black colors are present and looks nice.

As for rgb3dlut() I dont see any way to replace it with something similar..
I replaced the YUV lut files with RGB, but it didn't change anything in the video. Still no black.

L = L.rgb3dlut("D:\megui\calibration-v2\table(1).RGB")
R = R.rgb3dlut("D:\megui\calibration-v2\table(2).RGB")


https://i.postimg.cc/658VCKGw/rgb32.jpg

McRex
15th February 2025, 17:08
Maybe someone has DLL with this functions (found info about them on this forum, but no actual links to download) to replace rgb3dlut() in ddcc.dll
Looking for:
t3dlut()
cr3dlut()
or newer version of ddcc.dll

StainlessS
15th February 2025, 17:24
Looks like cr3dlut is an *.Exe

https://forum.doom9.org/showthread.php?p=1311919#post1311919
Yes, but that way you will use the 3D LUTs only for YV12->RGB32 conversion. If you don't want to use any of the other extra features of the 3D LUTs, you probably will be better served by disabling the 3D LUTs.


Yes. It will select the 3D LUT for SD and HD accordingly with the resolution of the file you are playing. The criteria is explained in madVR thread, I don't remember it exactly... I believe that HD is used when height > 576 or width > 1024


You can update cr3dlut simply by replacing the cr3dlut.exe file contained in madVR's cr3dlut directory.
If you want to replace the files yourself, you have to overwrite the files that are in madVR's directory. If you look carefully, you'll find 4 files:
- "hd - pc.3dlut"
- "hd - video.3dlut"
- "sd - pc.3dlut"
- "sd - video.3dlut"
The files with "pc" in the name are with PC levels (16-235->0-255).
The files with "video" in the name are with Video levels (16-235->16-235)
You just need to create the files, naming them accordingly, and just copy them to madVR's directory.
If you prefer that madVR creates the files for you, just delete them.

PS: If you want fast answers, questions about cr3dlut should be post in the madVR thread or the Gammut conversion thread, because I only monitorize a few threads. Today I decided to take a general look in the forum and found this thread...;)

t3dlut may be same (exe) but for txt data rather than raw.
https://forum.doom9.org/showthread.php?p=1275888#post1275888
oh OK, so t3dlut only works with .txt LUT's, not .3dlut...now that's confusing...how come it even works then?

well, the idea is that most files are mod4 anyway, so you can use yv12toyuy2(itype=2) but sometimes you have files that are mod2...and IIRC only itype=0 works on mod2.

so if yv12toyuy2() could either fall back to a mod2-compatible mode, or to ConvertToYUY2(it's GPL right? only a matter of cut/paste?)...that would make life easier when you run them in ffdshow instead of getting an error msg.

:thanks:
stuff starting with 'td' tends to be written by "tritical".

wonkey_monkey
19th February 2025, 15:34
Maybe someone has DLL with this functions (found info about them on this forum, but no actual links to download) to replace rgb3dlut() in ddcc.dll
Looking for:
t3dlut()
cr3dlut()
or newer version of ddcc.dll

Did you try my script? Curious to know how well it worked for you.

McRex
28th February 2025, 11:44
Did you try my script? Curious to know how well it worked for you.

I did, but as it is it's did not worked. Got error in 7 and 11 lines.
But I'm curious about MergeRGB it self.
Right now I learn more and try to replace Overlay() with MergeRGB in my last post script...

wonkey_monkey
28th February 2025, 19:45
I did, but as it is it's did not worked. Got error in 7 and 11 lines.
But I'm curious about MergeRGB it self.
Right now I learn more and try to replace Overlay() with MergeRGB in my last post script...

Strange. What was the error?

McRex
7th March 2025, 12:01
Strange. What was the error?

https://i.postimg.cc/BQnF6pvn/err.jpg


LoadPlugin("D:\megui\tools\lsmash\LSMASHSource.dll")
function Anaglyph(clip c, float "red_weight") {
red_weight = Default(red_weight, 0.5)
left = c.Crop(0, 0, c.width / 2, 0).ConvertBits(32).ConvertToPlanarRGB()
right = c.Crop(c.width / 2, 0, 0, 0).ConvertBits(32).ConvertToPlanarRGB()
red = Expr(left.ExtractR, left.ExtractG, left.ExtractB, "x x y z + + 3 / x - " + String(1 - red_weight) + " * +")
anaglyph = MergeRGB(red, right, right).BicubicResize(c.width, c.height, b = 0, c = 0.5)
return anaglyph.ConvertToYUV420().ConvertBits(8)
}
src = LWLibavVideoSource("D:\megui\video2.mkv")
Anaglyph(src)

wonkey_monkey
7th March 2025, 13:52
It looks like some updates were made to MergeRGB in Avisynth+ 3.7.2 which may be why the script works for me.

Maybe adding the two lines in bold will work on earlier versions:

function Anaglyph(clip c, float "red_weight") {
red_weight = Default(red_weight, 0.5)
left = c.Crop(0, 0, c.width / 2, 0).ConvertBits(32).ConvertToPlanarRGB
right = c.Crop(c.width / 2, 0, 0, 0).ConvertBits(32).ConvertToPlanarRGB

red = Expr(left.ExtractR, left.ExtractG, left.ExtractB, "x x y z + + 3 / x - " + String(1 - red_weight) + " * +")
red = red.ConvertToRGB24
right = right.ConvertToRGB24
anaglyph = MergeRGB(red, right, right)
return anaglyph.ConvertToYUV420.ConvertBits(8).BicubicResize(c.width, c.height, b = 0, c = 0.5)
}
src = LWLibavVideoSource("D:\megui\video2.mkv")
Anaglyph(src)

pinterf
7th March 2025, 14:34
It looks like some updates were made to MergeRGB in Avisynth+ 3.7.2 which may be why the script works for me.

Documentation page refreshed.
https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/mergergb.html

McRex
15th March 2025, 19:46
It looks like some updates were made to MergeRGB in Avisynth+ 3.7.2 which may be why the script works for me.

Maybe adding the two lines in bold will work on earlier versions:

function Anaglyph(clip c, float "red_weight") {
red_weight = Default(red_weight, 0.5)
left = c.Crop(0, 0, c.width / 2, 0).ConvertBits(32).ConvertToPlanarRGB
right = c.Crop(c.width / 2, 0, 0, 0).ConvertBits(32).ConvertToPlanarRGB

red = Expr(left.ExtractR, left.ExtractG, left.ExtractB, "x x y z + + 3 / x - " + String(1 - red_weight) + " * +")
red = red.ConvertToRGB24
right = right.ConvertToRGB24
anaglyph = MergeRGB(red, right, right)
return anaglyph.ConvertToYUV420.ConvertBits(8).BicubicResize(c.width, c.height, b = 0, c = 0.5)
}
src = LWLibavVideoSource("D:\megui\video2.mkv")
Anaglyph(src)


Works nice, thanks. I take this as new working example to learn.