Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 15th May 2019, 00:31   #1  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: Germany
Posts: 5,720
question on Dither tools

Which format does the script below output and which command line would I use to encode it with x265?

Code:
LoadPlugin("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\avs\AddGrainC\AddGrainC.dll")
LoadPlugin("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\avs\DFTTest\dfttest.dll")
LoadPlugin("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\avs\masktools2\masktools2.dll")
Import("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\AVS\Dither\mt_xxpand_multi.avsi")
LoadPlugin("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\avs\RgTools\RgTools.dll")
Import("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\AVS\Dither\dither.avsi")
LoadPlugin("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\AVS\Dither\dither.dll")
LoadPlugin("C:\Users\frank\Daten\Projekte\VB\staxrip\bin\Apps\Plugins\avs\L-SMASH-Works\LSMASHSource.dll")
LSMASHVideoSource("C:\Users\frank\Daten\Samples\test.mp4")
dither_convert_8_to_16()
dither_quantize(bitdepth=10, reducerange=true, mode=0)
dither_out()
BicubicResize(1280, 720)
Trim(1264, 1563)
stax76 is offline   Reply With Quote
Old 15th May 2019, 01:28   #2  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 33
Hi , i think interleaved-10bit , i tried it with below seems to works fine (i think u don't need an BicubicResize after dither_out).
Code:
avs4x26x --x26x-binary "C:\path\to\x265.exe" --input-depth 10 --sar 1:1 --output-depth 10 -o output.h265 "input.avs"

sorry i missed --sar 40:33 in above cli since my source was 720x480 for the test

or this

avs4x265.exe --input-depth 10 --sar 40:33 --output-depth 10 -o "output.hevc" "input.avs"

or

avs4x265.exe -P x265.exe --input-depth 10 --sar 40:33 --output-depth 10 -o "output.hevc" "input.avs"

Last edited by gugglu; 15th May 2019 at 02:52. Reason: forgot to attach the command line
gugglu is offline   Reply With Quote
Old 15th May 2019, 05:16   #3  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: Germany
Posts: 5,720
I would prefer either avs2pipemod64 or ffmpeg.
stax76 is offline   Reply With Quote
Old 15th May 2019, 11:00   #4  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 33
Quote:
Originally Posted by stax76 View Post
I would prefer either avs2pipemod64 or ffmpeg.
Code:
ok no problem 

avs2pipemod -rawvideo "input.avs" | x264-10bit - --input-depth 10 --input-csp i420 --input-res 720x480 --sar 40:33 --fps 24000/1001 -o "outputx26410bit.264"

avs2pipemod -rawvideo "input.avs" | x265 - --input-depth 10 --input-csp i420 --input-res 720x480 --sar 40:33 --fps 24000/1001 --output-depth 10 -o "outputx26510bit.hevc"
avs2pipemod cause kinda pain (why coz it doesn't read the avs it-self it always ask to define the res/fps/depth/csp which always take minute or two out of my time and sometime i have to double checking the info even take long) but avs4x26x/avs4x265 can read them itself and save time . i am not sure about ffmpeg thats not my handball game maybe someone else can crack that one

Last edited by gugglu; 15th May 2019 at 11:06.
gugglu is offline   Reply With Quote
Old 15th May 2019, 16:38   #5  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 636
Before regular high bit depth was introduced, there were two high bit depth version: stacked and interleaved. Stacked was used by Dither Tools and Interleaved was used by HDRTools, however the most used was stacked by dither tools.
Since Avisynth wasn't actually able to have 16bit internally, but only 8bit, in order to be able to work with 16bit precision, the image was divided in two parts: MSB (most significant bits) and LSB (less significant bits).
With 16bit stacked, the image has double height as MSB and LSB are "stacked" one on the top of the other. This is what Dither_Tools uses.
With 16bit interleaved, the image has double weight as MSB and LSB are "interleaved" one after the other. This is what HDRTools uses.
In you case, this is your code:

Code:
LSMASHVideoSource("C:\Users\frank\Daten\Samples\test.mp4")
dither_convert_8_to_16()
dither_quantize(bitdepth=10, reducerange=true, mode=0)
dither_out()
BicubicResize(1280, 720)
Trim(1264, 1563)
Alright, let's take a look at it:

Code:
LSMASHVideoSource("C:\Users\frank\Daten\Samples\test.mp4")
Now you are indexing your 8bit source, which is fine.

Code:
dither_convert_8_to_16()
Now you have just brought everything from 8bit planar to 16bit stacked.

Code:
dither_quantize(bitdepth=10, reducerange=true, mode=0)
Now you are dithering it down to 10bit stacked.

Code:
dither_out()
Finally, you are outputting 10bit stacked.

Code:
BicubicResize(1280, 720)
Trim(1264, 1563)
Now, this is something you can't do: you can't resize using an 8bit resizer which is not high bit depth aware, 'cause this poor resizer thinks that it's dealing with 8bit data at a "weird" resolution and it just resizes it, screwing up MSB and LSB.

For instance, this is ColorBars 848x480 8bit planar:



This is colorbars 16bit stacked (848x960) 'cause MSB and LSB are stacked one on the top of the other:



Once you apply reduce range, you get 10bit stacked 848x960, 'cause MSB and LSB are still stacked one on the top of the other, but with 10bit precision rather than 16bit.


If you are using a pipe to x264 or x265, you can definitely output 10bit stacked and let it encode it in 10bit planar, however, unless you are using a particular dithering method and you wanna stick with that for any particular reason, then I suggest you to output 16bit stacked to x264/x265 and then let x264/x265 dither it down and encode to 12bit/10bit/8bit planar.
Please note that every time you are using high bit depth (16bit stacked or interleaved) and you wanna filter in Avisynth, the filter you are using MUST be high bit depth aware and you MUST set it to work with the correct version of high bit depth, 'cause otherwise you are gonna screw up MSB and LSB.

I've been stuck with Avisynth 2.6.1 for years after 2016, but in the end I moved to Avisynth+ and I gotta say that it made my life so much easier as I can work with regular 10/12/14/16bit planar, which is great as I don't have to bother about MSB and LSB anymore. Sure, there are some "legacy" filters that have never been updated to work with planar 16bit, so I still have to use 16bit stacked or 16bit interleaved, but in the end I can go from one to the other and always go back to regular 16bit planar and output it to my target application/encoder and be sure that it's gonna read it, no matter what. For instance, with Avisynth+ pinterf mod:

Code:
#Indexing 10bit source
video=FFVideoSource("test.mxf")
audio=FFAudioSource("test.mxf")
AudioDub(video, audio)

#From 10bit planar to 16bit planar
ConvertBits(bits=16)

#From 16bit planar to 16bit stacked
ConvertToStacked()

#Denoise with 16bit precision
dfttest(sigma=64, tbsize=1, lsb_in=true, lsb=true, Y=true, U=true, V=true, opt=3, dither=0)

#From 16bit stacked to 16bit planar
ConvertFromStacked()

#Resize with 16bit planar precision
Spline64Resize(1280, 720)

#Dithering down from 16bit planar to 10bit with the Floyd-Steinber error diffusion
ConvertBits(bits=10, dither=1)

#Clipping for limited TV Range 10bit
Limiter(min_luma=64, max_luma=940, min_chroma=64, max_chroma=940)
As you can see, I can go from an high bit depth version to another.
If I want to, I could go from Planar to Interleaved and vice-versa as well.
If I was in Avisynth 2.6.1, I would have done something like:

Code:
#Indexing 10bit source as 16bit stacked
video=LWLibavVideoSource("test.mxf", stacked=true)
audio=LWLibavAudioSource("test.mxf")
AudioDub(video, audio)

#Denoise with 16bit stacked precision
dfttest(sigma=64, tbsize=1, lsb_in=true, lsb=true, Y=true, U=true, V=true, opt=3, dither=0)

#Resize with 16bit stacked precision
Dither_resize16nr(1280, 720, kernel="spline64")

#Dithering down to 10bit stacked with the Floyd-Steinberg error diffusion
Dither_quantize(bitdepth=10, reducerange=true, mode=6)
And then i had to apply clipping to make sure that luma and chroma are in limited tv range when I encode with the encoder, rather than in Avisynth.

Anyway, I hope this helps and clarifies your doubts about stacked, interleaved and planar.
Please also note that Avisynth 2.6.1 is no longer maintained and that new filters won't work in stacked/interleaved but only in planar. For instance, DGHDRtoSDR by Donald Graft works with 16bit planar only, ResizeMT by Jean Philippe works in planar only, so with Avisynth 2.6.1 it will be limited to 8bit precision, Hable, Mobius and Reinhard tone-mapping algorithms will work in 16bit planar only so you won't be able to use them in Avisynth 2.6.1, Cube will work in planar RGB 16bit only with a good enough precision, 'cause in 8bit planar RGB it would be too approximated and so on.
__________________
Broadcast Encoder
LinkedIn

Last edited by FranceBB; 15th May 2019 at 16:47.
FranceBB is offline   Reply With Quote
Old 15th May 2019, 17:36   #6  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: Germany
Posts: 5,720
@FranceBB

Great explanation, thanks!

@gugglu

You should be fine if your script outputs planar.
stax76 is offline   Reply With Quote
Old 15th May 2019, 18:34   #7  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 33
Quote:
Originally Posted by stax76 View Post
@gugglu

You should be fine if your script outputs planar.
thanks.
gugglu is offline   Reply With Quote
Old 15th May 2019, 18:42   #8  |  Link
Natty
Noob
 
Join Date: Mar 2017
Posts: 188
i think question was how to make x265 and staxrip read the output by this script

dither_convert_8_to_16()
dither_quantize(bitdepth=10, reducerange=true, mode=0)
dither_out()
Natty is offline   Reply With Quote
Old 15th May 2019, 18:48   #9  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 33
Quote:
Originally Posted by Natty View Post
i think question was how to make x265 and staxrip read the output by this script

dither_convert_8_to_16()
dither_quantize(bitdepth=10, reducerange=true, mode=0)
dither_out()


yes thats what i am wondering will staxrip read this script and will it output the correct output instead of the greenish look
gugglu is offline   Reply With Quote
Old 15th May 2019, 18:54   #10  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: Germany
Posts: 5,720
It outputs stacked format, right?

I don't know if stacked format is supported by Avs2pipemod, x265 or ffmpeg, the docs don't contain the word 'stacked'

http://avisynth.nl/index.php/Avs2pipemod

https://x265.readthedocs.io/en/latest/cli.html
stax76 is offline   Reply With Quote
Old 15th May 2019, 19:08   #11  |  Link
Natty
Noob
 
Join Date: Mar 2017
Posts: 188
Quote:
Originally Posted by gugglu View Post


yes thats what i am wondering will staxrip read this script and will it output the correct output instead of the greenish look
can you give example of how you make it work manually without any encoding app?

i dont know much but i think we need a list of native planar high bit depth supported filters, and some filters need to be ported to HBD in avs, which are already working in HBD in VapourSynth
Natty is offline   Reply With Quote
Old 15th May 2019, 19:23   #12  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 33
Quote:
Originally Posted by Natty View Post
can you give example of how you make it work manually without any encoding app?

i dont know much but i think we need a list of native planar high bit depth supported filters, and some filters need to be ported to HBD in avs, which are already working in HBD in VapourSynth
@Natty
yes sure i have all these program x264.exe / x265.exe avs2pipemod and avs4x26x also avs4x265 in this location C:\Users\administrator

and i use these below cli.bat files via cmd.exe to output and it works
Code:
avs2pipemod -rawvideo "input.avs" | x264-10bit - --input-depth 10 --input-csp i420 --input-res 720x480 --sar 40:33 --fps 24000/1001 -o "outputx26410bit.264"

avs2pipemod -rawvideo "input.avs" | x265 - --input-depth 10 --input-csp i420 --input-res 720x480 --sar 40:33 --fps 24000/1001 --output-depth 10 -o "outputx26510bit.hevc"

avs4x265.exe -P x265.exe --input-depth 10 --sar 40:33 --output-depth 10 -o "output.hevc" "input.avs"
@stax76
it was giving the double_width green output when i was trying it in staxrip , but avs2pipemod works fine with command line but it refuse to detect the dither_out hacked format high-bit depth in staxrip this is what is upsetting me a little , for everything else staxrip works brilliant as it should and i m happy with it .

can i request you to add avs4x26x or avs4x265 into staxrip if it is possible?

thanks for the staxrip, really appreciate your great work.
gugglu is offline   Reply With Quote
Old 15th May 2019, 19:33   #13  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: Germany
Posts: 5,720
and if you do this:

dither_convert_8_to_16()
dither_quantize(bitdepth=10, reducerange=true, mode=0)
dither_out()
ConvertFromDoubleWidth(bits=10)
stax76 is offline   Reply With Quote
Old 15th May 2019, 19:42   #14  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 33
Quote:
Originally Posted by stax76 View Post
and if you do this:

dither_convert_8_to_16()
dither_quantize(bitdepth=10, reducerange=true, mode=0)
dither_out()
ConvertFromDoubleWidth(bits=10)
that will work no doubt i guess , thanks foe de tip.

Edit:
Awesome! that works fine, just tried it. bunch of thanks.

Last edited by gugglu; 15th May 2019 at 19:46. Reason: tested the script
gugglu is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:31.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.