AnimeSuki Forums

Register Forum Rules FAQ Community Today's Posts Search

Go Back   AnimeSuki Forum > Anime Related Topics > General Anime > Fansub Groups

Notices

Reply
 
Thread Tools
Old 2007-06-03, 13:02   Link #1
TheFluff
Excessively jovial fellow
 
 
Join Date: Dec 2005
Location: ISDB-T
Age: 37
Avisynth Help thread

Since several people have asked me about how to do various things with Avisynth over the last few weeks, I think it's time we had a thread like this. Post your favorite tricks, utility functions, smart ways to do common things, etc.

I'll start off with the absolutely most common question I get:
How do I overlay an AFX clip or a picture on top of a video?
As usual with Avisynth, there's more than one way to do it, but one particularly convenient way is to write a custom function to do it. I did this once and Devastator had his own variant (that I'll let him post himself), but both are hidden deep in the AFX questions thread, so I'll post my version here:
Code:
function insertsign(clip mainclip, clip overlayclip, int startframe, int "endframe") {
	endframe = default(endframe,startframe+overlayclip.framecount()-1)
	endframe = (endframe == 0) ? startframe+overlayclip.framecount()-1 : endframe
	endframe = (endframe >= mainclip.framecount()-1) ? mainclip.framecount()-1 : endframe 
	
	begin	= (startframe == 1) ? mainclip.trim(0,-1) : mainclip.trim(0,startframe-1)
	middle	= mainclip.trim(startframe,endframe)
	end	= (endframe == mainclip.framecount()-1) ? blankclip(mainclip,length=0) : mainclip.trim(endframe+1,0)
	
	middleoverlay = Overlay(middle, overlayclip, mask=overlayclip.showalpha())

	final = (startframe == 0) ? middleoverlay ++ end : begin ++ middleoverlay ++ end
	return final
}
How to use it:
1. Copy-paste the code into an empty text document and rename it to .avsi (not .avs).
2. Put the .avsi in your Avisynth plugins directory.
3. Use the function insertsign(), like so:
The function takes 3 arguments (and one optional one: endframe):
Code:
insertsign(clip, overlayclip, startframe [, endframe])
Clip is the video you want to overlay the picture/AFX sign on. In 99% of all cases, this should be "last" (without the quotes).
Overlayclip is the AFX sign/picture you want to overlay. The function expects this to be a RGB32 clip with a transparency mask. See the AFX thread for details on that, or consult the manual for your image editing programs on how to make transparent PNG's.
Startframe is the frame in "clip" where the overlaying should start.
Endframe is the frame in "clip" where the overlay should end; this parameter is optional and if you don't specify it (or set it to 0), it will default to startframe+length of the overlayclip.
Example usage:
Code:
avisource("X:/stuff/source.avi")
sign1 = avisource("X:/stuff/afx-sign.avi")
logo = imagesource("X:/stuff/logo.png", pixel_type="RGB32", end=100)

insertsign(last, logo, 0)
insertsign(last, sign1, 563, 900)

Is there a way to apply a filter to only a part of a video?
Yes, that's pretty simple, but if you want to do this seriously you'd be best off with using YATTA for it. Anyway, here's how you do it (exactly like YATTA does it, but manually):
Code:
avisource("X:/stuff/example.avi")

function filterchain1(clip c) {
    c
    # do some filtering here
    return last
}

function filterchain2(clip c) {
    c
    # NASTY EVIL BLUR OR SOMETHING HERE
    return last
}

trim(0,500).filterchain1()+trim(501,550).filterchain2()+trim(551,0).filterchain1()

Is there a way to filter only part of a frame?
Yes, it's possible, but probably not worth it. If you insist on doing it anyway, here's how:
Code:
avisource("X:/stuff/example.avi") # let's assume 640x480
top = crop(0, 0, 0, -400) # top 80 lines
middle = crop(0, 80, 0, -100) # middle 300 lines
bottom = crop(0, 380, 0, 0) # bottom 100 lines (I'm probably off by 1 somewhere here, but I can't be assed to correct it)

middle = middle.crazy_evil_filter()

stackvertical(top, middle, bottom)
For more advanced operations you will simply need to split the frame into more parts, and do something like
Code:
stackvertical(stackhorizontal(a, b, c), stackhorizontal(d, e, f), stackhorizontal(g, h, i))
but the exact details are left as an exercise to the reader.


How do I insert a logo/picture before the actual video starts?
Simplest way to do it, if the video isn't VFR:
Code:
avisource("X:/stuff/episode.avi")
logo = imagesource("X:/stuff/logo.png", end=200).converttoyv12().assumefps(last)

