CrendKing / avisynth_filter

DirectShow filters that put AviSynth and VapourSynth into video playing
MIT License
107 stars 8 forks source link

Does not pass HDR metadata to MadVR #38

Closed aliencaocao closed 3 years ago

aliencaocao commented 3 years ago

Environment

LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64\svpflow1_64.dll") LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64\svpflow2_64.dll")

SetFilterMTMode("DEFAULT_MT_MODE",2) SetFilterMTMode("AvsFilterSource",3) SetFilterMTMode("SVSuper",1) SetFilterMTMode("SVAnalyse",1) ConvertToYV12()

global crop_string = "" global resize_string = "" global super_params = "{pel:1,scale:{up:0},gpu:1,full:false,rc:true}" global analyse_params = "{block:{w:32},main:{search:{coarse:{distance:-8,bad:{sad:2000,range:24}},type:2}},refine:[{thsad:250}]}" global smoothfps_params = "{gpuid:11,rate:{num:25,den:6},algo:23,mask:{area:50},scene:{mode:0}}"

global demo_mode=0 global stereo_type=0

global nvof = 2

########## BEGIN OF base.avs ##########

This file is a part of SmoothVideo Project (SVP) ver.4

This is NOT the full AVS script, all used variables are defined via

JScript code that generates the full script text.

function interpolate(clip src) { input = crop_string=="" ? src : eval("src."+crop_string) input = resize_string=="" ? input : eval("input."+resize_string) nvof=true ? eval(""" super=SVSuper(input, super_params) vectors=SVAnalyse(super, analyse_params, src=input) smooth=SVSmoothFps(input, super, vectors, smoothfps_params, mt=threads, src=src) """) : eval(""" nvof_blk = 16 nvof_src = input.LanczosResize(input.width/nvof_blk4,input.height/nvof_blk4,src_width=-(input.width % nvof_blk),src_height=-(input.height % nvof_blk)) smooth=SVSmoothFps_NVOF(input, smoothfps_params, nvof_src=nvof_src, mt=threads, src=src) """) return demo_mode==0 ? smooth : demo(input,smooth) } input=last stereo_type==0 ? eval(""" interpolate(input) """) : stereo_type==1 ? eval(""" lf = interpolate(input.crop(0,0,input.width/2,0)) rf = interpolate(input.crop(input.width/2,0,0,0)) StackHorizontal(lf, rf) """) : stereo_type==2 ? Eval(""" lf = interpolate(input.crop(0,0,0,input.height/2)) rf = interpolate(input.crop(0,input.height/2,0,0)) StackVertical(lf, rf)""") : input ########### END OF base.avs ########### Prefetch(threads)

- Do you use other DirectShow filters? Specify name and version: Nil

### Describe the bug
Playing a 4KHDR HEVC video from blue ray remux. Add Avsynth filter into MPC-HC external filters and enabled it. Then selected MadVR as the video renderer in MPC settings. MadVR OSD reports receiving BT.709 non-HDR video. The avisynth script is working as MadVR reports correct high frame rate due to the SVP script. However image looks washed out due to the BT.709 and MadVR unable to detect it as HDR video thus does not apply tone mapping. One workaround I found out is to add MadVR into the list of external filters too and place it right below the avisynth filter and enable it. However this approach results in heavy system resource usage as MadVR is being used twice thus processed the video twice (one as an external filter, one as a built-in video renderer). Tested with multiple HDR files, all same behaviour.
In v0.9.1, adding the avisynth filter to external filters list without the MadVR filter results in a black screen e.g. no video output at all, so I believe one of the change made between 0.9.1 and 0.9.2 caused this. Nonetheless, its still an improvement from black screen to displaying it without HDR data.

**Checklist**
- Try a different **video player** and check if the issue persist. For example, if your main video player is MPC-HC, try MPC-BE.
Findings: persist

- Try a different **video renderer** and check if the issue persist. For example, if issue exists with madVR, try EVR.
Findings: persist (only madVR can do tone mapping)

- Try a different **video file** and check if the issue persist. Try another file with different format, dimension and frame rate.
Findings: persist
![image](https://user-images.githubusercontent.com/20109683/107852957-7a1a9900-6e4e-11eb-984c-409db8520dd5.png)
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L5.1@High
HDR format : SMPTE ST 2086, HDR10 compatible
Codec ID : V_MPEGH/ISO/HEVC
Duration : 1 时 30 分
Bit rate : 67.6 Mb/s
Width : 3 840 像素
Height : 2 160 像素
Display aspect ratio : 16:9
Frame rate mode : 恒定帧率 (CFR)
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 位
Bits/(Pixel*Frame) : 0.340
Stream size : 42.9 GiB (93%)
Title : HEVC 4K HDR10
Writing library : ATEME Titan File 3.8.3 (4.8.3.0)
Language : 英语 (English)
Default :
Forced :
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0050 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 739 cd/m2
Maximum Frame-Average Light Level : 331 cd/m2
CrendKing commented 3 years ago

I have a P010 HDR video encoded with HEVC. Tested with AVSF 0.9.2. After enabling SVP to set FPS to 59.94, I see both SVP working, and madVR OSD showing HDR properties passthru. Check screenshot (notice SVP converts video to YUV420P8):

1

Do not add madVR to external filters. Select madVR in 输出.

As usual, first try a minimum avs script instead of relying on SVP, see if it works. SVP introduces lots of variables into the equation. Let's eliminate first.

AvsFilterSource()
return Prefetch(4)

Second, if it still doesn't work, upload log file.

Finally, I might need your video to do the test. You can use ffmpeg to cut a short clip. Test that clip still has problem then upload to a sharing website.

aliencaocao commented 3 years ago

hi, with your given two lines of script, i can confirm that the problem still exists on the same file. I also removed MadVR from external filters and selected it as the output renderer. Here's a screenshot: image I do not have an HDR monitor thus I need MadVR to tone map. From my own observation, the BT.2020 was not passed, only BT.709. And my AVSF didn't convert it to I420. Log: avisynth_filter.log Test video: https://drive.google.com/file/d/1oC83ZXCOeZj05wKSJogyM_5efBboETTC/view?usp=sharing

CrendKing commented 3 years ago

From the log I see you are using ffdshow Video Decoder, which is known to not passthru HDR metadata. Remove it and try again.

I tested your video, and I can see everything works fine (yellow text is injected by AVS Info()):

1

aliencaocao commented 3 years ago

How do I remove it though, there's no settings in MPC-HC that mention ffdshow. I'm using the built-in LAV filters.\ image

CrendKing commented 3 years ago

I don't think MPC-HC bundles ffdshow. One possibility is you registered ffdshow system-wide, and it automatically kicked in (just as madVR). Do a file search, and regsvr32 /u on the ax file. You should confirm it removed in the "Filters" menu in MPC-HC.

aliencaocao commented 3 years ago

I ran the ffdshow uninstaller and the problem was solved. Thanks for the help!