
ASS subtitles can have a translucent background for text.
Using aegisub
The easiest way to do this is aegisub .

- Open the subtitle file with eegisub.
- Click
Subtitle → Styles manager . - In
Current Script select Default , then click the Edit button. - Experiment with
Outline and Shadow values. Check out the Opaque box . - Under
Colors click a color under Outline or Shadows . A window will appear. Adjust the value of the Alpha field to change the transparency. - Save the subtitles as an
.ass file.
Now you can use the AAS file to create hardsubs or softsubs with ffmpeg .
Without aegisub
If you want hardsubs, you can use the subtitle filter to add a transparent background with the force_style option.
ffmpeg -i input -filter_complex "subtitles=subs.ass:force_style='OutlineColour=&H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20'" output
This will work with any text subtitles supported by FFmpeg, because the filter will automatically convert them to ASS.
For formatting, see SubStation Alpha (ASS) style fields .
Multiple Line Problem
If your subtitles contain multiple lines, due to the automatic tying of long lines or an intentional line break, the backgrounds will overlap and potentially look ugly, as shown below:

You can avoid this:
- Resize
Outline and Shadow to 0 . - Alpha shadow settings will control the transparency of the background. Click on the shadow color to adjust the
Alpha shadow color to the desired level of transparency. Edit the ASS file in a text editor. In the Style line, change the value corresponding to BorderStyle to 4 . This will fill the frame background for each subtitle event. Style line example:
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H80000000,&H80000000,-1,0,0,0,100,100,0,0,4,0,0,2,10,10,10,1
Example:

Please note that BorderStyle=4 is a non-standard value, so it may not work properly for all players.
Thanks to sup and wm4 for the BorderStyle suggestion.
Using drawbox
The drawbox filter can be used to create the background. This can be useful if you want the field to span the width.

ffmpeg -i input -filter_complex "drawbox=w=iw:h=24:y=ih-28:t=max: color=black@0.4 ,subtitles=subs.ass" output
Downside is something that you have to consider line breaks or word wrap for long subtitles. Just making the height of the drawer to compensate will be enough, but it will look ugly, because the basic level of subtitles remains static: in single-line subtitles there will be more indents from above than below.
LordNeckbeard
source share