logo = audiodub(logo, blankclip(last, length=200))

logo ++ last
How do I change the speed of a clip?
This one is just for lols, but say you wanted a video to play 50% faster:
Code:
avisource("X:/stuff/slow.avi")
assumefps(last.framerate*1.5)
assumesamplerate(int(last.samplerate*1.5))

And that's what I can come up with today. Everyone else feel free to post other contributions or ask questions.
__________________
| ffmpegsource
17:43:13 <~deculture> Also, TheFluff, you are so fucking slowpoke.jpg that people think we dropped the DVD's.
17:43:16 <~deculture> nice job, fag!

01:04:41 < Plorkyeran> it was annoying to typeset so it should be annoying to read

Last edited by TheFluff; 2008-12-10 at 17:19. Reason: typo
TheFluff is offline   Reply With Quote
Old 2007-06-03, 14:49   Link #2
Starks
I see what you did there!
*Scanlator
 
 
Join Date: Apr 2004
Age: 36
Send a message via AIM to Starks
Okay, here's a question. Is it possible to append a single repeating frame onto a video using ImageSource?

Until now, I've been doing it this way.

Code:
ImageSource("image.png", end=72, pixel_type="RGB32").ConvertToYV12()
and then appending it as an avi in a separate script.

Code:
partA=AviSource("encode.avi").AssumeFPS(23.976)                                                                
partB=AviSource("image.avi").AssumeFPS(23.976)
fin=partA++partB
Is there an easier way to do this?
__________________
Starks is offline   Reply With Quote
Old 2007-06-03, 15:22   Link #3
jfs
Aegisub dev
 
 
Join Date: Sep 2004
Location: Stockholm, Sweden
Age: 39
Quote:
Originally Posted by TheFluff View Post
Is there a way to filter only part of a frame?
Yes, it's possible, but probably not worth it. If you insist on doing it anyway, here's how:
Code:
avisource("X:/stuff/example.avi") # let's assume 640x480
top = crop(0, 0, 0, -400) # top 80 lines
middle = crop(0, 80, 0, -100) # middle 300 lines
bottom = crop(0, 380, 0, 0) # bottom 100 lines (I'm probably off by 1 somewhere here, but I can't be assed to correct it)

middle = middle.crazy_evil_filter()

stackvertical(top, middle, bottom)
For more advanced operations you will simply need to split the frame into more parts, and do something like
Code:
stackvertical(stackhorizontal(a, b, c), stackhorizontal(d, e, f), stackhorizontal(g, h, i))
but the exact details are left as an exercise to the reader.
Another way of doing this, though I haven't tested it, would be to crop out the part to be filtered (or crop out from a filtered copy) and use the Overlay function to put it back in. This is probably easier for non-simple cases.
You can also load an alpha mask image with ImageReader and use that mask for the Overlay, if you want non-rectangular areas filtered.


Quote:
Originally Posted by TheFluff View Post
How do I insert a logo/picture before the actual video starts?
Simplest way to do it, if the video isn't VFR:
Code:
avisource("X:/stuff/episode.avi")
logo = imagesource("X:/stuff/logo.png", end=200).converttoyv12().assumefps(last)

logo = audiodub(logo, blankclip(last, length=200)

logo ++ last
I think this can be simplified:
Code:
avisource("X:/stuff/episode.avi")
logo = imagesource("X:/stuff/logo.png", end=200).converttoyv12().assumefps(last)

logo + last
Exploiting that AlignedSplice (single +) will insert silence as needed.


As for Starks's question, there shouldn't be anything preventing you from just:
Code:
partA=AviSource("encode.avi").AssumeFPS(23.976)                                                                
partB=ImageSource("image.png", end=72, pixel_type="RGB32", fps=23.976).ConvertToYV12()
fin=partA++partB
__________________

Aegisub developer [ Forum | Manual | Feature requests | Bug reports | IRC ]
Don't ask for: More VSFilter changes (I won't), karaoke effects, help in PM's
jfs is offline   Reply With Quote
Old 2007-06-03, 16:23   Link #4
martino
makes no files now
 
 
Join Date: May 2006
Quote:
Originally Posted by jfs View Post
I think this can be simplified:
Code:
avisource("X:/stuff/episode.avi")
logo = imagesource("X:/stuff/logo.png", end=200).converttoyv12().assumefps(last)

logo + last
You can also do:
Code:
avisource("X:/stuff/episode.avi")
logo = imagesource("X:/stuff/logo.png").converttoyv12().loop(200).assumefps(last)

