Log in

View Full Version : How Can I Do MultiColored Subtitle Lines???


Aaron76
10th October 2007, 04:00
I have racked my brain trying to figure out how to do subtitles on the same video sequence with the first line being one color, the title. And the next 2 lines, a different color. I tried applying 2 subtitle functions to the same clip but that doesn't work.

# Variables for Video.
VideoWidthPixels = 768
VideoHeightPixels = 576
VideoFadeFrames = 120
VideoClip = "D:\Videos\BF2 Videos\Battlefield.2.Clips.06..27.avi"

# Variables for IntroVideo.
IntroClipFrames = 300
IntroFadeFrames = 60
IntroScreenshot = "C:\Documents and Settings\Aaron\Desktop\Chopper.png"

# Create Video.
Video = AviSource(VideoClip).ConvertToYV12().Spline64Resize(VideoWidthPixels, VideoHeightPixels)
# Add fade to beginning and end of Video.
Video = FadeIO0(Video, VideoFadeFrames)

# Create IntroVideo, IntroAudio, and combine them into IntroVideo.
# ImageSource() likes to add an extra blank frame to the end, so subtract 1 frame to compensate.
IntroVideo = ImageSource(IntroScreenshot, end=IntroClipFrames - 1, fps=Framerate(Video)).ConvertToYV12().Spline64Resize(VideoWidthPixels, VideoHeightPixels)
IntroAudio = BlankClip(Video, length=IntroClipFrames)
IntroVideo = AudioDub(IntroVideo, IntroAudio)

IntroVideo = Subtitle(IntroVideo, "Different Colored Title\n(KST) ADonat\n(KST) Elite_Marines", x=-1, y=100, first_frame=0,
\last_frame=IntroVideo.framecount-1, font="Comic Sans MS", size=75, text_color=$FF3333, halo_color=$3333FF,
\align=5, spc=50, lsp=1, font_width=0, font_angle=0, interlaced=false).FadeIO0(IntroFadeFrames)

Video = IntroVideo + Video
return Video:thanks:

foxyshadis
10th October 2007, 04:09
With avisynth 2.5.7 you should be able to do this and have them show up in different colors:

subtitle("this is a ",text_color=$FFFF00)
subtitle("\nplaystation black disc",text_color=$151588,lsp=1)

I just tested, came out okay. Just make sure the \n is the first character of the second one, otherwise you have to fiddle with the y value.

Aaron76
10th October 2007, 05:05
I tried taking out all the arguments. Basically I stripped it down to -> Subtitle("This should of worked.")

It throws an error of invalid argument in function Subtitle. I assume Subtitle would work on the special variable "last" if an argument was not specified in the function. It works in a script by itself. And you are right that it does work. But it does not work in my script for some odd reason. I thought I could just keep adding different colored subtitles if I specified IntroVideo as an argument or left that out and just applied subtitles right after I created the IntroVideo.

I am using avisynth 2.5.8. I might just restore the backup image to my hard drive and install the latest stable just to be sure. Although I think I might of tried that already.

Aaron76
10th October 2007, 05:42
Reverted back to 2.5.7 Still no luck. I tried your script a second time. I may have been too fast to say that I had gotten it to work. I have multicolored text that is already in the top left corner for the actual video. DOH. BF2 text chat stuff. Anyways, it seems the second subtitle function cancels out the first one. So all I am seeing is the last line of text. I tried taking out the IntroVideo= so it is just Subtitle(arguments), but that is throwing an error. Removing all arguments except the "text" is throwing an invalid arguments error too.

foxyshadis
10th October 2007, 08:24
If you're getting that, it might mean you're getting your initial clip argument mixed up somehow while making changes. If you have no last, then sure, you can't use it without a video argument, but maybe in this case it'd be simpler to work with one and just pick it up at the end:

IntroVideo = ....
IntroAudio = BlankClip(Video, length=IntroClipFrames)
AudioDub(IntroVideo, IntroAudio)

Subtitle("Different Colored Title", x=-1, y=100, first_frame=0,
\last_frame=IntroVideo.framecount-1, font="Comic Sans MS", size=75, text_color=$33FF33, halo_color=$3333FF,
\align=5, spc=50, lsp=1)
Subtitle("\n(KST) ADonat\n(KST) Elite_Marines", x=-1, y=100, first_frame=0,
\last_frame=IntroVideo.framecount-1, font="Comic Sans MS", size=75, text_color=$FF3333, halo_color=$3333FF,
\align=5, spc=50, lsp=1)
FadeIO0(IntroFadeFrames)
last ++ Video

Don't go crazy restoring old drive images over a script error. o.O I took out "font_width=0, font_angle=0, interlaced=false" because I don't have 2.5.8, and it worked fine, so somewhere a video clip must have been doubled or left off something. (Passing a video as an argument while also passing one by dot will give it one too many, for instance.) If you post the last script you had, I could point it out.

Just for legibility, you might want to junk first_/last_frame, just because they're already the defaults.

IanB
10th October 2007, 08:28
Function Foo(clip xyzzy) {
xyzzy # Set initial "Last"
Subtitle("plugh")
return last
}

..Source(...)
Foo()

Aaron76
10th October 2007, 20:54
I have gotten it to work thanks to you guys. I am trying to clean up the code a little bit more and I have been implementing fuctions so I can use them in other scripts more easily.
I think my syntax was wrong because I can't reproduce what was happening before. As far as restoring my hard drive, I always back up things before I install a bunch of programs. :) Anyways... I was wondering if this is the proper functioning of Subtitle()

This works because it works on built in variable "last".

VideoClip = "D:\Videos\BF2 Videos\Battlefield.2.Clips.06..27.avi"
AviSource(VideoClip)

Subtitle("When I use the Subtitle funtion this way,",text_color=$FFFF00)
Subtitle("\nit applies both subtitles lines correctly to the built in variable last which is of type clip.", text_color=$FF3333, lsp=1)

This only displays the second subtitle. I assume since only the second subtitle function is assigned to "last".

VideoClip = "D:\Videos\BF2 Videos\Battlefield.2.Clips.06..27.avi"
Video = AviSource(VideoClip)

Subtitle(Video, "When I use the Subtitle funtion this way,",text_color=$FFFF00)
Subtitle(Video, "\nit only shows this line and ignores the first Subtitle function.",text_color=$FF3333,lsp=1)

foxyshadis
10th October 2007, 21:30
Sure, when you explicitly name clips, you have to assign them back to something (as in your first post) if you don't want them to be set to last and then lost. Clips are never modified by a function, only new ones returned, unlike C functions. That's why you have to be careful to keep track of what's going in and out when you work with a lot of named clips.

Aaron76
11th October 2007, 03:17
Clips are never modified by a function, only new ones returned, unlike C functions. That's why you have to be careful to keep track of what's going in and out when you work with a lot of named clips.

I think that is where I went wrong. I assumed the function acted on the clip instead of making a new one.:thanks: