How to use the vapoursynth.YUV function in VapourSynth

To help you get started, we’ve selected a few VapourSynth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github darealshinji / vapoursynth-plugins / scripts / mvsfunc.py View on Github external
# Change chroma sub-sampling if needed
        if dHSubS != sHSubS or dVSubS != sVSubS:
            # Apply depth conversion for processed clip
            clip = Depth(clip, pbitPS, pSType, fulls, fulls, dither, useZ, ampo, ampn, dyn, staticnoise)
            clip = core.fmtc.resample(clip, kernel=kernel, taps=taps, a1=a1, a2=a2, css=css, planes=[2,3,3], fulls=fulls, fulld=fulls, cplace=cplace)
        # Apply depth conversion for output clip
        clip = Depth(clip, dbitPS, dSType, fulls, fulld, dither, useZ, ampo, ampn, dyn, staticnoise)
    elif sIsGRAY:
        # Apply depth conversion for output clip
        clip = Depth(clip, dbitPS, dSType, fulls, fulld, dither, useZ, ampo, ampn, dyn, staticnoise)
        # Shuffle planes for Gray input
        widthc = input.width // dHSubS
        heightc = input.height // dVSubS
        UV = core.std.BlankClip(clip, width=widthc, height=heightc, \
        color=1 << (dbitPS - 1) if dSType == vs.INTEGER else 0)
        clip = core.std.ShufflePlanes([clip,UV,UV], [0,0,0], vs.YUV)
    else:
        # Apply depth conversion for processed clip
        clip = Depth(clip, pbitPS, pSType, fulls, fulls, dither, useZ, ampo, ampn, dyn, staticnoise)
        # Apply matrix conversion for RGB input
        if matrix == "OPP":
            clip = core.fmtc.matrix(clip, fulls=fulls, fulld=fulld, coef=[1/3,1/3,1/3,0, 1/2,0,-1/2,0, 1/4,-1/2,1/4,0], col_fam=vs.YUV)
            clip = SetColorSpace(clip, Matrix=2)
        elif matrix == "2020cl":
            clip = core.fmtc.matrix2020cl(clip, full=fulld)
        else:
            clip = core.fmtc.matrix(clip, mat=matrix, fulls=fulls, fulld=fulld, col_fam=vs.YCOCG if matrix == "YCgCo" else vs.YUV)
        # Change chroma sub-sampling if needed
        if dHSubS != sHSubS or dVSubS != sVSubS:
            clip = core.fmtc.resample(clip, kernel=kernel, taps=taps, a1=a1, a2=a2, css=css, planes=[2,3,3], fulls=fulld, fulld=fulld, cplace=cplace)
        # Apply depth conversion for output clip
        clip = Depth(clip, dbitPS, dSType, fulld, fulld, dither, useZ, ampo, ampn, dyn, staticnoise)
github darealshinji / vapoursynth-plugins / scripts / scoll.py View on Github external
if clipa.num_frames > mask.num_frames:
        mask = core.std.DuplicateFrames(clip=mask,
                                        frames=[mask.num_frames-1] * (clipa.num_frames-mask.num_frames))

    if x != 0 or y != 0:
        clips = vsh.move([clipb, mask], x, y)
        clipb = clips[0]
        mask = clips[1]

    if processing is not None:
        processing = processing.lower()
        if processing == 'yuv':
            if clipa.format.color_family != vs.YUV:
                clipa = core.fmtc.resample(clipa, kernel="lanczos", css="444")
                clipb = core.fmtc.resample(clipb, kernel="lanczos", css="444")
                clipa = core.fmtc.matrix(clipa, mat=matrix, col_fam=vs.YUV)
                clipb = core.fmtc.matrix(clipb, mat=matrix, col_fam=vs.YUV)

        elif processing == 'rgb':
            if clipa.format.color_family != vs.RGB:
                clipa = core.fmtc.resample(clipa, kernel="lanczos", css="444")
                clipb = core.fmtc.resample(clipb, kernel="lanczos", css="444")
                clipa = core.fmtc.matrix(clipa, mat=matrix, col_fam=vs.RGB)
                clipb = core.fmtc.matrix(clipb, mat=matrix, col_fam=vs.RGB)

        else:
            raise ValueError('Unsuported processing mode ("rgb" or "yuv", got: "{}").'.format(processing))

        if clipb.format.bits_per_sample != mask.format.bits_per_sample:
            mask = core.fmtc.bitdepth(mask, bits=clipb.format.bits_per_sample)

    merg = core.std.MaskedMerge(clipa=clipb, clipb=clipa, mask=mask)
