Skip to content

Instantly share code, notes, and snippets.

@emcodem
Last active June 12, 2023 13:45
Show Gist options
  • Save emcodem/3f0891353971f7256972ba40d111d251 to your computer and use it in GitHub Desktop.
Save emcodem/3f0891353971f7256972ba40d111d251 to your computer and use it in GitHub Desktop.
loadplugin("C:\dev\FFAStrans\Processors\avs_plugins\ffms2\x64\ffms2.dll")
loadplugin("C:\AvsPmod\plugins\fmtconv.dll")
loadplugin("C:\AvsPmod\plugins\avsresize\x64\Release\avsresize.dll")
FFVideoSource("C:\temp\vistek.mxf") #vistek is a bt.709 colorbar
#check initial values in rgb 10 bit format
#z_ConvertFormat(pixel_type="rgbp10",colorspace_op="709:709:709:limited=>rgb:same:same:limited") #full-limited and to 10 bit
#return last
# convert matrix from yuv422 to RGB Float 32 and limited-full
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="709:709:709:limited=>rgb:same:same:full")
# execute the 709-HLG-709 roundtrip (duplicate the lines to simulate mutliple rounds)
c = last
c= BT2087_SDR_TO_HDR_SceneRef(c)
c = BT2407_HDR_TO_SDR_Sceneref(c)
#Finally convert Full-limited and from RGB Float32 to output format, in this case we use rgb10 for measuring.
c = z_ConvertFormat(c, pixel_type="rgbp10",colorspace_op="rgb:709:709:full=>rgb:same:same:limited") #full-limited and to 10 bit
return c
#rbg to linear rgb, input is assumed to be RGBP32 and full.
function BT2087_SDR_TO_HDR_SceneRef(clip c){
# Case #2 on Page3 Bt.2087 ( the goal is to match the colours of a direct Rec. 2020 camera output)
c = fmtc_transfer (c,transs="709",transd="linear",sceneref=true,fulls=true,fulld=true,flt=true)
# M2 on Page 4 Bt.2087
c = fmtc_matrix (c,coef="0.6274 0.3293 0.0433 0 0.0691 0.9195 0.0114 0 0.0164 0.0880 0.8956 0",fulls=true,fulld=true)
# Case #2 on Page4 Bt.2087
c = fmtc_transfer(c,transs="linear",transd="2020",sceneref=true,fulls=true,fulld=true,flt=false)
return c
}
#Linear RGB HLG to 709, "Simple linear matrix conversion" of §2 in Bt.2407
function BT2407_HDR_TO_SDR_Sceneref(clip c){
c = fmtc_transfer (c, transs="2020",transd="linear",sceneref=true,fulls=true,fulld=true,flt=true)
c = fmtc_matrix (c, coef="1.6605 -0.5876 -0.0728 0 -0.1246 1.1329 -0.0083 0 -0.0182 -0.1006 1.1187 0",fulls=true,fulld=true) # matrix from BT.2407 2.2
c = fmtc_transfer(c, transs="linear",transd="709",sceneref=true,fulls=true,fulld=true,flt=false)
return c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment