View Single Post
Old 15th October 2019, 18:26   #22  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,733
Quote:
Originally Posted by redbtn View Post
Thank you for advice! Can you share your script for Zopti comparison? I just looked Zopti topic, but it's a little complicated for me.
Code:
from vapoursynth import core
from zoptilib import Zopti

orig = core.ffms2.Source(source=r'ridgemont.avi') # lossless intermediate file containing 80-100 single frames throughout the whole movie (see below how I do it)
   
zopti = Zopti(r'results.txt', metrics=['mdsi', 'time'], matrix='709')

b = -110/100.0					# optimize b = _n_/100.0 | -175..-50 | b
c = -10/100.0					# optimize c = _n_/100.0 | -30..70 | c

alternate = core.resize.Bicubic(orig, width=1280, height=688, filter_param_a=b, filter_param_b=c) # this one downsizes the lossless clip to my final size
alternate = core.resize.Bicubic(alternate, width=3840, height=2064, filter_param_a=0, filter_param_b=0.5) # this one upsizes the downsized clip to the full 4K resolution as I have a 4K TV
orig = core.resize.Bicubic(orig, width=3840, height=2064, filter_param_a=0, filter_param_b=0.5) # the lossless clip (having the original resolution minus black borders) is upsized to 4K
zopti.run(orig, alternate) # we compare the upsized original to the downsized-upsized one to get as close as possible
To get the lossless clip, I simply load the source, add the denoising part etc. and then add these ones:

clp = core.std.SelectEvery(clp, 700, 1)
clp = core.std.Trim(clp, 2, 101)

So in this case it would pick one frame in every 700 frames, then trim the result to 100 frames. I do this to make sure the comparison uses various kind of frames throughout the movie. I usually adjust the first line so that the clip length is first something like 105-110 frames, then uncomment the Trim line.
Then I use ffmpeg to encode the lossless clip (you can use FFV1 as the codec for example), like vspipe.exe --y4m "yourscript.vpy" - | c:\utils\ffmpeg\bin\ffmpeg.exe -i - -c:v ffv1 "c:\zopti\yourlosslessclip.avi"

The idea of the Zopti script is to simulate encoding the video in a lower resolution and then your TV or media player will upsize it to 4K when you watch it. We are trying to find optimal parameters in Bicubic to make sure the distortion in the final result is as small as possible. The other metric to try is gmsd, it's faster than mdsi. Usually ends up in a slightly less sharp final result.

This is the Zopti command line I use:
zopti test.vpy -alg mutation -iters dyn -dyniters 15 -dynphases 2 -pop 1 -runs 1 -mutcount 1 -mutamount 0.1 0.01 -initial script

Then from the log file, get the best result for b and c (filter_param_a and filter_param_b in Vapoursynth Bicubic). Place them in your script that you use to encode.
zopti -mode evaluate -log "nameofthezoptilogfilehere.log"

It may look a bit complicated but once you do it a few times, you get the hang of it. I'm quite happy with the results, much better than what I could have done manually.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote