如何在ffmpeg中为字幕设置背景? [英] How to set background to subtitle in ffmpeg?
问题描述
.
- 使用 aegisub 打开您的字幕文件.
- 点击
Subtitle
→样式管理器
. - 在
Current Script
下选择Default
,然后按下Edit
按钮. - 使用
Outline
和Shadow
值进行实验.选中不透明框
. - 在
Colors
下,点击Outline
或Shadows
下的颜色.将出现一个窗口.调整Alpha
框的值以更改透明度. - 将字幕另存为
.ass
文件.
现在您可以使用 AAS 文件通过 ffmpeg
制作
您可以通过以下方式避免这种情况:
- 将
Outline
和Shadow
大小更改为0
. - 阴影的 alpha 设置将控制背景框的透明度.单击阴影颜色以将阴影颜色的
Alpha
调整为所需的透明度级别. 在文本编辑器中编辑 ASS 文件.在
Style
行中,将BorderStyle
对应的值更改为4
.这将填充每个字幕事件的边界框背景.示例Style
行:Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H80000000,&H80000000,-1,0,0,0,100,100,0,0,4,0,0,2,10,10,10,1
示例:
请注意,BorderStyle=4
是一个非标准值,因此它可能无法在所有播放器中正常工作.
感谢
ffmpeg -i input -filter_complex "drawbox=w=iw:h=24:y=ih-28:t=max:color=black@0.4,subtitles=subs.ass" 输出
缺点是你必须考虑到长字幕的换行或换行.简单地使框更高以进行补偿就足够了,但会看起来很难看,因为字幕基线保持静态:单行字幕的顶部填充比底部多.
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?
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.
这篇关于如何在ffmpeg中为字幕设置背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!