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 26th September 2015, 21:37   #1  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
Strange color problem

Hi,
I have a video that has a strange problem with colors, it's especially visible on parts in movement.
But when I play this mpg with MPC-HC, this problem is not really visible.

IIRC, I recorded it a few years ago on TV with my Set-top box. Its HDD was crypted and the only way I had to transfer recordings was to capture by its analog output (Scart with S-video adaptator) with my Hauppauge card.

Thus I wonder if the problem comes from a bad encoding by the TV channel or if it was created when I captured it and was caused by the Set-top box or by my capture card.
I recorded in mpeg-2 @ 12Mbps in PAL system. That's supposed to be anamorphic 16/9 but I exported these jpeg in 720.576 with Virtual Dub.

Here is how it looks like without any filter (I tried FFVideoSource and LWLibavVideoSource, both give the same result, except the field order), click to see the real size ;



It's originally progressive but encoded interlaced.
It seems 2 fields of 2 successive frames are blended.
If I use tfm(), that's better, but another problem appears (the main problem actually) ;



I get the same result than tfm() if I remove the first field like this ;
Code:
separatefields().trim(1,0).weave()
And here is what happens when I separate fields, whatever I use tfm() before or not, these are 3 successive frames (or fields actually) ;







The chroma and luma move separately
How to fix this ?
Music Fan is offline   Reply With Quote
Old 26th September 2015, 21:55   #2  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 649
On first image both fields have exactly same chroma, which is blended from 2 frames. Last 3 images seem to have normal chroma, but it's not synced to luma.
It's really hard to say if it's fixable without an actual sample.
vivan is offline   Reply With Quote
Old 26th September 2015, 22:51   #3  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
Here is a sample ;
https://www.sendspace.com/file/2eermu
Music Fan is offline   Reply With Quote
Old 26th September 2015, 23:20   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,551
Code:
orig=MPEG2Source("Dji ext.d2v")

u=orig.utoy.tfm.vinverse
v=orig.vtoy.tfm.vinverse
YToUV(u,v)
MergeLuma(orig.tfm.trim(1,0))
poisondeathray is offline   Reply With Quote
Old 26th September 2015, 23:30   #5  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 649
Code:
LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
vivan is offline   Reply With Quote
Old 26th September 2015, 23:30   #6  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
Quote:
Originally Posted by poisondeathray View Post
Code:
orig=MPEG2Source("Dji ext.d2v")

u=orig.utoy.tfm.vinverse
v=orig.vtoy.tfm.vinverse
YToUV(u,v)
MergeLuma(orig.tfm.trim(1,0))
Thanks, great !
Do you know what could be the origin of this problem ?
And can you explain a little bit your script ?

There are still little problems ; add separatefields() at the end and look at frames 393, 395, 397, 399 and 401 (196 to 200 without separatefields) : the top of the wall becomes green.
Music Fan is offline   Reply With Quote
Old 26th September 2015, 23:35   #7  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
Quote:
Originally Posted by vivan View Post
Code:
LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
Great ! That seems ok with this script
Music Fan is offline   Reply With Quote
Old 26th September 2015, 23:37   #8  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 649
I can see what the problem is (chroma fields are out of order, maybe they are BFF while luma TFF), but I have no idea how this could have happened.
In my script I change order of chroma fields by using SelectEvery and then remove one field, that matches all fields and makes video progressive.
vivan is offline   Reply With Quote
Old 26th September 2015, 23:37   #9  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,551
vivan's looks correct.

It's a chroma phase delay. I don't know the exact "engineering-speak" mechanism, but I think it's related to PAL hannover bars

https://en.wikipedia.org/wiki/Hanover_bars

Last edited by poisondeathray; 26th September 2015 at 23:42.
poisondeathray is offline   Reply With Quote
Old 27th September 2015, 11:52   #10  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
Thanks, I had never heard of this.
If I get it with really interlaced videos (Tv shows, documentary ...), will vivan's script work too ?

By the way, with other videos (recorded with my new Set-top box that does not crypt its HDD) transfered as is on my pc, I see sometimes the same problem than on first frame (blending) but without chroma phase delay. In this case, can I simply remove first field (which seems to work) or there is something better to do ?
When these videos are movies (originally progressive), tfm() also works. Same question ; is there anything better to do ?

