如何在ffmpeg视频过滤器的字幕中添加字体大小 [英] How to Add Font size in subtitles in ffmpeg video filter

查看:3443
本文介绍了如何在ffmpeg视频过滤器的字幕中添加字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此命令裁剪,缩放,然后添加字幕作为重叠

  ffmpeg -i input.avi -vf[in] crop = in_w:in_h-20:0:0 [crop]; [crop] scale = 320:240 [scale]; [scale] subtitles = srt.srt-apect 16:9 -vcodec libx264 -crf 23 oq.mp4 

我们如何设置字幕的字体大小/颜色?

解决方案

有两种使用字幕的方法:hardsubs和softsubs。



Hardsubs



字幕 视频过滤器可以用于hardsub或老化字幕。这需要重新编码,字幕成为视频本身的一部分。



force_style 选项



要自定义字幕,您可以在字幕过滤器中使用 force_style 选项。使用字幕文件 subs.srt 并使用红色字体颜色制作字体大小为24的示例。

 code> ffmpeg -i video.mp4 -vfsubtitles = subs.srt:force_style ='Fontsize = 24,PrimaryColour =& H0000ff&'-c:copy copy.mp4 




  • force_style 使用 SubStation Alpha(ASS)样式字段


  • PrimaryColour 以蓝绿色红色订单为十六进制。请注意,这是与HTML颜色代码相反的顺序。颜色代码必须始终以& H 开始,并以& 结尾。




Aegisub



或者,您可以使用 Aegisub 来创建和设计您的字幕。另存为 SubStation Alpha (ASS)格式,因为它可以支持字体大小,字体颜色,阴影,轮廓,缩放,角度等。






Softsubs



是文件中的附加流。播放器只是在播放时渲染它们。比hardbubbing更灵活,因为:




  • 您不需要重新编码视频。

  • 您可以使用多种字幕(各种语言)并在它们之间切换。

  • 您可以在播放过程中打开/关闭它们。

  • 可以调整大小任何值得使用的玩家。



当然,如果设备或播放器无法使用softsubs,有时需要hardsubs。

使用流拷贝复制到视频文件中的多媒体字幕a>模式:

  ffmpeg -i input.mkv -i subtitles.ass -codec copy -map 0 -map 1输出。 mkv 

没有任何重新编码,所以整个过程将很快,质量和格式将会保存。



使用SubStation Alpha(ASS)字幕将允许您格式化字幕,但您喜欢。这些可以用Aegisub创建/转换。






另请参阅




I'm using this command to crop,scale, and then add subtitles as overlay

ffmpeg -i input.avi  -vf "[in]crop=in_w:in_h-20:0:0 [crop]; [crop]scale=320:240 [scale];[scale]subtitles=srt.srt" -aspect 16:9 -vcodec libx264  -crf 23 oq.mp4

how can we set font size/color of subtitle ?

解决方案

There are two methods to use subtitles: hardsubs and softsubs.

Hardsubs

The subtitles video filter can be used to hardsub, or burn-in, the subtitles. This requires re-encoding and the subtitles become part of the video itself.

force_style option

To customize the subtitles you can use the force_style option in the subtitles filter. Example using subtitles file subs.srt and making font size of 24 with red font color.

ffmpeg -i video.mp4 -vf "subtitles=subs.srt:force_style='Fontsize=24,PrimaryColour=&H0000ff&'" -c:a copy output.mp4

  • force_style uses the SubStation Alpha (ASS) style fields.

  • PrimaryColour is in hexadecimal in Blue Green Red order. Note that this is the opposite order of HTML color codes. Color codes must always start with &H and end with &.

Aegisub

Alternatively, you can use Aegisub to create and stylize your subtitles. Save as SubStation Alpha (ASS) format as it can support font size, font color, shadows, outlines, scaling, angle, etc.


Softsubs

These are additional streams within the file. The player simply renders them upon playback. More flexible than hardsubbing because:

  • You do not need to re-encode the video.
  • You can have multiple subtitles (various languages) and switch between them.
  • You can toggle them on/off during playback.
  • They can be resized with any player worth using.

Of course sometimes hardsubs are needed if the device or player is unable to utilize softsubs.

To mux subtitles into a video file using stream copy mode:

ffmpeg -i input.mkv -i subtitles.ass -codec copy -map 0 -map 1 output.mkv

Nothing is re-encoded, so the whole process will be quick and the quality and formats will be preserved.

Using SubStation Alpha (ASS) subtitles will allow you to format the subtitles however you like. These can be created/converted with Aegisub.


Also see

这篇关于如何在ffmpeg视频过滤器的字幕中添加字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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