logo + last
Where instead of using "end=200" you use "loop(200)" to do the trick. Same output, just slightly different syntax.
__________________
"Light and shadow don't battle each other, because they're two sides of the same coin"
martino is offline   Reply With Quote
Old 2007-06-03, 16:45   Link #5
Starks
I see what you did there!
*Scanlator
 
 
Join Date: Apr 2004
Age: 36
Send a message via AIM to Starks
Anyone know any good sites that list (and possibly explain) syntax that AviSynth can read?
__________________
Starks is offline   Reply With Quote
Old 2007-06-03, 16:55   Link #6
martino
makes no files now
 
 
Join Date: May 2006
You should take a look at the AviSynth Documentation that comes with it, then maybe AviSynth's website (now they have a new MediaWiki which is still being worked on so some stuff is still missing) might have some more stuff, but generally it's the same as in the documentation AFAIK.

(hopefully I understood correctly what you meant there)
__________________
"Light and shadow don't battle each other, because they're two sides of the same coin"
martino is offline   Reply With Quote
Old 2007-06-03, 17:00   Link #7
Starks
I see what you did there!
*Scanlator
 
 
Join Date: Apr 2004
Age: 36
Send a message via AIM to Starks
Quote:
Originally Posted by martino View Post
You should take a look at the AviSynth Documentation that comes with it, then maybe AviSynth's website (now they have a new MediaWiki which is still being worked on so some stuff is still missing) might have some more stuff, but generally it's the same as in the documentation AFAIK.

(hopefully I understood correctly what you meant there)
I guess... <_<

I've been seeing some unfamiliar chains and syntax over the past week or so...
__________________
Starks is offline   Reply With Quote
Old 2007-06-03, 17:04   Link #8
TheFluff
Excessively jovial fellow
 
 
Join Date: Dec 2005
Location: ISDB-T
Age: 37
Quote:
Originally Posted by jfs View Post
I think this can be simplified:
Code:
avisource("X:/stuff/episode.avi")
logo = imagesource("X:/stuff/logo.png", end=200).converttoyv12().assumefps(last)

logo + last
Exploiting that AlignedSplice (single +) will insert silence as needed.
Eh, aligned splice is ++, single + is unaligned. And it doesn't work anyway, because Avisynth doesn't let you splice two clips together where one has audio and the other doesn't, you will get an error message "Splice: one clip has audio and the other doesn't (not allowed)", which is the reason I wrote it like that in the first place. :V

Quote:
Originally Posted by jfs View Post
As for Starks's question, there shouldn't be anything preventing you from just:
Code:
partA=AviSource("encode.avi").AssumeFPS(23.976)                                                                
partB=ImageSource("image.png", end=72, pixel_type="RGB32", fps=23.976).ConvertToYV12()
fin=partA++partB
Actually there IS something that prevents you from doing that, namely the fact that ImageSource's fps argument only takes integer numbers. Which is retarded, but that's the way it is, so you have to do imagesource(...).assumefps(). Otherwise yes, that works.
EDIT: ok, it didn't USE to take floats, but it does now. So yes, it works as advertised.
__________________
| ffmpegsource
17:43:13 <~deculture> Also, TheFluff, you are so fucking slowpoke.jpg that people think we dropped the DVD's.
17:43:16 <~deculture> nice job, fag!

01:04:41 < Plorkyeran> it was annoying to typeset so it should be annoying to read
TheFluff is offline   Reply With Quote
Old 2007-06-03, 19:21   Link #9
edogawaconan
Hi
*Fansubber
 
 
Join Date: Aug 2006
Send a message via MSN to edogawaconan Send a message via Yahoo to edogawaconan
my favorite (very simple) script:
Code:
a=directshowsource("a.avi")
b=directshowsource("b.wmv",convertfps=true)
c=directshowsource("c.mp4",convertfps=true)
d=directshowsource("d.mkv",convertfps=true)
stackhorizontal(stackvertical(a,b),stackvertical(c,d))
basically plays 4 video at once. just make sure all the specs are same (or do manual adjustment as needed).
nice and easy way to compare encodes
__________________
edogawaconan is offline   Reply With Quote
Old 2007-06-03, 19:26   Link #10
Starks
I see what you did there!
*Scanlator
 
 
Join Date: Apr 2004
Age: 36
Send a message via AIM to Starks
Quote:
Originally Posted by edogawaconan View Post
my favorite (very simple) script:
Code:
a=directshowsource("a.avi")
b=directshowsource("b.wmv",convertfps=true)
c=directshowsource("c.mp4",convertfps=true)
d=directshowsource("d.mkv",convertfps=true)
stackhorizontal(stackvertical(a,b),stackvertical(c,d))
basically plays 4 video at once. just make sure all the specs are same (or do manual adjustment as needed).
nice and easy way to compare encodes
Trippy... I gotta try that now. <_<
__________________
Starks is offline   Reply With Quote
Old 2007-06-04, 04:59   Link #11
martino
makes no files now
 
 
Join Date: May 2006
Quote:
Originally Posted by edogawaconan View Post
nice and easy way to compare encodes
Not really if you are using DirectShowSource() since in most cases the frames will not match, might be good enough for basic comparisons, but if you want to be really accurate load avss.dll from Haali's splitter directory and use DSS2() for input. It's frame accurate, but audio input doesn't work with it.

