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 19th October 2020, 13:24   #1  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
Problem with ColorMatrix

I use this(695kB) clip with:
Code:
ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadPlugin("I:\Hybrid\32bit\AVISYN~1\LSMASHSource.dll")
LoadPlugin("I:\Hybrid\32bit\AVISYN~1\ColorMatrix.dll")
# loading source: C:\Users\Selur\Desktop\ColorTest.mp4
#  color sampling YV12@8, matrix: bt709, scantyp: progressive, luminance scale: limited
Source = LWLibavVideoSource("C:\Users\Selur\Desktop\COLORT~1.MP4",cache=false,format="YUV420P8", prefer_hw=0,repeat=true)
# current resolution: 1440x1080
SourceFiltered = Source
# color modifications
SourceFiltered = SourceFiltered.ColorMatrix(mode="Rec.709->Rec.601",clamp=0,interlaced=false,hints=false)
# filtering
# adjust color to RGB32
SourceFiltered = SourceFiltered.ConvertToRGB32(matrix="Rec601")
# adjust color to RGB32
Source = Source.ConvertToRGB32(matrix="Rec709")
# interleaving for filter preview
Source = Source.Subtitle("Original")
SourceFiltered = SourceFiltered.Subtitle("Filtered") 
Interleave(Source, SourceFiltered)
PreFetch(8)
return last
problem is:

There is no difference between the original and filtered version, as if ColorMatrix had no effect. (on other files this problem does not occur.)

-> What am I missing? What did I do wrong?
Can someone explain why there is no difference? (or are my eyes simply getting to old?)


Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 19th October 2020, 22:22   #2  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
It's the expected result, because you used 2 different ConvertToRGB32 matrices

Source was converted to RGB with 709
SourceFiltered was converted to RGB with 601 . Normally there would be a colorshift , but you compensated for that with colormatrix Rec.709->Rec.601
poisondeathray is offline   Reply With Quote
Old 19th October 2020, 22:31   #3  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
@poisondeathray: Okay, so ColorMatrix X->Y really is basically just ConvertToRGB(matrix=X).Convert<Some YUV color space>(martix=Y) ? I always assumed it did more.

Okay, follow up question:
How do I need to adjust the preview then to view it correctly (I want to compare source and filtered version.

So should I use
Code:
# adjust color to RGB32
SourceFiltered = SourceFiltered.ConvertToRGB32(matrix="Rec601")
# adjust color to RGB32
Source = Source.ConvertToRGB32(matrix="Rec601")
# interleaving for filter preview
Source = Source.Subtitle("Original")
SourceFiltered = SourceFiltered.Subtitle("Filtered") 
Interleave(Source, SourceFiltered)
or
Code:
# adjust color to RGB32
SourceFiltered = SourceFiltered.ConvertToRGB32(matrix="Rec709")
# adjust color to RGB32
Source = Source.ConvertToRGB32(matrix="Rec709")
# interleaving for filter preview
Source = Source.Subtitle("Original")
SourceFiltered = SourceFiltered.Subtitle("Filtered") 
Interleave(Source, SourceFiltered)
or something totally different?

Cu Selur
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 19th October 2020 at 22:48.
Selur is offline   Reply With Quote
Old 19th October 2020, 22:46   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by Selur View Post
@poisondeathray: Okay, so ColorMatrix X->Y really is basically just ConvertToRGB(matrix=X).Convert<Some YUV color space>(martix=Y) ? I always assumed it did more.

Cu Selur
It changes the colors in YUV, "as if" that video had that matrix to begin with.

It doesn't go through a RGB step, and that's the main benefit
poisondeathray is offline   Reply With Quote
Old 19th October 2020, 23:00   #5  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
Ah okay, thanks for clearing that up.
But the question remains: How can I preview and compare source&filtered? (I need RGB32 for Preview)
Should I use:
ConvertToRGB32(matrix="Rec709") since I specified it as 'from' in ColorMatrix
or
ConvertToRGB32(matrix="Rec601") since I specified it as 'to' in ColorMatrix
or
ConvertToRGB32(matrix="Rec709") since I specified it the source was flagged with it.
?

Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 19th October 2020, 23:02   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
This might be worth pointing out.
Someone once asked if "RGB is 601 or 709 ?" [or words of similar meaning].
Matrix only really applies to YUV, and how it was converted from RGB (and how to convert back to RGB again).
You would usually only use ColorMatrix() on RGB if was previously converted wrongly from YUV.
EDIT: RGB is just RGB, it has no matrix, and no need of one.
EDIT: Leastwise, above as I understand it.
__________________
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; 19th October 2020 at 23:28.
StainlessS is offline   Reply With Quote
Old 19th October 2020, 23:13   #7  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
Yes, I know that matrix is only used for YUV<>RGB conversions.
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 20th October 2020, 00:34   #8  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by Selur View Post
But the question remains: How can I preview and compare source&filtered? (I need RGB32 for Preview)
By default, and convention, "HD" uses 709 . So if your video is "HD" dimension use 709, if "SD" use 601 for the RGB conversion. That's what many media players will be using . Some have different definitions for "HD" based on certain width or height . Since you have 1440x1080 (That's "HD" by any definition), use 709 for both RGB conversions
poisondeathray is offline   Reply With Quote
Old 20th October 2020, 05:40   #9  |  Link
pwnsweet
Registered User
 
