# MPEG2Dec3 : MPEG-2 Decoder for Avisynth 2.5

(v1.00)

## Warning - YV12 inside !!

This filter is designed for Avisynth 2.5
It would work only with Avisynth 2.5 at least
it's able to output in RGB24,YUY2 and YV12 colorspaces

## 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, ect..

## Exemples Usage of MPEG2Dec3 package filters:

(all the avisynth script lines here are only exemples)
First, add the following line in your .avs script :
`
LoadPlugin("MPEG2Dec3.dll") # because Avisynth 2.5 didn't support Autoloading yet
`

### Basic MPEG2Dec3 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 convertions :

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
`

### Usefull additionnal 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 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 tunning.
smaller values are stronger. use with care.
default : moderate_h=20, moderate_v=40

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)
default : 0

iPP :

To use Field-Based Post-Processing.
it' better if you want to deinterlace
- True : Field based
- False : Image 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, 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 :
"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 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, less accurate than decoder intergrated PP, but still very efficient
need YV12 input.
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

## 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 MPEG2Dec3.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)

- very little bugfix

v 1.00 (19.01.03)

- final version
- i squashed all bugs i were aware of

## 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

## 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 :

Don't even doubt of e-mailing me for any suggestion :-), bug report :-(,
feature request :D, or whatever else :-P.
I hope you'll find this prog useful ! (i do...)

Last update 19.01.03 @ 18h00 GMT by MarcFD