When I tried to follow you exactly typing the expression by hand it didn't work, so I checked the description and copied the one you provided. It worked! Not sure what I was missing in mine!
Okay I just tried again. I started with a brand new rectangle, and when it came to the expression I had better luck when I used the autofill suggestions when possible. It seemed to link things together properly. This is my first time doing an expression so I have NO idea what the proper way is. XD
If this isn't working for you, here's something that helped me: Go to your background subtitle box layer, and make sure that every Scale or Size is set to 1920x1080, or 100%
Very helpful expression! The problem I'm currently facing is that when you move the text and box in the timeline, the timing of the box gets completely messed up for me and the box moves inbetween the text hold keyframes for some reason. I tried precomposing text and the box to move it but that doesnt fix the problem. I don't really know much about expressions but maybe it has to do with the .sourceRectAtTime command? Edit: I just found a workaround to not move the layers themselves, but dragging out the back and pulling in the front and then moving the keyframes to the correct timing. That kinda fixes it.
Great tutorial! So far, the only "problem" I'm facing is that the subtitles-box even shows a little square when the text is empty (includes no letters).. So when you want to have a "break" for a moment with the subtitles you would have to work around it.. (I know it's because of the additional space which is added to the size of the letters/text). I'm sure there is a way through expressions to tell it not to show a box whenever the text remains empty... unfortunately I'm not familiar enough with expressions.
I was having the same trouble and i didn't know how to solve it, so i asked it to ChatGPT and i can belive it but it solved that issue, change the code with this: Subtext = thisComp.layer("Subtitles"); textContent = Subtext.text.sourceText; if (textContent == " ") { [0,0] } else { TextWidth = Subtext.sourceRectAtTime(time).width+80; TextHeight = Subtext.sourceRectAtTime(time).height+30; [TextWidth, TextHeight] } Have the consideration that ( " " ) represent a space and not empty, because when i didn't have text what i did was create a space to create a keyframe. I hope it solve your problem too!
Lol no way GPTChat gave you that answer :)) You can make it even a little simpler. Add these 3 lines to your "Subtitles Box" layer opacity property: subs = thisComp.layer("Subtitles").text.sourceText; if (subs == "") 0 else 70 it checks the text value on your Subtitles layer and if its empty, sets box opacity to 0.
Hey, thanks a lot, nice and easy tutorial, tho I'm using it for an animated interface. I have animated text inside a button, which needs a minimum rectangle size. Could you think of a solution?
thx fot the tut mate, is there an expression that makes the rectangle follows the text word by word I asked chat gpt for this but I keep getting errors please let me know if that's possible thanks again
I can't get it to work. The first line returns "object of type layer found where a property is needed" - don't really see, why a layer can't be assignable to a variable...
Thank you, so well done. Subbed) How do I account for the parts of text that are below the centre like in "g" etc? They seem to make it not quite centred if you see what I mean.
Thanks Alex. Yeah that's a little annoying and I only noticed it myself after recording the tutorial. There's a couple of ways to fix it: 1. Use capitalized text. It will make all of your letters the same size. 2. You could turn off that Anchor Point expression and simply adjust your subtitles text position by hand. You'd also have to set a fixed height for Subtitles BG box expression "textHeight = 100;". This approach doesn't work with 2 lines of text. I'm sure there's a way to write an expression that looks at whether the line has any "g" or "l" type of characters that stick out either at the top or bottom, but that's a little too complex for the tutorial I wanted to share. Hope this helps.
Late to the Party - but: Just ad keyframes with no text or a blank space in the textelement. You will have a small backround-box with the dimensions of your padding in the pauses. to get rid of them automatically i just use an expression to set opacity of the box-Layer to the Width of the text. It's not sophisticated but worked for me (subText = thisComp.layer("Subtitles"); transform.opacity = subText.sourceRectAtTime(time).width; )
@SOUTH11_YT Hey, thanks for your tutorial! Do you know of any additonal code if I want the box to look more accurate for 2 lines with different width? E.g. Top line is shorter than the bottom line, ideally would want the box above to be shorter than the one at the bottom (rather than just a rectangular box)? I am ok if there is no additional leading from line 1 to line 2 excluding the box! lmao not sure if you know what I'm talking about.
Hi Eindrew9 its strange you say it doesn't work when you copy it to a new comp. I've tested it a couple of ways here and I can't see to find a way to break it. Could you send me your file to support@southeleven.com so I can take a look? When duplicating the two layers you have to update the first expression line on "Background Box 2" layer's "size" parameter. Change it from "subText = thisComp.layer("Subtitles Text");" to "subText = thisComp.layer("Subtitles Text 2");".
Hmm weird - I can't seem to be able to reproduce this. But one thing that comes to mind is that your video comp might have a different framerate to the comp where you created your subtitles. If you paste the two layers into your video comp, text layer will have the keyframes set in between the frames and no exactly on them. You could try to shift them to exact frames manually and see if that fixes is?
subText = thisComp.layer("Subtitles"); textWidth = subText.sourceRectAtTime(time),width + 100; textHeight = subText.sourceRecAtTime(time),height + 40; [textWidth, textHeight] I'm getting an error with this, can anyone see what the issue is? Thanks
What’s the error saying? Is your subtitles text layer called “Subtitles”? Does the expression work if you just copy and paste it exactly as in description?
@@connorwarden1557 Glad to hear that. What was the problem? Could it be that you added a text box (you add it by clicking and dragging out a box using a text tool) instead of typing your text? There's no expressions on your text layer to affect how the text is displayed so I'm not sure why it would do that.
Great tutorial, I have a question I have this code for a subtitle text box : text=thisComp.layer(""); width=tex.sourceRectAtTime(time-tex.inPoint,true).width+45; myFade = 12; if ( marker.numKeys > 0){ m = marker.nearestKey(time); t = m.time; d=linear(width,0,1400,45,1400); if (t
I'd probably approach it using an array and do it something like this: // Vars subs = thisComp.layer("Subtitles").text.sourceText; subsText = thisComp.layer("Subtitles"); keyArray = []; //Create an array with all keyframe times for (i = 1; i < subs.numKeys+1; i++) { keyArray.push(subs.key(i).time); } //Transition for (i = 0; i < subs.numKeys-1; i++) { if (time>keyArray[i]) { transitionTime = keyArray[i+1] keyCur = keyArray[i] keyNext = keyArray[i+1]; } } //Set box width textWidthCur = subsText.sourceRectAtTime(keyCur).width + 100; textWidthNext = subsText.sourceRectAtTime(keyNext).width + 100; //Output textWidth = ease(time, transitionTime-0.2, transitionTime, textWidthCur, textWidthNext); textHeight = subsText.sourceRectAtTime(time).height + 40; [textWidth, textHeight] --------------------------------------------------------------------------------- You'd have to clean it up a little bit but if you paste it into your "Subtitles Box" layer, it will work. Not sure how you'd approach the text to create a smooth transition but please do share the finished project as I'd like to see how it turns out. All the best,