MPEG2Dec3 : MPEG-2 Decoder for AviSynth 2.5+
(v1.10)
Warning - YV12 inside !!
This filter is designed for AviSynth 2.5 and above;
it is able to output video in RGB24, YUY2 and YV12 color spaces
What it does:
This is a MPEG-2 video decoder.
It is able to decode any MPEG-2 video stream 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.
Usage examples of MPEG2Dec3 package filters:
(all the AviSynth script lines here are only examples)
First, add the following line in your .avs script:
LoadPlugin("MPEG2Dec3.dll") # because AviSynth 2.5 did not yet support auto-loading
Basic MPEG2Dec3 usage :
To do plain YV12 decoding.
MPEG2Source("dvd.d2v")
To use Post Processing - here, deblocking only.
MPEG2Source("dvd.d2v",cpu=4)
It is recommended to use Field Based Post Processing for interlaced sources.
MPEG2Source("dvd.d2v",cpu=4,iPP=true)
If you have an 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")
Color space conversions :
The Following inbuilt color space conversions may cause problems.
Please use the AviSynth core functions where possible!
i.e.
ConvertToRGB24()
ConvertToYUY2(interlaced=false)
etc.
MPEG2Dec3's color space routines:
To convert to YUY2.
MPEG2Source("dvd.d2v")
YV12toYUY2()
To convert a progressive source to YUY2.
MPEG2Source("dvd.d2v")
YV12toYUY2(interlaced=false)
To convert to RGB24.
MPEG2Source("dvd.d2v")
YV12toRGB24()
FlipVertical() #YV12->BGR24 conversion natively flips image
To convert a progressive source to RGB24 .
MPEG2Source("dvd.d2v")
YV12toRGB24(interlaced=false)
FlipVertical() #YV12->BGR24 conversion natively flips image
Useful additional YV12 Filters :
To darken luminosity.
LumaFilter(-10,0.9)
To lighten 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 MPEG2Dec3 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 tuning.
Smaller values are stronger. Use with care.
Default : moderate_h=20, moderate_v=40
idct : 0 to 7
iDCT algorithm used.
0 : Default value (read from .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 :
To use Field-Based Post-Processing.
Recommended if you want to deinterlace.
- True : Field based
- False : Frame based (default)
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, but degraded accuracy.
Included just for testing purposes, and would probably be removed in future versions.
For SSEMMX capable CPU only.
Default : false
cpu2 :
Custom CPU settings
You have to enter a 6 character string.
Each cross (x) would enable the corresponding Post Processing feature.
Other characters act as placeholder; I'd suggest a circle (o).
Example :
"oxoxox"
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)
LumaFilter :
LumaFilter(clip, integer "lumoff", float "lumgain")
The transformation is : y' = (y*lumgain)+lumoff
lumoff :
Luminosity offset.
Default : -2 (for iago ^^)
lumgain :
Luminosity gain.
Default : 1
YV12toRGB24 :
YV12toRGB24(clip, bool "interlaced" bool "TVscale")
YV12->RGB24 conversion natively flips image. Use FilpVertical() afterwards.
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, less accurate than the decoder intergrated PP, but still very efficient
Requires YV12 input.
quant :
Emulated Quantizer.
Use higher value to increase aggressiveness.
Using a value close to the source will allow very accurate post processing.
Default : 2
cpu, cpu2, iPP, moderate_h, moderate_v :
same settings as MPEG2Source's PP.
Defaults : cpu=6, cpu2="", iPP=false, moderate_h=20,
moderate_v=40
History :
based on MPEG2Dec2 (save-oe CVS 28.09.2002)
betas versions (1 to 6)
- added Nic's Post Processing with Field-Based PP
- overrode iDCT / luma filtering choice
- fixed Luma filtering MMX code (3 bugs at least)
- optimised YV12->YUY2 conversion (+10 % speed)
- fixed a PP bug - it's a bit slower now
- disabled trbarry's SSE2 optimisation
- added showQ debugging trigger.
- added vlad's new MC (3Dnow!/SSEMMX) / re-wrote 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 the source a bit more
- added MPEG2Dec3.def default settings loading (like don's filters)
- bff mode in SeparateFieldsYV12
v 0.92 (17.11.02)
- code released
- blindPP implemented
v 0.93 (25.11.02)
- total YV12 code conversion...
- ...which fixed YV12 bugs
- requires less memory
- fast MMX copy (faster seeking)
v 0.94 (08.12.02)
v 1.00 (19.01.03)
- final version
- 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 differently
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 MPEG2Dec3.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 :
Chia-chen Kuo, author of DVD2AVI
Peter Gubanov, author of the MMX/SSEMMX iDCT
Dmitry Rozhdestvensky, author of the SSE2 iDCT
Miha Peternel, author of the Floating Point and Reference iDCT
Mathias Born, author of MPEG2Dec
Special thanks to Nic, for the Post Processing who made MPEG2Dec3 possible
1.01 and above: Nic, trbarry, sh0dan
Thanks to Skal for the use of his iDCT (http://skal.planet-d.net)
Code Distribution :
This is a free sofware distribued under the terms of the GNU-GPL v2
To get the source code, there's a separated rar archive on my site
Contact :