This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

[HELP] AviSynth 32 bit - ColorMatrix filter not working for video?
#1
Question 
Try loading the attached "ColorTest.mp4" video into Hybrid.

Enable the ColorMatrix filter for AviSynth, clear "Adjust by Resolution", then select From: Rec.709, To: Rec.601.

Open the previewer, then toggle the check box for ColorMatrix on and off. It has no effect on the preview.

The script looks like this:

ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadCPlugin("C:\PROGRA~1\Hybrid\32bit\AVISYN~1\ffms2.dll")
LoadPlugin("C:\PROGRA~1\Hybrid\32bit\AVISYN~1\ColorMatrix.dll")
# loading source: E:\USER\ColorTest.mp4
#  color sampling YV12@8, matrix: bt709, scantyp: progressive, luminance scale: limited
FFVideoSource("E:\USER\COLORT~1.MP4",colorspace="YV12")
# current resolution: 1440x1080
# color modifications
ColorMatrix(mode="Rec.709->Rec.601",interlaced=false,hints=false)
# filtering
PreFetch(4)
return last


The thing is, the ColorMatrix filter DOES work for VapourSynth.

Enable it for VapourSynth and use the same settings...  clear "Adjust by resolution", then select From: Rec.709, To: Rec.601. Open the previewer and toggle it, and you will see the correct color change.

The script looks like this:

# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading Plugins
core.std.LoadPlugin(path="C:/Program Files/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# source: 'E:\USER\ColorTest.mp4'
# current color space: YUV420P8, bit depth: 8, resolution: 1440x1080, fps: 23.976, color matrix: 709, yuv luminance scale: limited, scanorder: progressive
# Loading E:\USER\ColorTest.mp4 using LibavSMASHSource
clip = core.lsmas.LibavSMASHSource(source="E:/USER/ColorTest.mp4")
# making sure input color matrix is set as 709
clip = core.resize.Point(clip, matrix_in_s="709",range_s="limited")
# making sure frame rate is set to 23.976
clip = core.std.AssumeFPS(clip, fpsnum=24000, fpsden=1001)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# ColorMatrix: adjusting color matrix from 709 to 470bg
clip = core.resize.Bicubic(clip=clip, matrix_in_s="709", matrix_s="470bg", range_in=0, range=0)
# Output
clip.set_output()


I checked, and this behavior is the same in Hybrid version 2020.02.19.1. So it's been like this for a while.

The AviSynth ColorMatrix filter DOES work as expected when using IMAGE streams. It shifts colors the same as the VapourSynth filter does. You can verify this by loading the attached image as an image stream and toggling the filter.

(The reason I'm wanting to do 709 to 601, is I'm processing DVD's with other applications that force a shift to 709 (like running ColorMatrix from 601 to 709). Running this filter afterwards shifts it back to the correct colors.)

I've attached some logs, as well as the source file and single image.

Logs:
[attachment=1086]
[attachment=1087]
[attachment=1085]

Test Video:
[attachment=1088]

Test Image:
[attachment=1089]
Reply
#2
When using '709->601' conversion Hybrid uses:
ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadCPlugin("I:\Hybrid\32bit\AVISYN~1\ffms2.dll")
LoadPlugin("I:\Hybrid\32bit\AVISYN~1\ColorMatrix.dll")
# loading source: F:\TestClips&Co\files\test FFMEG.avi
#  color sampling YV12@8, matrix: bt601, scantyp: progressive, luminance scale: limited
FFVideoSource("F:\TESTCL~1\files\TESTFF~1.AVI",cachefile="E:\Temp\avi_6699eed53e91d42d0c14a1d0daf52a2f_853323747_1_0.ffindex",fpsnum=25,colorspace="YV12")
# current resolution: 640x352
# color modifications
ColorMatrix(mode="Rec.709->Rec.601",interlaced=false,hints=false)
# filtering
# adjust color to RGB32 (for preview)
ConvertToRGB32(matrix="Rec601")
PreFetch(8)
return last
when not using the color matrix conversion, Hybrid used:
ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadCPlugin("I:\Hybrid\32bit\AVISYN~1\ffms2.dll")
# loading source: F:\TestClips&Co\files\test FFMEG.avi
#  color sampling YV12@8, matrix: bt601, scantyp: progressive, luminance scale: limited
FFVideoSource("F:\TESTCL~1\files\TESTFF~1.AVI",cachefile="E:\Temp\avi_6699eed53e91d42d0c14a1d0daf52a2f_853323747_1_0.ffindex",fpsnum=25,colorspace="YV12")
# current resolution: 640x352
# filtering
# adjust color to RGB32 (for preview)
ConvertToRGB32(matrix="Rec601")
PreFetch(8)
return last
as preview scripts.

To check whether something changes I:
  • enabled "Filtering->Avisynth->Filter view"
  • enabled "Filtering->Avisynth->Misc->FiterView->SplitView"
  • selected "Filtering->Avisynth->Misc->FiterView->SplitView->Placement->interleaved"
this way I can switch between an unfiltered and a filter view.
-> seems to be working

After this (which made it easier to spot the changed of the color matrix) I disabled "Filtering->Avisynth->Filter view" and then looked at the changes, when en- and disabling 'ColorMatrix' while it was set to '709->601'.
-> knowing what to look for the changed where there

=> can't reproduce the problem.

Cu Selur
Reply
#3
Let me try to show what is happening to me using 256 color animated gifs. It does at least show in general what is happening to me. It's probably best to right click the images and open them in a new tab, to show them at original size. Pay attention to the colors in the video (image).


Here's the video file (ColorTest.mp4) in AviSynth. I'm toggling the ColorMatrix filter itself off and on. On my system, it has no effect:

[Image: J0zeYjb.gif]



Here's the same video file in VapourSynth. Again, same ColorMatrix filter settings, toggling off and on. The color pallette shifts like it's supposed to:

[Image: TTJfYoZ.gif]



Finally, here's the image (Test-AdobeRGB.png) that was used to make the above video file in AviSynth, loaded as an image stream. Again, same settings for ColorMatrix. Toggling the filter shows it works and shifts the color pallette:

[Image: WpbToUq.gif]

So, the problem for me on my system, is that the AviSynth ColorMatrix filter is NOT working for VIDEO file (in this case .mp4) input.

Can you confirm, that when you load ColorTest4.mp4 into Hybrid, open the AviSynth previewer, and then toggle the ColorMatrix filter on and off with the above settings, if you see the same thing that is shown in the first gif? Or do you see something more like the third gif?

I tried running jobs and saving video files, and what is shown in the previewers is what renders to the output files.
Reply
#4
Not at a computer till later today.
Does it work if you use the filter view like I described before?

Cu Selur
Reply
#5
For AviSynth, I believe it is working for the image stream, because it is an RGB image, and the script runs ConvertToYUY2(interlaced=false, matrix="Rec601")

That is what is actually doing the color palette shift. The ColorMatrix filter is not needed at that point.

So, a workaround for AviSynth for YUV video, is to use the following custom script:

ConvertToRGB(interlaced=false, matrix="Rec709")
ConvertToYUY2(interlaced=false, matrix="Rec601")

or

ConvertToRGB(interlaced=false, matrix="Rec709")
ConvertToYV12(interlaced=false, matrix="Rec601")

Shouldn't ColorMatrix do the above?


(19.10.2020, 07:16)Selur Wrote: Not at a computer till later today.
Does it work if you use the filter view like I described before?

Cu Selur

I did try it as you described, I got the same results. And it renders to output file that way as well.
Reply
#6
Strange thing is that it worked fine for me with mp4 files,....
Reply
#7
Dependency Walker for ColorMatrix.dll shows it has no dependencies other than kernel32.dll, so I wonder if it's a Windows 7/10 problem.

Edit - Probably not, I tried ColorMatrix.dll version 2.5 from 2009, and that didn't work for me either.
Reply
#8
1. If there was a missing dependency loading the library would have failed.
2. check the preview scripts (they are in your temp folder while the Avisynth Preview is open), the problem must be with them

Cu Selur
Reply
#9
Okay, I can reproduce the problem with your sample,...
Works fine with the attached file from me. Smile

-> looking into it Smile
---
Preview script itself looks fine:
ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadCPlugin("I:\Hybrid\32bit\AVISYN~1\ffms2.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 = FFVideoSource("C:\Users\Selur\Desktop\COLORT~1.MP4",cachefile="E:\Temp\mp4_cc56df01aa772a307c11e0e45982b2c1_853323747_1_0.ffindex",colorspace="YV12")
# current resolution: 1440x1080
SourceFiltered = Source
# color modifications
SourceFiltered = SourceFiltered.ColorMatrix(mode="Rec.709->Rec.601",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
-> no clue atm. why, but I noticed another bug. Clipping lection doesn't change the script :/

Using another source filter doesn't make a difference either.

Cu Selur
Ps.: Opened a post over at doom9s, may be someone else sees the problem.
Reply
#10
from doom9s answers:
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

so question is how does the preview code needs to be adjusted?

instead of using two different matrixes, like I did:
SourceFiltered = SourceFiltered.ConvertToRGB32(matrix="Rec601")
Source = Source.ConvertToRGB32(matrix="Rec709")
Should I use both times 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.
?
I suspect it '"Rec709" since I specified it the source was flagged with it', but I'm totally unsure atm. Smile

Cu Selur
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)