Join Date: Nov 2008
Posts: 100
Can someone answer this simple question for me please?

I have a 720x540 YV12 source. I want to upscale it and eventually watch it on a HDTV. My filter chain looks like this:

import source
nnedi3_resize16(1440,1080)
colormatrix("rec.601->rec.709")

output as MagicYUV - YUV 4:2:0 using 709 colorspace

Does the resulted, upscaled clip look 'the same' (in terms of colors) on my HDTV as the source clip when also displayed on the HDTV?

Last edited by pwnsweet; 20th October 2020 at 05:48.
pwnsweet is offline   Reply With Quote
Old 20th October 2020, 05:51   #10  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by pwnsweet View Post
Can someone answer this simple question for me please?

I have a 720x540 YV12 source. I want to upscale it and eventually watch it on a HDTV. My filter chain looks like this:

import source
nnedi3_resize16(1440,1080)
colormatrix("rec.601->rec.709")

output as MagicYUV - YUV 4:2:0 using 709 colorspace

Does the resulted, upscaled clip look 'the same' (in terms of colors) on my HDTV as the source clip when also displayed on the HDTV?
It should.

But it depends on your playback chain.

No TV can playback MagicYUV natively

So it depends on what is playing it back, how it's being sent to the TV, where and how the RGB conversion is being done.


You can test a short clip.
poisondeathray is offline   Reply With Quote
Old 20th October 2020, 06:03   #11  |  Link
pwnsweet
Registered User
 
Join Date: Nov 2008
Posts: 100
Quote:
Originally Posted by poisondeathray View Post
It should.

But it depends on your playback chain.

No TV can playback MagicYUV natively

So it depends on what is playing it back, how it's being sent to the TV, where and how the RGB conversion is being done.


You can test a short clip.
OK, let's ignore the final step of outputting as MagicYUV. If I instead encode with x264 and display that on my HDTV, both source and result should display with the same colors?

If that's true...how is it true? The colors visibly change in AVSPmod when I apply colormatrix("rec.601-rec.709"). Is that color change 'reversed' when the TV decodes a YUV HD source (using the 709 matrix) to display it on the RGB screen? Is my undestanding correct here?

Last edited by pwnsweet; 20th October 2020 at 07:15.
pwnsweet is offline   Reply With Quote
Old 20th October 2020, 15:33   #12  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by pwnsweet View Post
The colors visibly change in AVSPmod when I apply colormatrix("rec.601-rec.709"). Is that color change 'reversed' when the TV decodes a YUV HD source (using the 709 matrix) to display it on the RGB screen? Is my undestanding correct here?
How do you have avspmod preview set up?

video => YUV->RGB -> "resolution based" would mean the preview uses 701 for "HD" , 601 for "SD" . If that's the case the should look the same with original video 720x540 video vs. the script. If you had it set to 709 or 601, it should be different . "<= 576" height is usually one of the cut offs for "SD" video, but it might be slightly different in different applications

Another way to check is explicitly control the RGB conversion for the preview with ConvertToRGB(matrix="blah") at the end of the script . The assumption is that HD uses 709, SD uses 601. It's a valid and true assumption for 99.9% of the cases (there are a few exceptions)
poisondeathray is offline   Reply With Quote
Old 29th October 2020, 12:14   #13  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
Quote:
Originally Posted by pwnsweet View Post
If that's true...how is it true? The colors visibly change in AVSPmod when I apply colormatrix("rec.601-rec.709"). Is that color change 'reversed' when the TV decodes a YUV HD source (using the 709 matrix) to display it on the RGB screen? Is my undestanding correct here?
Yes.

The main thing to worry about is if the colors are the same as the source video when you open it directly. Open the source and scripts in different instances of MPC-HC if you want to compare them.

This should display with the same colors as the source.

Code:
import source
nnedi3_resize16(1440,1080)
colormatrix("rec.601->rec.709")
Whereas this wouldn't.

Code:
import source
colormatrix("rec.601->rec.709")
Neither would this:

Code:
import source
nnedi3_resize16(1440,1080)
There's no colorimetry information in the Avisynth raw video output, so MPC-HC (or the renderer) should convert to RGB using rec.601 or Rec.709 based on resolution.

It doesn't hurt to set the correct colorimetry info when encoding with x264. Add this to the command line:

--colormatrix bt709

For standard definition, I use
--colormatrix bt470bg
for PAL and
-colormatrix smpte170m
for NTSC.
(there's no bt601 option)
hello_hello 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 08:36.


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