DGDecode 1.2.1 MPEG2 Decoder
for Avisynth 2.5+
Warning: YV12 inside!
This filter is designed for Avisynth 2.5 and above.
It's able to output in RGB24, YUY2 and YV12 colorspaces.
Important Note: This filter was renamed to DGDecode to avoid naming confusions and to
clearly link it with neuron2's version of DVD2AVI called DGIndex. Neuron2
wants to take great pains to acknowledge the origins of DGDecode as described
by MarcFD in the text below! Yes, neuron2 has continued the evolution and made
some fixes, but he stands on the shoulders of the giants documented below in the Credits
section.
What it does:
This is a MPEG-2 decoder. It's able to decode any MPEG-2 streams readable by DVD2AVI.
This version is a modified version of MPEG2Dec2 from save-oe (smart audio video encoder).
The additional features are, for example, YV12, YUY2 and RGB32 output, interlacing control,
integrated PostProcessing, Luminance Filtering, etc.
DGDecode filter usage examples :
All the avisynth script lines here are only examples.
First, add the following line in your .avs script:
LoadPlugin("DGDecode.dll")
Basic DGDecode usage :
To do plain YV12 decoding.
MPEG2Source("dvd.d2v")
To use Post Processing : here, deblocking only.
MPEG2Source("dvd.d2v",cpu=4)
it's better to use Field Based Post Processing for interlaced sources.
MPEG2Source("dvd.d2v",cpu=4,iPP=true)
if you have a intel Pentium 4 cpu, you can force sse2 idct.
MPEG2Source("dvd.d2v",idct=5)
To use custom post processing setting : only deringing here.
MPEG2Source("dvd.d2v",cpu2="ooooxx")
Colorspace conversions :
The following built-in colorspace conversions may cause problems. Please
use the AviSynth functions where possible.
DGDecode's Colorspace routines:
To convert to YUY2.
MPEG2Source("dvd.d2v")
YV12toYUY2()
To convert to YUY2 a progressive source.
MPEG2Source("dvd.d2v")
YV12toYUY2(interlaced=false)
To convert to RGB24.
MPEG2Source("dvd.d2v")
YV12toRGB24()
FlipVertical() #YV12->BGR24 convertion natively flips image
To convert to RGB24 a progressive source.
MPEG2Source("dvd.d2v")
YV12toRGB24(interlaced=false)
FlipVertical() #YV12->BGR24 convertion natively flips image
Useful additional YV12 filters :
To Darken Luminosity.
LumaFilter(-10,0.9)
To Ligthen Luminosity.
LumaFilter(+10,1.1)
Of course you can tweak the settings how you want.
See the Syntax part for more information about it.
Syntax of DGDecode package filters :
MPEG2Source :
MPEG2Source(str "d2v", int "cpu" int "idct" bool "iPP", int "moderate_h", int "moderate_v", bool "showQ", bool "fastMC", str "cpu2")
d2v :
Your DVD2AVI project file. (*.d2v)
cpu : 0 to 6.
DivX decoder like cpu level setting.
- 0 : No PP
- 1 : DEBLOCK_Y_H
- 2 : DEBLOCK_Y_H, DEBLOCK_Y_V
- 3 : DEBLOCK_Y_H, DEBLOCK_Y_V, DEBLOCK_C_H
- 4 : DEBLOCK_Y_H, DEBLOCK_Y_V, DEBLOCK_C_H, DEBLOCK_C_V
- 5 : DEBLOCK_Y_H, DEBLOCK_Y_V, DEBLOCK_C_H, DEBLOCK_C_V, DERING_Y
- 6 : DEBLOCK_Y_H, DEBLOCK_Y_V, DEBLOCK_C_H, DEBLOCK_C_V, DERING_Y, DERING_C
(Y=luma C=chroma, H=horizontal V=vertical)
default : 0
moderate_h, moderate_v :
Post Processing strength fine tunning.
smaller values are stronger. use with care.
default : moderate_h=20, moderate_v=40
info : 0-3.
Debug information.
0 : Do not generate debug information
1 : Overlay debug information on the video
2 : Output debug information via OutputDebugString()
3 : Output hints in the video (as defined in utilities.cpp/utilities.h)
default : 0
idct : 1 to 5.
iDCT : iDCT algo used.
0 : Default value (in .d2v file)
1 : 32 bit MMX
2 : 32 bit SSEMMX
3 : 64 bit FPU
4 : 64 bit IEEE-1180 Reference
5 : 32 bit SSE2 (for P4)
6 : Skal's SSEMMX iDCT (fastest)
7 : SimpleiDCT (Very accurate iDCT from XviD project)
default : 0
iPP : true/false
Field-based post-processing (it's better if you want to deinterlace).
true : Field-based
false : Frame-based (progressive)
default (option not specified) : auto (switches between field/frame based on
the progressive_frame flag)
showQ :
To see the quantizers used for each MB (a fun tool to play with)
default : false
fastMC :
Vlad's Fast Motion Compensation code.
very small speedup, and degraded accuracy
it's here for testing purposes, and would probably be removed in next versions
for ssemmx capable cpu only.
default : false
cpu2 :
Custom cpu settings
you need to enter a 6 charachter string. each cross (x)
would enable the corresponding Post Processing feature :
example :
"ooxxox"
123456
would enable chroma only PP
1 : luma horizontal deblocking
2 : luma vertical deblocking
3 : chroma horizontal deblocking
4 : chroma vertical deblocking
5 : luma deringing
6 : chroma deringing
default : " " (disabled)
upConv : true/false
Upconvert to 4:2:2 from 4:2:0 based on progressive_frame flag
(ignored if the input is not 4:2:0).
true : Upconvert based on progressive_frame flag
false : Don't upconvert
default : false
Use YV12toYUY2(interlaced=true) to upsample always interlaced.
Use YV12toYUY2(interlaced=false) to upsample always progressive.
i420 : true/false
Deliver I420 color space instead of the default YV12
(ignored if the input is not 4:2:0, or if upConv=true).
true : Deliver I420
false : Deliver YV12
default : false
LumaFilter :
LumaFilter(clip, integer "lumoff", float "lumgain")
the transfomation is : yy = (y*lumgain)+lumoff
lumoff :
Luminosity offset.
default = -2 (for iago ^^)
lumgain :
Luminosity gain.
default = 1
YV12toRGB24 :
YV12toRGB24(clip, bool "interlaced" bool "TVscale")
YV12->BGR24 convertion natively flips image
Use FilpVertical() after
interlaced :
set this to true if your source is interlaced,
to interlace chroma correctly.
if you have a progressive stream, using false will
give sharper and real colors
default : true
TVscale :
The same setting as in DVD2AVI.
it may be inversed. try with and without and keep your favorite
default : false
YV12toYUY2 :
YV12toYUY2(clip, bool "interlaced")
interlaced :
set this to true if your source is interlaced,
to interlace chroma correctly.
if you have a progressive stream, using false will
give sharper and real colors
default : true
tff :
Top Field First.
set this to false if you have Bottom Field First.
default : true
BlindPP :
BlindPP(clip, int "quant", int "cpu", str "cpu2", bool "iPP", int "moderate_h", int "moderate_v")
To Deblock and Dering on any kind of DCT-encoded source.
Of course, it's less accurate than the decoder-integrated PP, but still very useful.
Supports YUY2 and YV12 input. Please see APPENDIX A for usage notes.
quant :
Emulated Quantizer
use higher value to increase aggressivity
using a value close to the source will allow very accurate postprocessing
default : 2
cpu, cpu3, iPP, moderate_h, moderate_v :
same settings as MPEG2Source's PP.
defaults : cpu=6,cpu2="",iPP=false,moderate_h=20,moderate_v=40
Deblock :
Deblock()
H.264 deblocking filter by "Manao". Please see here for usage details.
History :
based on MPEG2Dec2 (save-oe CVS 28.09.2002)
betas versions (1 to 6)
- Added Nic's Post Processing with Field-Based PP
- Overrided iDCT / luma filtering choice
- Fixed Luma filtering MMX code (3 bugs at least)
- YV12->YUY2 Convertion optimised (+10 % speed)
- a PP bug fixed. a bit slower now.
- trbarry's SSE2 optimisation disabled.
- Added showQ debugging trigger
- Added vlad's new MC (3dnow/ssemmx) / re-writed ssemmx
- Added working MMX memory transfer for seeking (+3% speed)
- Added Interlaced Upsampling support
v 0.9 (09.11.02)
- heavy code cleaning
- redesigned the whole Avisynth interface
- YV12 support
- RGB24 support
- other misc stuff
v 0.91 (10.11.02)
- cleaned a bit more the source
- added DGDecode.def default settings loading (like don's filters)
- bff mode in SeparateFiledsYV12
v 0.92 (17.11.02)
- code released
- blindPP implemented
v 0.93 (25.11.02)
- total YV12 code convertion...
- ...who fixed YV12 bugs
- less memory is needed
- fast MMX copy (faster seeking)
v 0.94 (08.12.02)
v 1.00 (19.01.03)
- final version
- i squashed all bugs i were aware of
v 1.01 (unknown) - trbarry
Fixed HDTV bug (0x21 PID hardcoded)
v 1.02 (12.05.03) - Nic
aligned malloc done different
v 1.03 (12.05.03) - Nic
Now supports both DVD2AVI 1.77.3 D2V Files and 1.76 ones
v 1.04 (12.05.03) - Nic
Removed another memory leak, slightly quicker
v 1.05a (12.05.03) - trbarry
trbarry test version for optimisations
v 1.06 (24.05.03)
Nic: Added 2 new iDCT's Skal's (fastest!, idct=6) & SimpleiDCT (very accurate, idct=7)
Nic: Support for external use of DGDecode.dll without AviSynth added back in
(See Source code for example.zip and GetPic example)
trbarry: Added new Add_Block optimisations as well as optimised Block Decoding for SSE2 machines
sh0dan: Uses AviSynth's fast BitBlt for mem copys where possible
Nic: General optimisations :) Faster now on all machines tested.
v 1.07 (6.06.03)
Nic & Sh0dan: Bug Fixes, better stability on broken streams
v 1.08 (8.06.03)
trbarry: Optimised Simple_iDCT, lots faster now :)
Nic: added CPUCheck elsewhere, forgot to fix Lumafilter last time (Thanx ARDA!), robUx4 helped me make simple_idct into a fastcall
v 1.09 (26.07.03)
Nic: Now skal's Sparse iDCT is used instead for idct=6 (fastest!)
Nic: Added the Luminance_Filter from DVD2AVI 1.77.3, for when Luminance_Filter is used in the .d2v
v 1.10 (28.07.03)
Nic: Damn! There was a problem with the Luminance filter and 1.77.3 D2V files. Fixed!
Credits :
Mathias Born, author of MPEG2Dec
Donald Graft, for frame loss fix, accurate indexing, PVA support, and more
Peter Gubanov, author of the MMX/SSEMMX iDCT
Chia-chen Kuo, author of DVD2AVI
"MarcFD", for YV12 support and more
Nic, for the post processing
Miha Peternel, author of the Floating Point and Reference iDCT
Dmitry Rozhdestvensky, author of the SSE2 iDCT
"sh0dan", code optimizations
"Skal", for the use of his iDCT
"trbarry", transport parsing, and code optimizations
"tritical", for upsampling, info overlay, and lots of bug fixes
"Manao", Deblock() filter
Code Distribution :
This is free software distributed under the terms of the GNU GPL v2.
To get the source code, there's a separate archive available at the site below.
Latest versions hosted at http://neuron2.net
APPENDIX A. Notes on BlindPP() Usage by Didée
Blocks result from the 8x8-pixel DCT used by the MPEG2 encoder.
So first off, you must be sure that the blocks that you want to deblock are still aligned at 8-pixel boundaries. That means no cropping and no resizing before you apply BlindPP(). If your source is
encoded interlaced, set iPP=true, if it's progressive then the default is already correct (iPP=false).
The parameters are: quant, cpu2, moderate_h, and moderate_v.
"quant" specifies the overall strength at which the deblocking process is to perform.
Set "cpu2" to "xxxxoo" for horizontal and vertical deblocking on luma and chroma, to "xooxoo" for horizontal luma and vertical chroma deblocking, etc. You get the idea.
"moderate_h" and "moderate_v" specify the horizontal and vertical sensitivities, that is, where to perform deblocking, and where not to. They control the sensitivity for recognizing that a block is present.
While "cpu2" and "quant" are pretty clear, the "moderate_X" settings are a little like a black box:
quant=2, moderate_h=35-45, moderate_v=45-55 will give you a very gentle softening on strong, clearly visible blocks only. It will retain very much detail and sharpness, but will also leave intact weaker blocks, and not totally kill stronger ones.
quant=16, moderate_h=15-20, moderate_v=20-30 will perform rather strong deblocking on almost anything that perhaps could be a block, but will also smooth away a lot of detail and sharpness.
The rest is up to you, your taste, and your source material.
One other example: Since the excellent denoiser PixieDust may sometimes cause blocking by itself in moving areas, I sometimes do this:
PixieDust(2).BlindPP(quant=8,cpu2="xxxxoo",moderate_h=45,moderate_v=55)
This takes away a good amount of the most visible blocking, if and only if PixieDust has produced some. On the remaining 99.8% where PixieDust didn't block, this will do almost nothing, as desired.