Furthermore you can also do:
Code:
a = AviSource("clip1.avi").ConvertToRGB()
b = AviSource("cllip2.avi").ConvertToRGB()
Compare(a,b)
And it will show the differences in a more "mathematical" way.
__________________
"Light and shadow don't battle each other, because they're two sides of the same coin"
martino is offline   Reply With Quote
Old 2007-06-04, 09:18   Link #12
edogawaconan
Hi
*Fansubber
 
 
Join Date: Aug 2006
Send a message via MSN to edogawaconan Send a message via Yahoo to edogawaconan
Quote:
Originally Posted by martino View Post
Not really if you are using DirectShowSource() since in most cases the frames will not match, might be good enough for basic comparisons, but if you want to be really accurate load avss.dll from Haali's splitter directory and use DSS2() for input. It's frame accurate, but audio input doesn't work with it.
I know, but it looks accurate enough for my recent compares (which basically a video I encoded three times then load them at once with that script). Will try DSS2()
by the way, is dss2()'s frame accuracy comparable to normal xvid encodes in avi?

Quote:
Originally Posted by martino View Post
Furthermore you can also do:
Code:
a = AviSource("clip1.avi").ConvertToRGB()
b = AviSource("cllip2.avi").ConvertToRGB()
Compare(a,b)
And it will show the differences in a more "mathematical" way.
I've seen enough math in my daily life though (that is, being having math as major )
__________________
edogawaconan is offline   Reply With Quote
Old 2007-06-04, 09:57   Link #13
martino
makes no files now
 
 
Join Date: May 2006
Quote:
Originally Posted by edogawaconan View Post
I know, but it looks accurate enough for my recent compares (which basically a video I encoded three times then load them at once with that script). Will try DSS2()
by the way, is dss2()'s frame accuracy comparable to normal xvid encodes in avi?
It should have the same accuracy as when VfW is used, I only tried one sample (mkv and re-encoded to xvid in AVI) and the frames did match wherever I scrolled (IIRC, it's been a while since).

Quote:
Originally Posted by edogawaconan View Post
I've seen enough math in my daily life though (that is, being having math as major )
Ouch... /me puts his hat down
__________________
"Light and shadow don't battle each other, because they're two sides of the same coin"
martino is offline   Reply With Quote
Old 2007-06-04, 23:37   Link #14
Starks
I see what you did there!
*Scanlator
 
 
Join Date: Apr 2004
Age: 36
Send a message via AIM to Starks
What is the difference between AviSource, DirectShowSource, and DSS2?
__________________
Starks is offline   Reply With Quote
Old 2007-06-05, 03:24   Link #15
TheFluff
Excessively jovial fellow
 
 
Join Date: Dec 2005
Location: ISDB-T
Age: 37
Avisource uses VfW codecs and the VfW framework only. Think of it like VirtualDub but in Avisynth. As long as the AVI in question doesn't have any particularly funky hacks, it will always have frame-accurate seeking.
Directshowsource uses Directshow codecs and is hence the Avisynth equivalent of Windows Media Player. It's usually NOT frame-accurate, but it does support VFR, kind of; either through converting to CFR (convertfps=true) or by just reading all frames and ignoring timecodes.
DSS2 is Haali's implementation of Directshowsource. It has the advantage of being frame-accurate, but only supports VFR by converting it to CFR; at least that was the case when I tried it last time, it might have changed.
__________________
| ffmpegsource
17:43:13 <~deculture> Also, TheFluff, you are so fucking slowpoke.jpg that people think we dropped the DVD's.
17:43:16 <~deculture> nice job, fag!

01:04:41 < Plorkyeran> it was annoying to typeset so it should be annoying to read
TheFluff is offline   Reply With Quote
Old 2007-06-06, 13:53   Link #16
Quarkboy
Translator, Producer
 
 
Join Date: Nov 2003
Location: Tokyo, Japan
Age: 44
I might mention that Graft (author of dvd2avi i.e. dgindex) is almost to the beta stages for DGAVCDec, a similar program which allows preindexing and then frame accurate seeking in AVC (i.e. h.264) encoded files, in the exact same manner that dgindex indexes mpeg2 .vob streams.

It's in alpha right now but it works pretty well already. Not only will it improve encoding speed considerably for such sources, but it will make using AVC sources a lot easier to work with in avisynth.

http://forum.doom9.org/showthread.php?t=122598
__________________
Read Light Novels in English at J-Novel Club!
Translator, Producer, Japan Media Export Expert
Founder and Owner of J-Novel Club
Sam Pinansky
Quarkboy is offline   Reply With Quote
Old 2007-06-06, 14:56   Link #17
DarkT
Banned
 
Join Date: Jun 2007
About the applying filters only to certain parts, there's this dude called "stickyboy" and he has a pretty good thing I use lots of times, 's called "RemapFrames" I think...

Here's how you use it:

ReplaceFramesSimple(Tcomb(mode=2,fthreshl=12, othreshl=19),
\ mappings= "[106 218]
[492 540]
[31815 33226]
[33283 33334]
[33420 33434]
[33479 33558]
[33588 33614]
[33851 33947]")
DarkT is offline   Reply With Quote
Old 2007-06-06, 23:12   Link #18
Starks
I see what you did there!
*Scanlator
 
 
Join Date: Apr 2004
Age: 36
Send a message via AIM to Starks
What percent of encoders in the fansub community use Avisynth to the extent that Fluff, quark, or eek do?
__________________
Starks is offline   Reply With Quote
Old 2007-06-06, 23:41   Link #19
skystrife
Encoder
*Fansubber
 
Join Date: Jun 2007
Location: Illinois
Hello all,

I'm just starting to get into the fansubbing scene, mainly doing work on my own in order to get more experienced before actually applying for a job. I'm interested in doing timing and encoding.

Bah, enough about me.

I've got myself a HD RAW, but it's got some flaws that are really quite irritating. Rather than try to describe it using endless gobs of words that make no sense, I'll just show you. This image isn't blown up at all, and hopefully Paint doesn't barf with PNGs as much as it does with JPEGs. >_<

http://skystrife.com/images/weird_edges.png

It's on a(n?) H.264 encode, and it's quite frustrating trying to get rid of. If I aWarpSharp it to death I can get rid of most of the problem, but that in itself causes issues of its own. Would I be best off just applying the heavy aWarpSharp-ing to any areas in the video I see this issue (basically anything that has dark lines that move... -_-)? Have any of you come across this issue before (I'd bet someone has, judging by the sheer amount of experience some of the well-known people here have)?

Last edited by skystrife; 2007-06-06 at 23:43. Reason: Clarification.
skystrife is offline   Reply With Quote
Old 2007-06-07, 04:12   Link #20
Quarkboy
Translator, Producer
 
 
Join Date: Nov 2003
Location: Tokyo, Japan
Age: 44
Quote:
Originally Posted by skystrife View Post
Hello all,

I'm just starting to get into the fansubbing scene, mainly doing work on my own in order to get more experienced before actually applying for a job. I'm interested in doing timing and encoding.

Bah, enough about me.

I've got myself a HD RAW, but it's got some flaws that are really quite irritating. Rather than try to describe it using endless gobs of words that make no sense, I'll just show you. This image isn't blown up at all, and hopefully Paint doesn't barf with PNGs as much as it does with JPEGs. >_<

http://skystrife.com/images/weird_edges.png

It's on a(n?) H.264 encode, and it's quite frustrating trying to get rid of. If I aWarpSharp it to death I can get rid of most of the problem, but that in itself causes issues of its own. Would I be best off just applying the heavy aWarpSharp-ing to any areas in the video I see this issue (basically anything that has dark lines that move... -_-)? Have any of you come across this issue before (I'd bet someone has, judging by the sheer amount of experience some of the well-known people here have)?
That's not a problem with the encoding. It's either a problem with the original broadcast source (bad de-interlacing or upsizing) or a problem with the capture from the source itself.
The best thing to do is to find another raw without the issue. If all the raws have the same problem then it's the fault of the broadcaster themselves, and you have 2 choices:
1. Try warpsharping it to death, or some other solution such as tisophate (one of tritical's avisynth filters that's supposed to help jagged lines like that. Personally I never got it to produce satisfactory results).
2. Ignore it and blame the issue on the broadcasting company.

1. is a lot of work and might end up doing more harm then good. 2. is kind of like a cop out, but hey, you can only do so much.
__________________
Read Light Novels in English at J-Novel Club!
Translator, Producer, Japan Media Export Expert
Founder and Owner of J-Novel Club
Sam Pinansky
Quarkboy 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 -5. The time now is 16:43.


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