github Irrational-Encoding-Wizardry / yuuno / yuuno / core / converter / vs_conv.py View on Github external
def ensure_rgb24(cls, clip: vs.VideoNode, *, matrix=None, compat=False) -> vs.VideoNode:
        """
        Converts the clip to a RGB24 colorspace
        :param clip:    The clip to convert
        :param matrix:  The matrix to use when converting from YUV to RGB
        :return: An RGB24-Clip
        """

        if matrix is None:
            matrix = settings.yuv_matrix

        if clip.format.color_family == vs.YUV:           # Matrix on YUV
            clip = clip.resize.Spline36(
                format=vs.RGB24,
                matrix_in_s=matrix
            )
            
        if clip.format.color_family != vs.RGB or clip.format.bits_per_sample != 8:
            clip = clip.resize.Spline36(
                format=vs.RGB24
            )
            
        if compat:
            clip = clip.resize.Spline36(
                format=vs.COMPATBGR32
            )

        return clip
github darealshinji / vapoursynth-plugins / scripts / vsTAAmbk.py View on Github external
-2: AAEedi3SangNom,
        -3: AANnedi3SangNom,
        'Eedi2': AAEedi2,
        'Eedi3': AAEedi3,
        'Nnedi3': AANnedi3,
        'Nnedi3UpscaleSangNom': AANnedi3UpscaleSangNom,
        'Spline64NrSangNom': AASpline64NRSangNom,
        'Spline64SangNom': AASpline64SangNom,
        'Eedi2SangNom': AAEedi2SangNom,
        'Eedi3SangNom': AAEedi3SangNom,
        'Nnedi3SangNom': AANnedi3SangNom,
        'PointSangNom': AAPointSangNom
    }

    aaed_clip = None
    if clip.format.color_family is vs.YUV:
        y = core.std.ShufflePlanes(edge_enhanced_clip, 0, vs.GRAY)
        u = core.std.ShufflePlanes(edge_enhanced_clip, 1, vs.GRAY)
        v = core.std.ShufflePlanes(edge_enhanced_clip, 2, vs.GRAY)
        if aatype != 0:
            try:
                y = aa_kernel[aatype](y, strength, down8, opencl=opencl, opencl_device=opencl_device, **args).out()
                cycle_y = cycle
                while cycle_y > 0:
                    y = aa_kernel[aatype](y, strength, down8, opencl=opencl, opencl_device=opencl_device, **args).out()
                    cycle_y -= 1
                y = mvf.Depth(y, clip.format.bits_per_sample) if down8 is True else y
            except KeyError:
                raise ValueError(MODULE_NAME + ': unknown aatype.')
        if aatypeu != 0:
            try:
                u = aa_kernel[aatypeu](u, 0, down8, opencl=opencl, opencl_device=opencl_device,
github Irrational-Encoding-Wizardry / fvsfunc / fvsfunc.py View on Github external
if end > clip.num_frames:
        end = clip.num_frames
    if start >= end:
        raise ValueError('InsertSign: "start" must be smaller than or equal to "end"!')
    if matrix == '601':
        matrix = '470bg'
    clip_cf = clip.format.color_family
    overlay_cf = overlay[0].format.color_family

    before = clip[:start] if start != 0 else None
    middle = clip[start:end]
    after = clip[end:] if end != clip.num_frames else None

    matrix_s = None
    matrix_in_s = None
    if clip_cf == vs.YUV and overlay_cf == vs.RGB:
        matrix_s = matrix
    if overlay_cf == vs.YUV and clip_cf == vs.RGB:
        matrix_in_s = matrix
    sign = core.resize.Spline36(overlay[0], clip.width, clip.height, format=clip.format.id,
                                matrix_s=matrix_s, matrix_in_s=matrix_in_s,
                                dither_type='error_diffusion')

    if overlay[1] is None:
        overlay[1] = core.std.BlankClip(sign, format=vs.GRAY8, color=255)
    mask = core.resize.Bicubic(overlay[1], clip.width, clip.height)
    mask = Depth(mask, bits=clip.format.bits_per_sample, range='full', range_in='full')

    middle = core.std.MaskedMerge(middle, sign, mask)

    out = middle
    if before is not None:
github Irrational-Encoding-Wizardry / kagefunc / kagefunc.py View on Github external
def hybriddenoise(src, knl=0.5, sigma=2, radius1=1):
    """
    denoise luma with BM3D (CPU-based) and chroma with KNLMeansCL (GPU-based)
    sigma = luma denoise strength
    knl = chroma denoise strength. The algorithm is different, so this value is different from sigma
    BM3D's sigma default is 5, KNL's is 1.2, to give you an idea of the order of magnitude
    radius1 = temporal radius of luma denoising, 0 for purely spatial denoising
    """
    y = get_y(src)
    y = mvf.BM3D(y, radius1=radius1, sigma=sigma)
    denoised = core.knlm.KNLMeansCL(src, a=2, h=knl, d=3, device_type='gpu', device_id=0, channels='UV')
    return core.std.ShufflePlanes([y, denoised], planes=[0, 1, 2], colorfamily=vs.YUV)
github Irrational-Encoding-Wizardry / fvsfunc / fvsfunc.py View on Github external
h = 720
    if resizer is None:
        resizer = ''
    if yuv444 and not resizer:
        resizer = 'spline36'
    if b is None:
        b = 1/3
    if c is None:
        c = 1/3
    if bits is None:
        bits = src.format.bits_per_sample

    # Value checking
    if src.format.color_family not in [vs.YUV, vs.GRAY, vs.YCOCG]:
        raise TypeError(funcname + ': "src" must be YUV, GRAY or YCOCG color family!')
    if ref.format.color_family not in [vs.YUV, vs.GRAY, vs.YCOCG]:
        raise TypeError(funcname + ': "ref" must be YUV, GRAY or YCOCG color family!')
    if thr < 0.1 or thr > 10.0:
        raise ValueError(funcname + ': "thr" must be in [0.1, 10.0]!')
    if thrc < 0.1 or thrc > 10.0:
        raise ValueError(funcname + ': "thrc" must be in [0.1, 10.0]!')
    if radius <= 0:
        raise ValueError(funcname + ': "radius" must be positive.')
    if radiusc <= 0:
        raise ValueError(funcname + ': "radiusc" must be positive.')
    if elast < 1:
        raise ValueError(funcname + ': Valid range of "elast" is [1, +inf)!')
    if elastc < 1:
        raise ValueError(funcname + ': Valid range of "elastc" is [1, +inf)!')
    if smode not in [0, 1, 2, 3, 4, 5]:
        raise ValueError(funcname + ': "smode" must be in [0, 1, 2, 3, 4, 5]!')
    if smode in [0, 3]:
github darealshinji / vapoursynth-plugins / scripts / mvsfunc.py View on Github external
core = vs.get_core()
    funcName = 'BM3D'
    clip = input
    
    if not isinstance(input, vs.VideoNode):
        raise TypeError(funcName + ': \"input\" must be a clip!')
    
    # Get string format parameter "matrix"
    matrix = GetMatrix(input, matrix, True)
    
    # Get properties of input clip
    sFormat = input.format
    
    sColorFamily = sFormat.color_family
    sIsRGB = sColorFamily == vs.RGB
    sIsYUV = sColorFamily == vs.YUV
    sIsGRAY = sColorFamily == vs.GRAY
    sIsYCOCG = sColorFamily == vs.YCOCG
    if sColorFamily == vs.COMPAT:
        raise ValueError(funcName + ': Color family *COMPAT* is not supported!')
    
    sbitPS = sFormat.bits_per_sample
    sSType = sFormat.sample_type
    
    sHSubS = 1 << sFormat.subsampling_w
    sVSubS = 1 << sFormat.subsampling_h
    
    if full is None:
        # If not set, assume limited range for YUV and Gray input
        # Assume full range for YCgCo and OPP input
        if (sIsGRAY or sIsYUV or sIsYCOCG) and (matrix == "RGB" or matrix == "YCgCo" or matrix == "OPP"):
            fulls = True