Log in

View Full Version : Having a subtilte appear at intervals


mionis
6th November 2010, 19:08
Hello

I'm fairly new to AviSynth and I'm just getting my barrings.
I have an upcoming project where I need statuc burn-in to appear. This burn-in needs to appear at 5min intervals and last for 30sec during the course of 90min.

Is this possible in AviSynth?

Thank You

Gavino
6th November 2010, 19:45
Something like this will do what you want:
interval = 5 # every 5 mins
duration = 30 # for 30 secs
title = "whatever..."

AviSource(...) # or some suitable source
fInterval = round(60*interval*Framerate())
fDuration = round(duration*Framerate())
ConditionalFilter(last, Subtitle(title), last, "current_frame%fInterval", "<", "fDuration")

mionis
7th November 2010, 23:03
Wow Gavino!!!

Thank you so much for the script. I've been testing it out and it's working well.
You obviously know your stuff!!!
I've been learning from your script and have a few questions.
What are "Conditional Filters"?
There's the command "last" in the Conditional Filter. What does "last" refer too?

Also, is there a way to only have the the subtitle to appear not at the 1st frame but at the 5min and then fall into it's cycle.
Is there to have it end at a perticualr cycle?
Is there a way to do fade's in/out or modicy the opicty?

Thank you again for knowledge and help.

Gavino
8th November 2010, 00:51
What are "Conditional Filters"?
There's the command "last" in the Conditional Filter. What does "last" refer too?
For conditional filters (also known as run-time filters), see
http://avisynth.org/mediawiki/ConditionalFilter and
http://avisynth.org/mediawiki/Runtime_environment
(Before reading these, you'll need a good understanding of the Avisynth basics - see below.)

last is a special variable used by Avisynth to hold the result of the most recent statement that returned a clip.
Here it refers to the source clip.
http://avisynth.org/mediawiki/Grammar
http://avisynth.org/mediawiki/AviSynth_Syntax
Also, is there a way to only have the the subtitle to appear not at the 1st frame but at the 5min and then fall into it's cycle.
Is there to have it end at a perticualr cycle?
Is there a way to do fade's in/out or modicy the opicty
The condition part of ConditionalFilter determines the frames where the subtitle appears, so you can vary this to suit requirements. Eg to omit the title at the very start, use
ConditionalFilter(last, Subtitle(title), last, \
"current_frame >= fInterval && current_frame%fInterval < fDuration", "==", "true")
Fading subtitles in and out is a bit more tricky - the simplest way is usually to use the SubtitleEx (http://avisynth.org/mediawiki/External_filters#Subtitling) plugin. But the ConditionalFilter method won't work for repeated fades as you need a new instance of SubtitleEx for each section. I think it could probably be done using SubtitleEx in combination with stickboy's ApplyEvery (http://avisynth.org/stickboy/) plugin (which is an alternative approach for the plain subtitles too).

mionis
8th November 2010, 15:46
Hello Gavino

Thanks so much for figuring this out. I've been looking over the AviSynth wiki. By nature I'm not a programmer, but I have been having fun working with AviSynth. However, my eduction with this program is in it's early stage. Hope one day too surpase that.

I dowloaded the plugin SubtitlEX. But the documentation that came with it wouldn't open. Don't know what is wrong w/the "dvutilities.chm" file. Have you been able to open this?

If I use a graphic instead of a subtitle. Could I get the same result and more including the frade in/out command?
Or could I nest the susbtle.avs into another overlay script to produce the fade in/out's?

Thanks for your help Gavino. I owe you a beer

Gavino
8th November 2010, 17:18
I dowloaded the plugin SubtitlEX. But the documentation that came with it wouldn't open. Don't know what is wrong w/the "dvutilities.chm" file. Have you been able to open this?
It works fine for me. It is a Windows help file - I don't know if perhaps there is a problem with more recent versions of Windows (I am running XP).

Example use to get a 50 frames fade in/out of titles:
SubtitleEx("Fading title", effects = "f(50,50)")
If I use a graphic instead of a subtitle. Could I get the same result and more including the frade in/out command?
Or could I nest the susbtle.avs into another overlay script to produce the fade in/out's?
The difficult (but not impossible) part in your case is combining the two effects - fading and periodic repeating. Using a graphic instead is possible, but the scripting difficulties would be similar.

But I think something based on this would do the job:
ApplyEvery(fInterval, """SubtitleEx(title, firstFrame=0, lastFrame=fDuration, effects="f(50, 50)")""")

mionis
9th November 2010, 16:08
Hello Gavino

Thanks for the help w/SubtitlEx. I'm on Vista but I'm able to open other .chm files. I'll try and take a look at an XP station later today.

I applied the code you gave and it's showing the words "fade up" but not fadining up or down. I
ve tried changing the vaules with no change in the fade. It pretty much pops on and off.

Here's what I got

ConditionalFilter(last, SubtitleEx("Fading title", effects = "f(50,50)"), last, \
"current_frame >= fInterval && current_frame%fInterval < fDuration", "==", "true")

What am I doing wrong?

Thanks

Gavino
9th November 2010, 16:32
As I said earlier, the fading won't work with the ConditionalFilter method since there is only a single instance of the Subtitle(Ex) and you need a separate one for each repetiton (so that the fade is re-activated).

That's why I suggested using ApplyEvery, which does create a fresh instance of the used filter for each repetition.

The closest equivalent to the ConditionalFilter method would be to use ScriptClip, but it's a bit messier:
ScriptClip("""
offset = current_frame%fInterval
start = current_frame-offset
end = start + fDuration-1
current_frame >= fInterval && offset < fDuration ? \
SubtitleEx("Fading title", firstFrame=start, lastFrame=end, effects = "f(50,50)") : \
last
""")

mionis
11th November 2010, 23:25
The script is working!!! Thank you for walking me through this. I've nested the script into another script to adjust the opacity by 50%.
I've noticed a performance slow down. Does AviSynth require robust CPU power? It's not too big of a deal on my end, but I'm curious if nesting causes memory issues.
Also, I was able to get the .chm file on SubtitlEx to work. With Xp it's not an issue, but if you're on Vista it is. You must right click on the file, go to properties and "unlock" it.

Thanks again for your help

Gavino
12th November 2010, 00:38
I've nested the script into another script to adjust the opacity by 50%.
I've noticed a performance slow down. Does AviSynth require robust CPU power? It's not too big of a deal on my end, but I'm curious if nesting causes memory issues.
What sort of nesting do you mean? What is your final script?

Certainly, using Subtitle inside ScriptClip causes a slowdown, as the filter has a high 'startup' cost and with ScriptClip a new instance of it is created for every frame - the same is probably true of SubtitleEx.

mionis
12th November 2010, 15:51
Here's the nest by overlaying the Subtitle script or my AVI image. I thought this would be a good option if I wanted a gloable opacity setting. So far it's been working well, but if you have any thoughts. I would appreciate it.

a1 = AviSource("horse_race.avi")
a2 = AviSource("subtitle.avs")
mask_clip = Mask(a2, a2.GreyScale.Levels(0, 1, 75, 0, 255))
Overlay(a1, a2, mask=ShowAlpha(mask_clip), y=0, x=0,
\ mode="blend", opacity=0.5)

Gavino
12th November 2010, 17:13
a2 = AviSource("subtitle.avs")
You should use Import instead of AviSource to include a clip created by another script. Using AviSource causes a second independent instance of AviSynth to be loaded. That probably explains your performance drop.