Log in

View Full Version : Please review and critique this AVS script


Avisynth_challenged
2nd January 2012, 19:43
Happy New Year, fellow D9F members. Been away from Avisynth for a while, but a small project emerged this week.

The source:
1280x720 @59.94p HD MPEG2 film-based source from ATSC broadcast

The goal:
720x480 @23.976p SD MPEG2 film-based encode, soft telecined to 29.97i (target media = DVD)

The workflow (up to Avisynth usage):

- Edit raw HD MPEG2 source to remove commercials (Videoredo)
- Save edited HD MPEG2 as elementary streams (.m2v/.ac3)
- Run DGIndex on .m2v, save as .d2v project
- Load edited .m2v HD MPEG2 file into Avisynth (v2.57 on WinXP Pro 32-bit SP3 system) via DGDecode
- Output to YUY2 Huffyuv intermediate AVI file

Here is my proposed .avs script:


# These lines call the plugins required for IVTC
LoadPlugin("C:\program files\avisynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\program files\avisynth 2.5\plugins\decomb.dll")
############

# This line loads the MPEG source
MPEG2Source("HD_MPEG2edit.d2v")
############

# This line invokes the IVTC command for 720p source
SelectEvery(2,0)
Decimate(cycle=5)
############

ColorMatrix(mode="Rec.709->Rec.601" , clamp=false)
############

spline36resize(704,480).addborders(8,0,8,0)
############

# This line converts from MPEG2 YV12 to YUY2
converttoyuy2()
############


The final conversion to YUY2 is to prepare the intermediate AVI for SD MPEG2 encoding via CCE 2.70.

What does everyone here think of the overall plan, particularly the HD -> SD conversion via the AVS script presented above? Thanks in advance.

TheSkiller
2nd January 2012, 20:49
What does everyone here think of the overall plan, particularly the HD -> SD conversion via the AVS script presented above?Looks good to me. You didn't forget about all quirks that are involved like colorimetry and non-square pixels. :)

But really, double – no triple check that the source does indeed not contain any real 59.94 parts like edits or so. If it does the "inverse telecine" to 23.976 will give jerky movements at such parts.
I also think there are better ways to do the inverse telecine, SelectEvery(2,0) is probably blowing the cadence. I can't help you with Decimate though, I hardly ever need it being a PAL user.

Oh, one thing I would do differently: put the ConvertToYUY2() before the resize. It will give better vertical chroma resolution in YUY2 when downscaling.

Avisynth_challenged
2nd January 2012, 23:38
Looks good to me. You didn't forget about all quirks that are involved like colorimetry and non-square pixels. :)

Thanks for the feedback. I've been learning about the "quirks" (and there are so many of them) from this excellent forum community here :)


But really, double – no triple check that the source does indeed not contain any real 59.94 parts like edits or so. If it does the "inverse telecine" to 23.976 will give jerky movements at such parts.
I also think there are better ways to do the inverse telecine, SelectEvery(2,0) is probably blowing the cadence. I can't help you with Decimate though, I hardly ever need it being a PAL user.

I appreciate this piece of sound advice. But I have absolute certainty that the 3:2 cadence of the edited source is perfect from beginning to end, so SelectEvery(2,0) is okay to use here. VideoRedo is a terrific MPEG2 editor, and it works wonders with respect to frame accurate cutting and joining of MPEG2 files, allowing me to stitch segments together without changing the 3:2 pattern at any joined edit points (as long as the raw MPEG2 recording had no glitches or dropouts disrupting the cadence originally, and even those can be edited to restore the cadence... although frames will be lost).


Oh, one thing I would do differently: put the ConvertToYUY2() before the resize. It will give better vertical chroma resolution in YUY2 when downscaling.

Okay, how's this:


# These lines call the plugins required for IVTC
LoadPlugin("C:\program files\avisynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\program files\avisynth 2.5\plugins\decomb.dll")
############

# This line loads the MPEG source
MPEG2Source("HD_MPEG2edit.d2v")
############

# This line invokes the IVTC command for 720p source
SelectEvery(2,0)
Decimate(cycle=5)
############

ColorMatrix(mode="Rec.709->Rec.601" , clamp=false)
############

# This line converts from MPEG2 YV12 to YUY2
converttoyuy2()
############

spline36resize(704,480).addborders(8,0,8,0)
############

Thanks for your reply.

hello_hello
3rd January 2012, 00:58
Does the colormatrix line work? Which version are you using?
Regarding the clamp option, from the help files of the version I'm using (2.5):

clamp:

Specifies whether pre/post clipping with limiter to 16-235/16-240 should be used. Possible settings:
0 - no clipping
1 - pre clipping (clip input to ColorMatrix)
2 - post clipping (clip output from ColorMatrix)
3 - pre and post clipping

3 is what previous (v1.x) versions of ColorMatrix used.

default - 3 (int)


Co-incidentally, I just started a thread to have the clamp option clarified if you're interested.
http://forum.doom9.org/showthread.php?p=1548449#post1548449