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

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

问题描述

我使用这个命令来裁剪、缩放,然后添加字幕作为叠加

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 ?

推荐答案

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

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

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

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.

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

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 使用 SubStation Alpha (ASS)样式字段.

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

    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 来创建和风格化您的字幕.另存为 SubStation Alpha (ASS) 格式,因为它可以支持字体大小、字体颜色、阴影、轮廓、缩放、角度等

    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.

    这些是文件中的附加流.播放器只是在播放时渲染它们.比硬字幕更灵活,因为:

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

    • 您无需重新编码视频.
    • 您可以拥有多个字幕(各种语言)并在它们之间切换.
    • 您可以在播放过程中打开/关闭它们.
    • 任何值得使用的播放器都可以调整它们的大小.

    当然,如果设备或播放器无法使用软字幕,有时需要硬字幕.

    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.

    使用 SubStation Alpha (ASS) 字幕可让您随意设置字幕格式.这些可以使用 Aegisub 创建/转换.

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

    • subtitles video filter documentation
    • How to burn subtitles into the video
    • How to convert subtitle from SRT to ASS format

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

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