2007-06-03, 13:02 | Link #1 |
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 } 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]) 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) Code:
stackvertical(stackhorizontal(a, b, c), stackhorizontal(d, e, f), stackhorizontal(g, h, i)) 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 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.
__________________
Last edited by TheFluff; 2008-12-10 at 17:19. Reason: typo |
2007-06-03, 14:49 | Link #2 |
I see what you did there!
Scanlator
|
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() Code:
partA=AviSource("encode.avi").AssumeFPS(23.976) partB=AviSource("image.avi").AssumeFPS(23.976) fin=partA++partB
__________________
|
2007-06-03, 15:22 | Link #3 | ||
Aegisub dev
Join Date: Sep 2004
Location: Stockholm, Sweden
Age: 39
|
Quote:
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:
Code:
avisource("X:/stuff/episode.avi") logo = imagesource("X:/stuff/logo.png", end=200).converttoyv12().assumefps(last) logo + last 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
__________________
|
||
2007-06-03, 16:23 | Link #4 | |
makes no files now
Join Date: May 2006
|
Quote:
Code:
avisource("X:/stuff/episode.avi") logo = imagesource("X:/stuff/logo.png").converttoyv12().loop(200).assumefps(last) logo + last
__________________
|
|
2007-06-03, 16:55 | Link #6 |
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)
__________________
|
2007-06-03, 17:00 | Link #7 | |
I see what you did there!
Scanlator
|
Quote:
I've been seeing some unfamiliar chains and syntax over the past week or so...
__________________
|
|
2007-06-03, 17:04 | Link #8 | ||
Excessively jovial fellow
Join Date: Dec 2005
Location: ISDB-T
Age: 37
|
Quote:
Quote:
EDIT: ok, it didn't USE to take floats, but it does now. So yes, it works as advertised.
__________________
|
||
2007-06-03, 19:21 | Link #9 |
Hi
Fansubber
|
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)) nice and easy way to compare encodes
__________________
|
2007-06-03, 19:26 | Link #10 | |
I see what you did there!
Scanlator
|
Quote:
__________________
|
|
2007-06-04, 04:59 | Link #11 |
makes no files now
Join Date: May 2006
|
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)
__________________
|
2007-06-04, 09:18 | Link #12 | |
Hi
Fansubber
|
Quote:
by the way, is dss2()'s frame accuracy comparable to normal xvid encodes in avi? I've seen enough math in my daily life though (that is, being having math as major )
__________________
|
|
2007-06-04, 09:57 | Link #13 | |
makes no files now
Join Date: May 2006
|
Quote:
Ouch... /me puts his hat down
__________________
|
|
2007-06-05, 03:24 | Link #15 |
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.
__________________
|
2007-06-06, 13:53 | Link #16 |
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
__________________
|
2007-06-06, 14:56 | Link #17 |
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]") |
2007-06-06, 23:41 | Link #19 |
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. |
2007-06-07, 04:12 | Link #20 | |
Translator, Producer
Join Date: Nov 2003
Location: Tokyo, Japan
Age: 44
|
Quote:
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.
__________________
|
|
|
|