Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetMatrix: prefer frameprops of frame 0 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ docs/_build/

# PyBuilder
target/

#VSCode
.vscode/
20 changes: 20 additions & 0 deletions mvsfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@


import vapoursynth as vs
import warnings
import functools
import math

Expand Down Expand Up @@ -2449,6 +2450,10 @@ def GetMatrix(clip, matrix=None, dIsRGB=None, id=False):
if sColorFamily == vs.COMPAT:
raise ValueError(funcName + ': color family *COMPAT* is not supported!')

# Get frameprops of input frame 0
sFrame = clip.get_frame(0)
sFrameProps = sFrame.props

# Get properties of output clip
if dIsRGB is None:
dIsRGB = not sIsRGB
Expand Down Expand Up @@ -2477,6 +2482,7 @@ def GetMatrix(clip, matrix=None, dIsRGB=None, id=False):
# Convert to string format
if matrix is None:
matrix = "Unspecified"
unspec = True
elif not isinstance(matrix, int) and not isinstance(matrix, str):
raise TypeError(funcName + ': \"matrix\" must be an int or a str!')
else:
Expand Down Expand Up @@ -2516,6 +2522,20 @@ def GetMatrix(clip, matrix=None, dIsRGB=None, id=False):
else:
matrix = (6 if id else "601") if SD else (9 if id else "2020") if UHD else (1 if id else "709")

# Check automatic determination conform frameprops, if not, frameprops take precedence
if unspec:
sMatrix = sFrameProps['_Matrix']
dictMatrix = {0:"RGB", 1:"709", 5:"601", 6:"601", 8:"YCgCo", 9:"2020", 10:"2020"}
if not id:
sMatrix = dictMatrix[sMatrix]
if not matrix is sMatrix:
matrix = sMatrix
warnings.warn(funcName + 'automatic determination not conform frameprops, prefer frameprops.')
else:
if not matrix is sMatrix or (matrix == 6 and sMatrix == 5) or (matrix == 9 and sMatrix == 10):
matrix = sMatrix
warnings.warn(funcName + ': automatic determination not conform frameprops, prefer frameprops.')

# Output
return matrix
################################################################################################################################
Expand Down