Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 5th February 2025, 10:04   #1  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
Кe-create anaglyph with other colors with AVIsynth

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:
Code:
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:
Code:
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.
McRex is offline   Reply With Quote
Old 6th February 2025, 23:36   #2  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 1,296
If your input 1920x1080 with 960x1080 left and right

L = crop(0, 0, 960, 1080)
R = crop(960, 0, 960, 1080)
DTL is offline   Reply With Quote
Old 7th February 2025, 11:42   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,108
I dont see anything wrong with either of the crop lines for the OP.
What does
Code:
# 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
Code:
# 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
Code:
# BlankClip(length=1,width=1920,height=1080,pixel_type="YUY2")
crop(0, 0, 960, 0)
Or if error line is R= etc, then try
Code:
# 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
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 7th February 2025 at 12:02.
StainlessS is offline   Reply With Quote
Old 9th February 2025, 08:59   #4  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
Quote:
Originally Posted by StainlessS View Post
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

Code:
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:
Attachments Pending Approval
File Type: jpg before.jpg
File Type: jpg after.jpg

Last edited by McRex; 9th February 2025 at 09:22.
McRex is offline   Reply With Quote
Old 10th February 2025, 19:20   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,108
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.p...ge#post1959414 }
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th February 2025, 05:26   #6  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
Thanks for info. I see my attachments did not get moderator attention so here is the images:
Before


After


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...
McRex is offline   Reply With Quote
Old 13th February 2025, 12:09   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,108
Well,
from Wiki (YV12To422) :- http://avisynth.nl/index.php/YV12To422
Code:
YV12To422 (clip, bool "interlaced", int "itype", int "cplace", bool "lshift", bool "yuy2", bool "avx2", bool "threads", float "b", float "c")
However,
Code:
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.
Code:
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
Code:
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
# ...
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th February 2025 at 12:45.
StainlessS is offline   Reply With Quote
Old 13th February 2025, 12:56   #8  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,641
Quote:
Originally Posted by McRex View Post
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.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is online now   Reply With Quote
Old 13th February 2025, 13:10   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,108
Me too, but from OP
Code:
 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
Code:
R = R.rgb3dlut("C:\Users\user\megui\table1.YUV")
L = L.rgb3dlut("C:\Users\user\megui\table2.YUV)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th February 2025, 13:28   #10  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,641
Try this:

Code:
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).
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 13th February 2025 at 16:30.
wonkey_monkey is online now   Reply With Quote
Old 15th February 2025, 12:01   #11  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
Thank you for the guidance, it helps me learn more.
As for
yv12toyuy2
Code:
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.
Code:
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:

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.
Code:
L = L.rgb3dlut("D:\megui\calibration-v2\table(1).RGB")
R = R.rgb3dlut("D:\megui\calibration-v2\table(2).RGB")

Last edited by McRex; 15th February 2025 at 12:18.
McRex is offline   Reply With Quote
Old 15th February 2025, 17:08   #12  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
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
McRex is offline   Reply With Quote
Old 15th February 2025, 17:24   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,108
Looks like cr3dlut is an *.Exe

https://forum.doom9.org/showthread.p...19#post1311919
Quote:
Originally Posted by yesgrey View Post
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.p...88#post1275888
Quote:
Originally Posted by leeperry View Post
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.

stuff starting with 'td' tends to be written by "tritical".
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 15th February 2025 at 17:33.
StainlessS is offline   Reply With Quote
Old 19th February 2025, 15:34   #14  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,641
Quote:
Originally Posted by McRex View Post
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.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is online now   Reply With Quote
Old 28th February 2025, 11:44   #15  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
Quote:
Originally Posted by wonkey_monkey View Post
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...
McRex is offline   Reply With Quote
Old 28th February 2025, 19:45   #16  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,641
Quote:
Originally Posted by McRex View Post
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?
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is online now   Reply With Quote
Old 7th March 2025, 12:01   #17  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
Quote:
Originally Posted by wonkey_monkey View Post
Strange. What was the error?


Code:
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)
McRex is offline   Reply With Quote
Old 7th March 2025, 13:52   #18  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,641
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:

Code:
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)
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is online now   Reply With Quote
Old 7th March 2025, 14:34   #19  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 2,465
Quote:
Originally Posted by wonkey_monkey View Post
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/.../mergergb.html
pinterf is offline   Reply With Quote
Old 15th March 2025, 19:46   #20  |  Link
McRex
Registered User
 
Join Date: Jan 2025
Posts: 8
Quote:
Originally Posted by wonkey_monkey View Post
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:

Code:
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.
McRex is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:38.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.