View Full Version : AviSynth+ pink pixels fix
kira
8th November 2023, 17:45
https://forum.videohelp.com/attachment.php?attachmentid=74697
ffmpeg.exe -y -i "C:\Users\kira\Downloads\ffmpeg-4.3.1-win64-static\ffmpeg-4.3.1-win64-static\bin\aamegui.avs" -c:v h264_nvenc -cq:v 19 -rc:v vbr -preset:v fast -b:v 18000 -maxrate:v 5000K -bufsize:v 5000K -pix_fmt yuv420p -c:a aac -i encoded2upload.mp4
I added my ffmpeg code. How can I fix this pink pixel issue with a filter?
Selur
8th November 2023, 19:47
Is that a screenshot of the source or of your reencode?
If those artifacts are visible in the reencode and not in the Avisynth preview or your script, it's an encoding issue. (using preset 'slow' instead of 'fast' might help)
If those artifacts are already in the source, share a small section of the source.
kira
8th November 2023, 20:11
The source does not have the same pixel problem. But changing it to slow or -cq:v 15 does not solve the problem. Except loseless i can't fix it.
https://drive.google.com/file/d/1_RcWjAfI30dcT2fwGpjSMBcALp7iiFPd/view?usp=sharing here is the source video. (00.55)
Emulgator
8th November 2023, 23:55
maxrate and bufsize do not expect K, IIRC
kira
9th November 2023, 00:07
maxrate and bufsize do not expect K, IIRC
https://prnt.sc/bFVNZNJCNHRJ
It's now even larger than the source video size, but it's still like this. By the way K working no problem with that.
ffmpeg.exe -y -i "C:\Users\kira\Downloads\ffmpeg-2023-11-02-git-4dbfb52230-full_build\ffmpeg-2023-11-02-git-4dbfb52230-full_build\bin\aamegui.avs" -c:v h264_nvenc -cq:v 15 -rc:v vbr -preset:v fast -b:v 28000000 -maxrate:v 15000000 -bufsize:v 15000000 -pix_fmt yuv420p -c:a aac encoded2upload.mp4
Emulgator
9th November 2023, 00:12
Ah, I see now. nvenc indeed accepts K and M.
Ok, off from HW encoding. What if you use x264? You may lower Chroma qp there if it still fails.
kedautinh12
9th November 2023, 01:02
Try use x264 with veryslow replace h264_nvenc, x264 slower but you will got better details
kira
9th November 2023, 01:03
https://prnt.sc/q6Wc_w0DGyp3
The normal h264 result is fine, but there were 3 different warnings.
[out#0/mp4 @ 0000017a6a5873c0] Codec AVOption cq (Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
[out#0/mp4 @ 0000017a6a5873c0] Codec AVOption rc (Override the preset rate-control) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
[libx264 @ 0000017a7995fec0] max bitrate less than average bitrate, assuming CBR
kira
9th November 2023, 01:10
I know h264 is better but my processor is bad and old and my graphics card is rtx3090. So I need to encode with the graphics card. With the program called Konayuki Plus, with h264_nvenc and crf20, the result is the same as h264. But I need to do this with ffmpeg for my automation software.
kira
9th November 2023, 01:20
https://prnt.sc/Lz4FJpgRizoL
This is h264_nvenc crf/qp 19 konayuki plus result. As you can see, it is the same quality as h264. And the file size is half the size of the source video.
Selur
9th November 2023, 05:42
Looking at the source while using Retinex to better see artifacts&co (since your clearly use higher brightness on playback):
https://imgsli.com/MjE5MzU3
https://imgsli.com/MjE5MzYw
https://imgsli.com/MjE5MzYz
https://imgsli.com/MjE5MzY1
https://imgsli.com/MjE5MzY2
https://imgsli.com/MjE5MzY4
(a simple increase in gamma will also show these artifacts&co, but will not show them as clearly as with using Retinex)
There are way worse scenes,...
Looks to me like:
a. the source already has quite some issues in dark areas (so I would recommend filtering those dark areas recommended)
b. encoding in 10bit hevc (or 10bit avc) would be better, since it would prevent creating new banding during reencoding.
https://imgsli.com/MjE5MzY5
https://imgsli.com/MjE5Mzcw
Looking at the 'hidden details' in dark areas (those artifacts are details to the encoder), it's no wonder high data rates are needed.
Cu Selur
kedautinh12
9th November 2023, 06:47
Is DPIR only use for images??
kedautinh12
9th November 2023, 07:39
Debanding with GradFun3plus is good too :D
https://imgsli.com/MjE5Mzgw
convertbits(16)
GradFun3plus(thr=0.25, radius=10, mask=2, smode=0,UV=1)
fmtc_bitdepth(bits=8, dmode=7)
Selur
9th November 2023, 08:45
@kedautinh12: in Avisynth you can use it through avs-mlrt (https://github.com/Asd-g/avs-mlrt) on video.
(I usually use it through Vapoursynth, but last I checked using it through Avisynth worked fine too)
With your example, one even sees that the pink areas. :)
Cu Selur
kira
9th November 2023, 10:27
ffmpeg -hwaccel auto -i aa.avs -c:v h264_nvenc -rc constqp -qp 20 -vf "ass=test.ass" aa2.mp4 solve the problem
https://prnt.sc/7ecFnrgW0TFz
kedautinh12
9th November 2023, 10:34
@kedautinh12: in Avisynth you can use it through avs-mlrt (https://github.com/Asd-g/avs-mlrt) on video.
(I usually use it through Vapoursynth, but last I checked using it through Avisynth worked fine too)
With your example, one even sees that the pink areas. :)
Cu Selur
I tried use this but I got error this is not video. I think dpir via avs-mlrt only use for image
Selur
9th November 2023, 15:06
@kira: What does the script look like?
@kedautinh12: If you mean that is only works on single frames and has no temporal component, you are correct.
kedautinh12
9th November 2023, 15:14
@kira: What does the script look like?
@kedautinh12: If you mean that is only works on single frames and has no temporal component, you are correct.
And Vs-Dpir can do work on video??
kira
9th November 2023, 15:22
@Selur avs script just DirectShowSource just using for add logo. If you wondering media info you can check https://prnt.sc/sK6GzGlgV-no
Selur
9th November 2023, 15:36
And Vs-Dpir can do work on video??
Both should work on video, but they are filtering frame-by-frame without taking other frames into account, which is true for nearly all models that you can use with mlrt (or VSGAN in Vapoursynth).
https://github.com/cszn/DPIR = Deep Plug-and-Play Image Restoration
If you want something that uses multiple frames, you would need to use BasicVSR++. (afaik. this can not be used in Avisynth atm.)
@kira: just wanted to see the Avisynth script, but since you don't want to show it, that's fine with me.
kira
9th November 2023, 19:58
Both should work on video, but they are filtering frame-by-frame without taking other frames into account, which is true for nearly all models that you can use with mlrt (or VSGAN in Vapoursynth).
https://github.com/cszn/DPIR = Deep Plug-and-Play Image Restoration
If you want something that uses multiple frames, you would need to use BasicVSR++. (afaik. this can not be used in Avisynth atm.)
@kira: just wanted to see the Avisynth script, but since you don't want to show it, that's fine with me.
Thats all nothing special
LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64+\LSMASHSource.dll")
# Load the video
video = DirectShowSource("C:\Users\kira\Downloads\ffmpeg-2023-11-02-git-4dbfb52230-full_build\ffmpeg-2023-11-02-git-4dbfb52230-full_build\bin\aa.mkv", pixel_type="RGB32")
# Load the logo image
logo = ImageSource("C:\Users\kira\Downloads\ffmpeg-2023-11-02-git-4dbfb52230-full_build\ffmpeg-2023-11-02-git-4dbfb52230-full_build\bin\logo2.png", pixel_type="RGB32")
# Set the dimensions
videoWidth = Width(video)
videoHeight = Height(video)
logoWidth = Width(logo)
logoHeight = Height(logo)
# Calculate the position for the logo in the upper right corner
positionX = videoWidth - logoWidth - 10
positionY = 30
# Overlay the logo on the video
Layer(video, logo, "add", opacity=1.0, x=positionX, y=positionY)
Selur
9th November 2023, 20:13
LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64+\LSMASHSource.dll")
isn't used,... at all, seems like the filtering is done by whatever DirectShow filters are used in the background.
kedautinh12
10th November 2023, 01:52
@kedautinh12: With your example, one even sees that the pink areas. :)
Cu Selur
It's better now with UV=3 :D
Script:
convertbits(16)
GradFun3plus(thr=0.5, radius=20, mask=2, smode=0,UV=3)
fmtc_bitdepth(bits=8, dmode=7)
https://imgsli.com/MjE5NTU4
Cu kedautinh12 :D
kedautinh12
10th November 2023, 05:16
@Selur dpir can work in avs+ now but the result doesn't like your, can you share your script from this image???
https://imgsli.com/MjE5Mzcw
Selur
10th November 2023, 06:56
iirc I only used vs-dpir with the default settings.
Yes, just recreated the script:
# Imports
import vapoursynth as vs
# getting Vapoursynth core
import sys
import ctypes
import os
import site
core = vs.core
# Import scripts folder
scriptPath = 'F:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# Adding torch dependencies to PATH
path = site.getsitepackages()[0]+'/torch_dependencies/bin/'
ctypes.windll.kernel32.SetDllDirectoryW(path)
path = path.replace('\\', '/')
os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
# Loading Plugins
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ColorFilter/Retinex/Retinex.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
# source: 'G:\clips\compression artifacts\blocking and artifacts in dark parts.mkv'
# current color space: YUV420P8, bit depth: 8, resolution: 1920x1080, fps: 23.976, color matrix: 709, yuv luminance scale: limited, scanorder: progressive
# Loading G:\clips\compression artifacts\blocking and artifacts in dark parts.mkv using DGSource
clip = core.dgdecodenv.DGSource("J:/tmp/mkv_79b0adfa70e6b824c5567c6dc58265c4_853323747.dgi")# 23.976 fps, scanorder: progressive
# Setting detected color matrix (709).
clip = core.std.SetFrameProps(clip, _Matrix=1)
# Setting color transfer info (709), when it is not set
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=1)
# Setting color primaries info (BT.709), when it is not set
clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=1)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# making sure frame rate is set to 23.976
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
from vsdpir import dpir as DPIR
# adjusting color space from YUV420P8 to RGBH for vsDPIRDeblock
clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="709", range_s="limited")
# deblocking using DPIRDeblock
clip = DPIR(clip=clip, strength=50.000, task="deblock", device_index=0)
# adjusting color space from RGBH to RGB48 for vsRetinex
clip = core.resize.Bicubic(clip=clip, format=vs.RGB48, range_s="limited")
# color adjustment using Retinex
clip = core.retinex.MSRCP(input=clip, sigma=[25,80,250], fulls=False, fulld=False)
# adjusting output color from: RGB48 to YUV420P10 for NVEncModel
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="709", range_s="limited", dither_type="error_diffusion")
# set output frame rate to 23.976fps (progressive)
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# Output
clip.set_output()
is what I used.
kedautinh12
13th November 2023, 05:54
Ok, I got a good result with DPIR in avs+, thank Selur :D
https://imgsli.com/MjE5OTY0
Script
z_ConvertFormat(pixel_type="rgbps", colorspace_op="709:709:709:l=>rgb:709:709:f")
mlrt_DPIR(model=3, strength=50, tiles=2)
z_ConvertFormat(pixel_type="yuv420p10", colorspace_op="rgb:709:709:f=>709:709:709:l")
anton_foy
13th November 2023, 15:01
Ok, I got a good result with DPIR in avs+, thank Selur :D
https://imgsli.com/MjE5OTY0
Script
z_ConvertFormat(pixel_type="rgbps", colorspace_op="709:709:709:l=>rgb:709:709:f")
mlrt_DPIR(model=3, strength=50, tiles=2)
z_ConvertFormat(pixel_type="yuv420p10", colorspace_op="rgb:709:709:f=>709:709:709:l")
Is this with the retinex filter?
maybe try this also? (https://forum.doom9.org/showthread.php?t=182411)
kedautinh12
13th November 2023, 15:25
Yeah, i use with Retinex
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.