View Full Version : Is it possible to create a bounding box with solid edges and transparent fill?
Qriist
7th August 2024, 05:29
Hey there, I'm asking for something that I'm not quiiite sure is possible: I would like to create a subtitle file that creates bounding boxes at specific points in the video.
The box should have solid edges and a transparent fill, like in this example:
https://i.imgur.com/R78yZ9L.png
There may be multiple boxes active at once, but it's okay for them to overlap.
Is it possible to do this with ASS (or whatever codec) subtitle rendering, or will I need to look at something like an avisynth script to reencode the video? Thanks in advance!
GeoffreyA
7th August 2024, 11:09
I think this is possible using Aegisub and ASS, but you'll have to experiment to get it working and the values right. Aegisub has a somewhat steep learning curve.
https://aegisub.org/docs/latest/ass_tags/
See "Drawing commands," where it talks about squares. AviSynth, VapourSynth, or FFmpeg might be simpler. In ffplay, which is FFmpeg's playing tool, here's a starting point with the first two boxes being displayed from seconds one to five. x and y denote where the rectangle starts. Each drawbox command is separated by commas.
ffplay -i INPUT.mp4 -vf "drawbox=x=32:y=32:width=400:height=64:color=red:enable='between(t,1,5)',drawbox=x=128:y=128:width=200:height=600:color=red:enable='between(t,1,5)'"
Qriist
9th August 2024, 07:36
I think this is possible using Aegisub and ASS, but you'll have to experiment to get it working and the values right. Aegisub has a somewhat steep learning curve.
https://aegisub.org/docs/latest/ass_tags/
See "Drawing commands," where it talks about squares. AviSynth, VapourSynth, or FFmpeg might be simpler. In ffplay, which is FFmpeg's playing tool, here's a starting point with the first two boxes being displayed from seconds one to five. x and y denote where the rectangle starts. Each drawbox command is separated by commas.
ffplay -i INPUT.mp4 -vf "drawbox=x=32:y=32:width=400:height=64:color=red:enable='between(t,1,5)',drawbox=x=128:y=128:width=200:height=600:color=red:enable='between(t,1,5)'"
Thanks for your quick reply! Someone in a typesetting Discord helped me come up with the following formula that does the trick:
DrawASSBB(bb,blw := 6){
;bb = bounding box
;blw = box line width
/* Formula for generating an ASS bounding box
With:
(x1,y1) = Top Left = bb[1]
(x2,y2) = Top Right = bb[2]
(x3,y3) = Bottom Right = bb[3]
(x4,y4) = Bottom Left = bb[4]
concatonate the following into a single line:
m x1 y1
l x2 y2
x3 y3
x4 y4
m (x1 + blw) (y1 + blw)
l (x4 + blw) (y4 − blw)
(x3 − blw) (y3 − blw)
(x2 − blw) (y2 + blw)
*/
ret := "m" a_space bb[1]["x"] a_space bb[1]["y"] a_space
. "l" a_space bb[2]["x"] a_space bb[2]["y"] a_space
. bb[3]["x"] a_space bb[3]["y"] a_space
. bb[4]["x"] a_space bb[4]["y"] a_space
. "m" A_Space (bb[1]["x"] + blw) a_space (bb[1]["y"] + blw) a_space
. "l" A_Space (bb[4]["x"] + blw) a_space (bb[4]["y"] - blw) a_space
. (bb[3]["x"] - blw) a_space (bb[3]["y"] - blw) a_space
. (bb[2]["x"] - blw) a_space (bb[2]["y"] + blw) a_space
return ret
}
Someone else later suggested using:
{\3c&HFF&\an7\pos(0,0)\bord4\1aFF\shad0\p1}m x_1 y_1 l x_2 y_2 x_3 y_3 x_4 y_4
but I haven't tried it since I already had the built funciton. Apparently this creates rounded corners but is otherwise identical.
GeoffreyA
9th August 2024, 09:43
Glad to hear that you got it working! Both pieces of code, in their own way, look excellent. The ingenuity of those in the typesetting community never fails to amaze me. Hats off to them.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.