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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th December 2003, 12:16   #1  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
automated NTSC -> PAL conversion for hybrid clips

Function
Code:
function converter(clip input, int x, int y, bool TFF, int "combth", bool "speedup", bool "show")
	{
	function kernelbob(clip a, int th)
		{
		f=a.
		  \kerneldeint(order=0, sharp=true, twoway=true, threshold=th) 
		e=a.separatefields.trim(1,0).weave.
		  \kerneldeint(order=1, sharp=true, twoway=true, threshold=th)
		interleave(f,e)
		}

	function speeduphybrid(clip i, int width, int height, bool debug)
		{
		comb  = telecide(i,order=1,post=0).decimate(5)
		f     = framerate(comb)

		film  = comb.lanczosresize(width,height).assumefps(25,true)
		film  = (debug == false) ? film : film.subtitle("film -> IVTC -> speedup")

		video = i.kernelbob(5).lanczosresize(width,height).
			\convertfps(2*f).assumefps(50,true).separatefields.selectevery(4,0,3).weave
		video = (debug == false) ? video : video.subtitle("video -> blending -> speedup")
		
		conditionalfilter(comb,video,film,"iscombed(combthr)","=","true")
		}

	function speedupfilm(clip i, int width, int height, bool debug)
		{
		film  = i.assumefps(25,true).lanczosresize(width,height)
		film  = (debug == false) ? film : film.subtitle("film -> speedup")
		return film
		}

	function converthybrid(clip i, int width, int height, bool debug)
		{
		comb  = telecide(i,order=1,post=0).decimate(5)

		film  = comb.lanczosresize(width,height).
			\changefps(50).separatefields.selectevery(4,0,3).weave
		film  = (debug == false) ? film : film.subtitle("film -> IVTC -> convert")

		video = i.kernelbob(5).lanczosresize(width,height).
			\convertfps(50).separatefields.selectevery(4,0,3).weave
		video = (debug == false) ? video : video.subtitle("video -> blending")

		conditionalfilter(convertfps(comb,25),video,film,"iscombed(combthr)","=","true")
		}

	function convertfilm(clip i, int width, int height, bool debug)
		{
		film  = i.lanczosresize(width,height).
			\changefps(50).separatefields.selectevery(4,0,3).weave
		film  = (debug == false) ? film : film.subtitle("film -> convert")
		return film
		}

	combth = default(combth,20)
	global combthr=combth	
	speed = default(speedup,true)
	debug = default(show ,false)

	input = (TFF == true) ? input.assumetff : input.assumebff

	speedupout = (framerate(input) < 26) ? 
		\speedupfilm(input,x,y,debug) : speeduphybrid(input,x,y,debug)

	convertout = (framerate(input) < 26) ? 
		\convertfilm(input,x,y,debug) : converthybrid(input,x,y,debug)

	final = (speed == true) ? speedupout : convertout

	final.resampleaudio(audiorate(input))
	}
Usage
Code:
loadplugin("...\kerneldeint140.dll")
loadplugin("...\decomb510.dll")
import("...\converter.avs")

avisource("hybrid.avi")
converter(768,576,TFF=true,combth=20,speedup=true,show=false)
this function converts a hybrid NTSC-Video automated
to PAL using IVTC on Telecined Film and blending on
the other parts.

You can decide, wheater the video should be speeded up
by 25/23.976 to get progressive Film-parts.

If no speedup is whished, the Film-parts get interlaced,
too. But with better quality then with stupid blending.

If the input-clip is already 23.976 fps, this will be
detected and just a speedup or conversion from 23.976
to 25 will be made.

Parameters:
x - new width
y - new height

TFF - true for TFF-clips, false for BFF-clips

combth - (default = 20) defines the threshold weather the
.........input clip is interlaced or progressive (telecined)

speedup - (default = true)
show - (default = false) shows, which conversion is applied
.........to the video:

29.97 fps input-clip with speedup gives either
"film -> IVTC -> speedup" or "video -> blending -> speedup"

29.97 fps input-clip without speedup gives either
"film -> IVTC -> convert" or "video -> blending"

23.976 fps input-clip shows:
with speedup "film -> speedup"
without speedup "film -> convert"

The Audio stays always in sync with the Video.
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.

Last edited by scharfis_brain; 27th December 2003 at 02:57.
scharfis_brain is offline   Reply With Quote
Old 21st December 2003, 12:29   #2  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Now, this is a nice one! Pity I've not one single NTSC source to test it on.

