Log in

View Full Version : problem with error using ConvertToYV12: invalid "matrix" parameter (RGB data only)


stax76
4th March 2015, 20:27
Can someone explain why the error happens, the source is Y4M.

ConvertToYV12: invalid "matrix" parameter (RGB data only)

(D:\Video\Lossless-Uncompressed streams-sources\1080p\crowd_run_1080p50_Source.avs, line 4)

FFVideoSource("%source_file%", cachefile = "%working_dir%%source_name%.ffindex")
AssumeFPS(%original_framerate%)
ConvertToYV12(matrix="Rec709")

This is my logic to for adding ConvertToYV12.


If Not sourceFilter.Script.Contains("ConvertToYV12") Then
Dim sourceColor = MediaInfo.GetVideo(originalSourcePath, "ChromaSubsampling")

If sourceColor <> "4:2:0" Then
Dim sourceHeight = MediaInfo.GetVideo(originalSourcePath, "Height").ToInt

If sourceHeight > 576 Then
p.AvsDoc.GetFilter("Source").Script += CrLf + "ConvertToYV12(matrix=""Rec709"")"
Else
p.AvsDoc.GetFilter("Source").Script += CrLf + "ConvertToYV12(matrix=""Rec601"")"
End If
End If
End If

StainlessS
4th March 2015, 22:50
From docs

matrix
Default Rec601. Controls the colour coefficients and scaling factors used in RGB - YUV conversions.
"Rec601" : Uses Rec.601 coefficients; scale full range [0..255] RGB to TV range [16..235] YUV, and vice versa.
"Rec709" : Uses Rec.709 coefficients; scale full range [0..255] RGB to TV range [16..235] YUV, and vice versa.
"PC.601" : Uses Rec.601 coefficients, keep full range.
"PC.709" : Uses Rec.709 coefficients, keep full range.
"AVERAGE" : Uses averaged coefficients, keep full range. (So the luma becomes the average of the RGB channels.)

Matrix only valid for ConvertToYV12 where source is RGB.
No idea what your code or MediaInfo thinks is inside it but looks like not being fed RGB.
Suggest what you want is maybe ColorMatrix filter in addition to ConvertToYV12. http://avisynth.org.ru/docs/english/externalfilters/colormatrix.htm

EDIT: You really need to find out what text sourceColor contains, maybe FFVideoSource is returning YUY2 or other YUV.

stax76
4th March 2015, 23:40
Thanks, what I didn't understand was that matrix can only be used for RGB.

StainlessS
4th March 2015, 23:50
Well I'm not sure that I had it correct there, Just checked with v2.6RC1 and no error giving matrix with Yv12 source.
Looked into RC1 source, only similar string I can find is in convert_yuy2.cpp, ie

env->ThrowError("ConvertToYUY2: invalid \"matrix\" parameter (RGB data only)");


I take it that you are using older v2.6 or v2.58.

EDIT: Also similar message in Greyscale.cpp

env->ThrowError("GreyScale: invalid \"matrix\" parameter (RGB data only)");


EDIT: Just checked with v2,58 and that error message is output when converting YV12->YV12 with matrix arg.
Does not occur in v2.6Alpha5. Strange that it is still illegal in 2.6RC1 YUY2 but OK in YV12.

stax76
5th March 2015, 00:49
Very interesting, thank you for investigating, I'll update to 2.6.

martin53
5th March 2015, 08:23
The problem you encountered was one of the reasons I wrapped all ConvertTo() calls in a script that cares for all these conditions where you're not allowed to supply parameters or need them, depending on source format.
You might want to take a look: Cnv2() (http://forum.doom9.org/showthread.php?p=1709547#post1709547)