Last edited by Music Fan; 27th September 2015 at 12:01.
Music Fan is offline   Reply With Quote
Old 4th October 2015, 23:43   #11  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
By the way, how to compare with and without effect with this kind of script ?
Quote:
Originally Posted by vivan View Post
Code:
LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
I found this structure, which works with simple scripts (v1 = as is, v2 = black and white);
Code:
v1=LWLibavVideoSource("P:\Dji ext.mpg")
v2=v1.greyscale()
stackhorizontal(v1,v2)
But I don't find how to integrate the lines luma = and chroma = in this kind of structure.
Music Fan is offline   Reply With Quote
Old 5th October 2015, 01:17   #12  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 649
For visual comparisons Interleave function is much better.

In Avisynth each function writes into a variable named "last" unless you explicitly assign it to another variable. For example my code is equal to
Code:
last = LWLibavVideoSource("Dji ext.mpg")
luma = last.SeparateFields().Trim(1, 0).Weave()
chroma = last.SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
last = luma.MergeChroma(chroma)
return last
Now you can see that original video was lost, since last was rewritten. What you can do is just to write result to another variable.
Code:
LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
v1 = luma.MergeChroma(chroma)
Interleave (v1, last)

Last edited by vivan; 5th October 2015 at 11:00.
vivan is offline   Reply With Quote
Old 5th October 2015, 08:34   #13  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
Thanks.

Quote:
Originally Posted by vivan View Post
In Avisynth each function writes into a variable named "last" until you explicitly assign it to another variable.
I guess you mean another function.

Quote:
Originally Posted by vivan View Post
For visual comparisons Interleave function is much better.
But if I really need to see both together, how tu use stack ?
Music Fan is offline   Reply With Quote
Old 5th October 2015, 09:32   #14  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
After some tests I found how to make it ;
Code:
LWLibavVideoSource("P:\Dji ext.mpg")
v2=LWLibavVideoSource("P:\Dji ext.mpg")#without effect
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
stackhorizontal(last,v2)
If I understand correctly, each line correspond to last, except when the sign = is present ; in this case, this line is not used before to be enabled in another line, as v2 enabled in stackhorizontal(last,v2).

edit : actually there is a strange problem : if I add SeparateFields() after this script to get ;
Code:
LWLibavVideoSource("P:\Dji ext.mpg")
v2=LWLibavVideoSource("P:\Dji ext.mpg")#without effect
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
stackhorizontal(last,v2)
SeparateFields()
v2 has a field inversion, while it's supposed to be untouched
I believed that v2 would act as this script ;
Code:
LWLibavVideoSource("P:\Dji ext.mpg")#tff
SeparateFields()
but it's not the case
I guess it's because last became BFF [with Trim(1, 0).Weave()] and last prevails over v2 which is thus forced to become bff.

edit 2 : the field inversion on v2 disappears when I simply reverse last and v2 in the stackhorizontal line ; stackhorizontal(v2,last) instead of stackhorizontal(last,v2)

Last edited by Music Fan; 5th October 2015 at 10:22.
Music Fan is offline   Reply With Quote
Old 5th October 2015, 11:18   #15  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 649
Quote:
Originally Posted by Music Fan View Post
I guess you mean another function.
I meant "unless" not "until", sorry. Yeah, that typo changed my explanation into a complete wrong one.
But no, you assign values to variables... Well, they will be objects in C#/Java, but still not functions. They have "clip" type, so lets simly call them clips.

You don't assign functions to anything, you assign their result. But that result is calculated "lazily", only when it's needed.
Just think about it as if clip was just a number.

Another thing to note is that every function uses "last" as first input if no input is specified. Or uses specified clip, if you write it like this: "clip.function()", which is equal to "function(clip)".

So this code
Code:
LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
actually means
Code:
last = LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields(last)
luma = Trim(luma, 1, 0)
luma = Weave(luma)
chroma = SeparateFields(last)
chroma = SelectEvery(chroma, 2, 1, 0)
chroma = Trim(chroma, 1, 0)
chroma = Weave(chroma)
last = MergeChroma(luma, chroma)
return last
Quote:
Originally Posted by Music Fan View Post
But if I really need to see both together, how tu use stack ?
It has same syntax.