Remarks:

1) Is "IsCombed = 20" the one-and-only sweetspot, or should that value also be parametrized?

2) For the not-so-advanced users, it should be mentioned that when using speedup, the audio part also gets (dumbly) speed up by ~4% to stay in synch. This is okay since it is the only way to do it in AviSynth. A better solution, though, is to change audio speed with an appropriate external audio editor to preserve pitch.

Once more, good work, Scharfi!

- Didée
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 21st December 2003, 15:00   #3  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
I've already tried to make something like that:
Code:
function speeduphybrid(clip i, int width, int height, int th,  bool debug)
    {i.iscombed(th)}
This returns "Don't know what th means"

thats really weird
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 21st December 2003, 16:28   #4  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Oh, yes.

Some time ago, this was driving me nuts, too.

Try
Code:
function speeduphybrid(clip i, int width, int height, int "th",  bool debug)
Better?

- Didée
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 21st December 2003, 16:47   #5  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
Grrrrrrrrrrrrrrrrrrrr

can't even get
Code:
x=avisource("hybrid.avi").assumetff

a=x.IsCombed()
x = ( a== true) ? x.subtitle("interlaced") : x.subtitle("progressive")
return x
working.

It always claims Invalid arguments to function "IsCombed"

no matter weather I use
x.iscombed()
x.iscombed(20)
iscombed(x) or
iscombed(x,20)

but within my NTSC->PAL converter it is working...

I am totally confused. Can anybody clear this up?
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 21st December 2003, 17:17   #6  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
You need to use it in the conditionalfilter invironment.
Wilbert is offline   Reply With Quote
Old 21st December 2003, 17:44   #7  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
Okay. Found out that (Pseudocode)

function x(clip x, clip y, clip z, int th)
{ conditionalfilter(x,y,z,"iscombed(th)","=","true") }

didn't work


but

global th = yourvalue
function x(clip x, clip y, clip z)
{ conditionalfilter(x,y,z,"iscombed(th)","=","true") }

worked....

weird again.

btw. I've updated the NTSC->PAL conversion-function above with variable combingthreshold
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 21st December 2003, 17:57   #8  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Variables in the conditional invironment need to be global and initiated. Thus something like


function x(clip x, clip y, clip z, int th)
{
global th2 = th
conditionalfilter(x,y,z,"iscombed(th2)","=","true")
}

should also work ...
Wilbert is offline   Reply With Quote
Old 5th January 2004, 21:17   #9  |  Link
verabgd
Registered User
 
Join Date: Jun 2003
Location: Belgrade, Serbia
Posts: 20
Invalid arguments to function “converter”?

@scharfis_brain

I have tried your “converter” but I got the error message in VirtualDubMob: Invalid arguments to function “converter”.

The script is:

++++++++++

loadplugin("...\mpeg2dec3.dll")
loadplugin("...\kerneldeint140.dll")
loadplugin("...\decomb510.dll")
import("...\converter.avs")

video1=MPEG2Source("...\Concert.d2v")
video=converter(video1,768,576,true,20,true,false)

return video
++++++++++++++++++

How to put right arguments? I suppose that the problem is argument “input”, type clip? The source clip must be AVI?

Thank you very much in advance.
verabgd is offline   Reply With Quote
Old 5th January 2004, 22:44   #10  |  Link
Bogalvator
Registered User
 
Join Date: Jun 2003
Location: Northampton, England
Posts: 187
If you replace your last 3 lines of script with:

MPEG2Source("...\Concert.d2v")
ConvertToYUY2(interlaced=true) #so convertfps(...) will work (only used when blending video sections)
converter(768,576,true,20,true,false)

it should be OK. ConvertToYUY2(...) is not required if your source is 100% film.
Bogalvator is offline   Reply With Quote
Old 6th January 2004, 04:00   #11  |  Link
verabgd
Registered User
 
Join Date: Jun 2003
Location: Belgrade, Serbia
Posts: 20
Thanks, but it doesn't work.

Actually it cannot work. If the function is defined as

function converter(clip input, int x, int y, bool TFF, int "combth", bool "speedup", bool "show")

with 7 arguments, function call must have 7 input values.

Function call:

converter(768,576,true,20,true,false)

has 6 input values. The input clip that should be converted is missing?
verabgd is offline   Reply With Quote
Old 6th January 2004, 04:47   #12  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
just use:

