如何在ffmpeg中设置字幕背景? [英] How to set background to subtitle in ffmpeg?

查看:4635
本文介绍了如何在ffmpeg中设置字幕背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  1. 用aegisub打开字幕文件。

  2. 点击小标题
  3. 当前脚本选择默认,然后按编辑按钮。

  4. 试用 Outline 阴影值。检查不透明框

  5. 颜色下单击大纲阴影。将出现一个窗口。调整 Alpha 框的值以更改透明度。

  6. 将副标题保存为 .ass file。

现在,您可以使用AAS文件使



你可以通过以下方式避免这种情况:


  1. 更改 Outline 阴影尺寸为 0

  2. 阴影的Alpha设置将控制背景框的透明度。点击阴影颜色将阴影颜色的 Alpha 调整到所需的透明度级别。

  3. 编辑ASS文件在文本编辑器中。在 Style 行中,将与 BorderStyle 对应的值更改为 4 。这将填补每个字幕事件的边界框背景。示例样式行:

     样式:默认,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_complexdrawbox = w = iw:h = 24:y = ih-28:t = max:color = 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.

  1. Open your subtitles file with aegisub.
  2. Click SubtitleStyles manager.
  3. Under Current Script choose Default, then press the Edit button.
  4. Experiment with the Outline and Shadow values. Check Opaque box.
  5. Under Colors click the color under Outline or Shadows. A window will appear. Adjust the value of the Alpha box to change transparency.
  6. 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:

  1. Changing the Outline and Shadow sizes to 0.
  2. 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.
  3. Edit the ASS file in a text editor. In the Style line change the value corresponding with BorderStyle to 4. This will fill the bounding box background of each subtitle event. Example Style 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