UPD:
Quote:
Originally Posted by Music Fan View Post
After some tests I found how to make it ;
While this works opening video twice is not a "clean" solution. Probably this way it will be easier to modify:
Code:
source = LWLibavVideoSource("P:\Dji ext.mpg")
luma = source.SeparateFields().Trim(1, 0).Weave()
chroma = source.SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
result = luma.MergeChroma(chroma)
StackHorizontal(source, result)
Quote:
Originally Posted by Music Fan View Post
I guess it's because last became BFF [with Trim(1, 0).Weave()] and last prevails over v2 which is thus forced to become bff.
Yes, after you do Weave() clip becomes BFF.

Quote:
Originally Posted by Music Fan View Post
edit 2 : the field inversion on v2 disappears when I simply reverse last and v2 in the stackhorizontal line ; stackhorizontal(v2,last) instead of stackhorizontal(last,v2)
Wiki says that
Quote:
Weave uses the frame-parity information in the source clip to decide which field to put on top. If it gets it wrong, use ComplementParity beforehand or SwapFields afterwards.
Honestly I have no idea how it works.

Last edited by vivan; 5th October 2015 at 11:34.
vivan is offline   Reply With Quote
Old 5th October 2015, 21:07   #16  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,651
Quote:
Originally Posted by vivan View Post
I meant "unless" not "until", sorry. Yeah, that typo changed my explanation into a complete wrong one.
But no, you assign values to variables... Well, they will be objects in C#/Java, but still not functions. They have "clip" type, so lets simly call them clips.

You don't assign functions to anything, you assign their result. But that result is calculated "lazily", only when it's needed.
Just think about it as if clip was just a number.

Another thing to note is that every function uses "last" as first input if no input is specified. Or uses specified clip, if you write it like this: "clip.function()", which is equal to "function(clip)".

So this code
Code:
LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
actually means
Code:
last = LWLibavVideoSource("Dji ext.mpg")
luma = SeparateFields(last)
luma = Trim(luma, 1, 0)
luma = Weave(luma)
chroma = SeparateFields(last)
chroma = SelectEvery(chroma, 2, 1, 0)
chroma = Trim(chroma, 1, 0)
chroma = Weave(chroma)
last = MergeChroma(luma, chroma)
return last
Woaw, I will have to read it several times to understand it, I'm a little bit confused with this.

Quote:
Originally Posted by vivan View Post
While this works opening video twice is not a "clean" solution. Probably this way it will be easier to modify:
Code:
source = LWLibavVideoSource("P:\Dji ext.mpg")
luma = source.SeparateFields().Trim(1, 0).Weave()
chroma = source.SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
result = luma.MergeChroma(chroma)
StackHorizontal(source, result)
Actually my script is simpler. The problem with yours is that I can't add easily functions (I like to see them one above the other).
Is there a way to open only 1 time the video and make a script a simple as mine, without result = and without typing source. each time a new line is added ?

Edit : I believe I have found, tell me if it's ok or if it has disadvantages ;
Code:
v1=LWLibavVideoSource("P:\Dji ext.mpg")
v2=v1
last=v1
luma = SeparateFields().Trim(1, 0).Weave()
chroma = SeparateFields().SelectEvery(2, 1, 0).Trim(1, 0).Weave()
luma.MergeChroma(chroma)
greyscale()#just to show that functions can be added this way
stackhorizontal(last,v2)#last is black and white, v2 is untouched (except its field order)
Quote:
Originally Posted by vivan View Post
Yes, after you do Weave() clip becomes BFF.

Wiki says thatHonestly I have no idea how it works.
There is no problem with weave, the result is logical, I was talking about the order in stackhorizontal.
Here is the explanation, that's what I guessed ;
http://avisynth.nl/index.php/StackHorizontal
Quote:
Most other information (sound track, frame rate, etc) is taken from the first clip
Which explains why the 2nd clip became BFF (as the 1st) while it was originally TFF.

Last edited by Music Fan; 5th October 2015 at 21:32.
Music Fan 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 21:40.


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