It is described here how ot burn a srt file into a video. However, I want to put a semi-transparent background to the subtitles so that the texts can be read more easily. How can I do that?
5 Answers
ASS subtitles can have a semi-transparent background for the text.
With aegisub
The easiest way to do this is with aegisub.
- Open your subtitles file with aegisub.
- Click
Subtitle
→Styles manager
. - Under
Current Script
chooseDefault
, then press theEdit
button. - Experiment with the
Outline
andShadow
values. CheckOpaque box
. - Under
Colors
click the color underOutline
orShadows
. A window will appear. Adjust the value of theAlpha
box to change transparency. - Save the subtitles as an
.ass
file.
Now you can use the AAS file to make hardsubs or softsubs with ffmpeg
.
Without aegisub
If you want hardsubs you can use the subtitles filter to add the 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 based subtitles supported by FFmpeg because the filter will automatically convert them to ASS.
See SubStation Alpha (ASS) style fields for formatting options.
Issue with multiple lines
If your subtitles contains multiple lines, due to auto-wrapping of long lines or an intentional line break, the backgrounds will overlap and potentially look ugly as shown below:
You can avoid this by:
- Changing the
Outline
andShadow
sizes to0
. - The alpha settings of the shadow will control the transparency of the background box. Click on the shadow color to adjust the
Alpha
of the shadow color to your desired transparency level. Edit the ASS file in a text editor. In the
Style
line change the value corresponding withBorderStyle
to4
. This will fill the bounding box background of each subtitle event. ExampleStyle
line: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:
Note that BorderStyle=4
is a non-standard value, so it may not work properly in all players.
Thanks to sup and wm4 for the BorderStyle
suggestion.
Using drawbox
The drawbox filter can be used to create a background box. This may be useful if you want the box 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 that you have to account for line breaks or word wrapping for long subtitles. Simply making the box taller to compensate will suffice, but will look ugly because the subtitles baseline remains static: the single line subtitles will have more padding on the top than the bottom.
-
2This leaves a nasty line in there in case of two-line subtitles. Is there a way to ged rid if it? – sup Jun 26 '16 at 13:50
-
1@sup Not that I know of. An alternative method would be to make a static, transparent box using the [drawbox filter](http://ffmpeg.org/ffmpeg-filters.html#drawbox), but that is not idea either. – llogan Jun 27 '16 at 21:26
-
@LordNeckbeard man you saved my life! That's perfect! Works like a charm!! No need of adobe encore, adobe premiere and all that stuff paid that's unable to do such a simple stuff like this! – imbr Nov 15 '16 at 01:30
-
2@eusoubrasileiro Good to hear. Just be aware of the "multiple lines may overlap and look ugly" issue. IIRC, it's a problem with libass. There's a bug report about it somewhere. – llogan Nov 15 '16 at 01:47
-
@LordNeckbeard the issue could be resolved if the leading of the lines was adjustable in Aegisub. But I couldn't find a way to do this. – Rajib Jan 02 '17 at 16:56
-
@LordNeckbeard This was super helpful! Thank you! (Now only if Aegisub would fix the ugly translucent overlap problem...) – Ryan Jan 08 '17 at 21:54
-
@LordNeckbeard Any idea where that bug report might be? – sup Feb 15 '17 at 11:28
-
1@sup If I recall correctly it was on the [Aegisub Bug Tracker](http://devel.aegisub.org/), but it's currently down. – llogan Feb 15 '17 at 19:42
-
@LordNeckbeard I asked at the forums: http://forum.aegisub.org/viewtopic.php?t=85495 and they sent me to libass developemnt, so I filed a new bug: https://github.com/libass/libass/issues/268 – sup Feb 19 '17 at 14:00
-
1@LordNeckbeard Actually, setting BorderStyle=4 fixes the issue (see the Github issue I opened), would you please update your answer? It only works with libass though. – sup Feb 19 '17 at 14:19
-
1@sup Updated. Thanks for the hint. – llogan Feb 19 '17 at 20:59
-
@lordNeckbeard The solution with borderstyle=4 has a problem that one cannot set margins to the box. I found a hack how to do that in and posted it on the upstream tracker: https://github.com/libass/libass/issues/268 - though I have not scripted it yet. But that way, letters like "y" do not get displayed outside of the semi-transparent box. – sup Mar 17 '18 at 12:15
-
Hm, so with libass https://github.com/libass/libass/releases/tag/0.13.7 and later, one can indeed just adjust border size and margins are respected, sweet! I was on too old software. – sup Mar 17 '18 at 16:55
-
@LordNeckbeard That would have been impractical, T at the beginning of aline also had this problem. But as I said, with version 0.13.7 of libass, one can set the margin. – sup Mar 17 '18 at 20:23
-
here after adjusting, using: `Style: Transparent,PingFang SC,20,&H00FFFFFF,&H000000FF,&HBC5E5E5E,&H8B000000,0,0,0,0,100,100,0,0,3,0,1,2,10,10,10,134` to implement the half transparent background subtitle. Thanks. – crifan Oct 16 '18 at 14:06
-
@llogan Your `ffmpeg` command has `BorderStyle=3` among the filtering options. What do you think about just replacing it with `BorderStyle=4` in those filtering options, instead of having to edit the `.ass` file and putting that option inside that file? Would this solve the multiple line subtitles issue according to you? – Kubuntuer82 Feb 06 '22 at 13:04
Create a png with a transparent box and a alpha channel in your favoured size. You can use e.g. gimp or photoshop.
Then use this command:
ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=10:10" \
-codec:a copy out.mp4
where 10:10 is the distance from the upper left corner.
After that you can insert your subtitles.

- 2,220
- 1
- 12
- 11
-
If you want to do this "make a separate background box" method it would be easier and more efficient to just use the [drawbox](https://ffmpeg.org/ffmpeg-filters.html#drawbox) filter. Also, using filters, such as overlay or drawbox, will require re-encoding of the video, but using ASS subtitles for softsubs as shown in my answer will not modify the video. – llogan Feb 19 '17 at 21:07
ffmpeg -i input.mp4 -filter_complex "subtitles=input.srt:force_style='BackColour=&H80000000,BorderStyle=4,Fontsize=11'" output.mp4
BackColour=&H80000000
means having a %50 opaque black background.
Its a hex representation of color, AABBGGRR.

- 31
- 1
-
1Where do I get color numbers like 'H80000000'. Can't I say "red, green, black,... and so on"? – cis Mar 31 '22 at 15:00
With the current version of libass (0.15) and the current version of ffmpeg (N-100402-g0320dab265, compiled from source, probably the same as version 4.2), you can use this bash script
INFILE="movie.mp4"
SUBS="subtitles.srt"
OUTFILE="result.mp4"
ffmpeg -i "${INFILE}" -vf subtitles=${SUBS}:force_style='Borderstyle=4,Fontsize=16,BackColour=&H80000000'" "${OUTFILE}"
to burn subtitles.srt into movie.mp4 and save it as result.mp4.
The subtitles will appear correctly boxed in a 50% transparent rectangle, even when there are 2 lines in a subtitle.

- 280
- 1
- 8
You can use this Aegisub script. This script automatically generate transparent background for every line of subtitle.

- 849
- 2
- 8
- 28