Code:
loadplugin("...\mpeg2dec3.dll")
loadplugin("...\kerneldeint140.dll")
loadplugin("...\decomb510.dll")
import("...\converter.avs")

MPEG2Source("...\Concert.d2v")
converttoyuy2(interlaced=true)
converter(768,576,true)
this should work, becase all other parameters are optional
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 7th January 2004, 00:03   #13  |  Link
verabgd
Registered User
 
Join Date: Jun 2003
Location: Belgrade, Serbia
Posts: 20
Yes, it works. Actually the quality of the output video is extremely good! Clean, sharp, with smooth movements … unbelievable for second generation NTSC hybrid tape from 1992! Thanks a lot.
verabgd is offline   Reply With Quote
Old 7th January 2004, 00:54   #14  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
Nice to hear, yuo had success!

I have one question:
sometimes my script fails and thus detecting FILM as Video and vice versa.

could you check your video for some of those parts and report whether the are causing jerks or not?

Please do the same with the cut-points, where Film is becoming Video & vice versa.

use show=true for examining this.


I ask this, because I am PAL-Man who doesn't have any hybrid NTSC.

This function is only build out of theory and synthetic generated clips....
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 7th January 2004, 01:27   #15  |  Link
Bogalvator
Registered User
 
Join Date: Jun 2003
Location: Northampton, England
Posts: 187
Could I suggest that you can replace convertfps(50) in the "function converthybrid" section with changefps(60).decimate(6)

This has the advantage of not having to change to YUY2 and also has no blending. However video may be slightly jerky. See which you prefer....
(The above is only applicable if you set speedup=false)


In my very swift test, I did find that the default value for combth of 20 did result in a large amount of video sections being detected as film - around 30% - which obviously results in a few jerky bits. Reducing this to 10 did help greatly. There were naturally still a few errors but never more than a few isolated frames.
Bogalvator is offline   Reply With Quote
Old 7th January 2004, 01:36   #16  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
just replace convertfps with changefps and you'll get your jerky result.

I dislike discharding 10 out of 60 frames to get 50 fps, because you'll get a really weird 10 Hz motion-stutter.

This is flatten out by convertfps

as you can see, I use changfps for converting 24fps to 25fps (no speedup), (inserting 2 fields per second -> two slight stutters per second) instead of using convertfps here, because this case isn't worth heavy blending.
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 7th January 2004, 15:49   #17  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
this script is superb! i've been looking for a pain free solution for hybrid clips, but just couldn't be bothered writing one for myself

thanks heaps. will try it out right away.

[edit]

nice. i'm curious as to how it handles 30p content? it seems to treat them as filmlike. that's okay, but it means i get the occasional jerky pan in some animes (chobits disc 2, R1)

[edit edit]

ha. looks like you posted while i was editing. yeah, i'd discovered that problem
__________________
sucking the life out of your videos since 2004

Last edited by Mug Funky; 7th January 2004 at 16:02.
Mug Funky is offline   Reply With Quote
Old 7th January 2004, 15:56   #18  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,653
If you want to have even more superbness (does this word exist?), just replace kernelbob with TMCkernelbob or TMCbob...

btw. One thing is unsolved with this converter.avs:
30p Video will be detected as progressive. That means every 5. Frame is taken out, which results in heavy jerkieness on 30p sequences.
But maybe there is a decomb-parameter which can do some blending in such cases?!? I don't know much about tweaking filters, I am just toooo lazy for doing so...

btw. maybe, I am writing the vice versa script for PAL-hybrids to NTSC, hehe (this will be MUCH easier than NTSC -> PAL)
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 9th January 2004, 21:42   #19  |  Link
gomi
Registered User
 
Join Date: Dec 2003
Posts: 5
He!
Is there already a compiled version of this DLL-funktion (Hybrid NTSC > PAL) available to download, or do i have to compile it oneself?

I,ll encode Star Trek NG Season 2 (Hybrid NTSC) soon and i never had such material, so i need to think about a method to handle this.

thanks

Last edited by gomi; 9th January 2004 at 22:37.
gomi is offline   Reply With Quote
Old 9th January 2004, 23:08   #20  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,733
You don't need a dll, the function is there already. You'll need KernelDeint and Decomb 5 though.

You may want to copy-paste the whole function to Notepad and save it to your plugins folder with any name but with the extension avsi so it will be loaded whenever you call any of the included functions in your script.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Reply


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:49.


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