View Full Version : Using SubtitleEx on non-square pixel video
chaynik
1st October 2009, 12:53
Does anyone know if this is possible? I need to generate text on non-square pixel video (for example, 704x480 with 10:11 and 40:33 PARs).
I've thought about making modified copies of the fonts I use to reflect the different pixel ratios, but I do not know of any tools to do so in a correct manner...
Thanks in advance!
MatLz
1st October 2009, 13:43
Hi chaynik, with subtitlecreator you can stretch subs horizontaly and verticaly.
Hope that helps you.
Comatose
1st October 2009, 14:37
You can do that with Aegisub too. In Avisynth, you can simply resize the video to a square pixel resolution, add the sub, then resize it back to the previous resolution.
Alternatively, you can add the sub on a Blackness clip which has the resolution the other clip would have if it was square pixel, resize it to the same size as the other clip, and then create a mask clip of the background (with Levels() or something), and Overlay() it onto the other clip, using the mask clip.
g-force
1st October 2009, 15:32
"Subtitle" in most recent versions of Avisynth has a font_width parameter that should do the trick for you.
thewebchat
1st October 2009, 15:56
@Comatose: Or you could just use the MaskSub() function.
chaynik
2nd October 2009, 02:03
Thanks for all the replies, guys. I would like to stay away from resizing to a square res and then back as that is 2 lossy pixel resampling steps.
I am familiar with the font_width parameter in Subtitle, however I like using SubtitleEx due to its fadein/fadeout and shadow options. Would it be possible to emulate those in Subtitle()?
As far as using Overlay(), I tried to stay away from it due to everything being converted to a non-subsampled YUV format for processing (so my 4:2:2 and 4:2:0 would be upsampled to 4:4:4 and then subsampled back to 4:2:2 or 4:2:0, which I believe can be quite lossy)
Any other ideas? Thanks again.
thewebchat
2nd October 2009, 02:36
You could try using mt_merge instead of Overlay to address this issue (?). I would just write the subtitles in SSA format and let VSFilter deal with it though. It supports all of your favourite subtitle effects, is fairly readable, and you can even make your own effects.
Gavino
2nd October 2009, 09:31
I am familiar with the font_width parameter in Subtitle, however I like using SubtitleEx due to its fadein/fadeout and shadow options. Would it be possible to emulate those in Subtitle()?
For fades, Dissolve between the relevant parts of c and c.Subtitle().
chaynik
3rd October 2009, 13:03
I would just write the subtitles in SSA format and let VSFilter deal with it though. It supports all of your favourite subtitle effects, is fairly readable, and you can even make your own effects.
Well, they're not really subtitles per se in my case, but rather lower thirds that occur only once in the entire video. I need to fadein some text, display about 10 seconds of the same text, and then fade it out. All this happens in a 5 minute clip and that's it. I looked into the SSA format but don't see an option anywhere for pixel ratio... Even if there were, I'd prefer not to have to generate an external file and keep everything inside the AviSynth script, as it's literally only 5 lines of text.
For fades, Dissolve between the relevant parts of c and c.Subtitle().
I'm afraid I don't follow. Could you please elaborate?
Gavino
3rd October 2009, 14:19
I'm afraid I don't follow. Could you please elaborate?
What I mean is do a dissolve between the original clip and the clip with the subtitle added.
Say you want a subtitle on frames 100-150.
Then instead of Subtitle(..., 100, 150, ...), you could use
subs = Subtitle(..., 100, 150, ...)
Dissolve(Trim(0, 99), subs.Trim(100, 150), Trim(151, 0), 5)
which would give you a fade in and out of 5 frames.
For repeated use, it would be fairly easy to write a wrapper function to do this as a replacement for Subtitle.
thewebchat
3rd October 2009, 16:07
@chaynik: You can specify the pixel ratio using ScaleX/Y in SSA.
chaynik
3rd October 2009, 23:36
For repeated use, it would be fairly easy to write a wrapper function to do this as a replacement for Subtitle.
Then I could save it as an AVSI and have it auto loaded in each AVS script subsequently, right?
Could you help me out with writing this function? I'm also looking to add shadows to the text and when using Subtitle I imagine just stacking two instances of it on top of each other, with the bottom one being black in color, a bit offset in x,y and with some sort of blur filter applied. I use a similar approach with SubtitleEx, but the downside is that when fading out, each "layer" (that is the text itself and the "shadow" text below it) dissolve independently, so the effect is a bit strange looking, being able to see the shadow through the actual text, if that makes any sense.
Thank you.
Gavino
4th October 2009, 00:39
Then I could save it as an AVSI and have it auto loaded in each AVS script subsequently, right?
Yes, that's right.
Here's a start:
# Add fade in/out to Subtitle
function SubtitleF(clip c, string text, int "x", int "y", int "first_frame", int "last_frame",
\ int "fade") {
first_frame = Default(first_frame, 0)
last_frame = Default(last_frame, c.Framecount-1)
fade = Default(fade, 10)
Assert(fade >= 0, "fade must not be negative")
Assert(2*fade <= last_frame-first_frame, "fade too large")
sub = Subtitle(c, text, x, y, first_frame, last_frame)
before = c.Trim(0, -(first_frame+fade))
mid = sub.Trim(first_frame, last_frame)
after = c.Trim(last_frame+1-fade, 0)
(fade == 0) ? sub : Dissolve(before, mid, after, fade)
}
You can change the default fade length to suit your own preference.
For clarity (or through laziness :)), I have not put in all the different arguments to Subtitle - you can easily add the ones you plan to use. Ask again if you still need help with this.
It should also be possible to extend it to add shadows using your idea, so have a go at that.
BTW in doing this, I realised I forgot to allow for the overlap in the earlier example, which should be
Dissolve(Trim(0, 104), subs.Trim(100, 150), Trim(146, 0), 5)
chaynik
31st October 2009, 12:22
Gavino, thank you very much for your help. Your function works flawlessly! I have added a few lines to do the discussed shadow effect as well as the arguments for font, size, etc:
# Add fade in/out to Subtitle
function SubtitleF(clip c, string text, int "first_frame", int "last_frame", int "fade")
{
first_frame = Default(first_frame, 0)
last_frame = Default(last_frame, c.Framecount-1)
fade = Default(fade, 10)
Assert(fade >= 0, "fade must not be negative")
Assert(2*fade <= last_frame-first_frame, "fade too large")
shadow = Subtitle(c, text, 38, 383, first_frame, last_frame,size=22,font="LL Cooper",text_color=$00000000,halo_color=$000000,lsp=-40)
shadow_blur = Blur(shadow,1.58)
sub = Subtitle(shadow_blur, text, 36, 381, first_frame, last_frame,size=22,font="LL Cooper",text_color=$00FFFFFF,halo_color=$000000,lsp=-40)
before = c.Trim(0, -(first_frame+fade))
mid = sub.Trim(first_frame, last_frame)
after = c.Trim(last_frame+1-fade, 0)
(fade == 0) ? sub : Dissolve(before, mid, after, fade)
}
Unfortunately, the Blur() filter does not only affect the shadow layer but the entire video below it. Can you think of any workaround for this?
Gavino
31st October 2009, 13:15
I think you would have to apply the shadow as an overlay using a mask formed by the Subtitle. Alternatively, it might be good enough for your purposes just to make the shadow slightly transparent instead of blurring it. See the Subtitle docs for how to do this using the color parameters.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.