使用简单滤镜里的 subtitles挂上字幕
一般常用字幕格式为 srt和 ass, ass 的格式自带修饰描述,比如颜色字体,位置等
ffmpeg就要求有filer: subtitles, drawtext,这样才能合成字幕 ,如果自行编译就要注意这点,一般下载的二进制执行文件应该都包括了。
参数 -vf 就是简单video filter的意思,用于一个视频与一个字幕合成。后面的subtitles="input.ass" 就是使用subtitles滤镜,
参数 -c:v 是指输出什么格式的视频,音频部分则没动
./ffmpeg -i "input.mp4" -vf subtitles="input.ass" -c:v libx264 -y "target/test.mp4"
字幕格式一般是两种:srt和 ass。
srt 格式很简单,基本上就是时间和文字,也可能扩展html,这个并不是必须的。
1
00:02:16,612 --> 00:02:19,376
Senator, we're making
our final approach into Coruscant.
2
00:02:19,482 --> 00:02:21,609
Very good, Lieutenant.
3
00:03:13,336 --> 00:03:15,167
We made it.
ass 格式就非常复杂,基本上不建议手写。
[Script Info]
; Script generated by Aegisub
; http://www.aegisub.org
Title: Neon Genesis Evangelion - Episode 26 (neutral Spanish)
Original Script: RoRo
Script Updated By: version 2.8.01
ScriptType: v4.00+
Collisions: Normal
PlayResY: 600
PlayDepth: 0
Timer: 100,0000
Video Aspect Ratio: 0
Video Zoom: 6
Video Position: 0
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: DefaultVCD, Arial,28,&H00B4FCFC,&H00B4FCFC,&H00000008,&H80000008,-1,0,0,0,100,100,0.00,0.00,1,1.00,2.00,2,30,30,30,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:01.18,0:00:06.85,DefaultVCD, NTP,0000,0000,0000,,{\pos(400,570)}Like an Angel with pity on nobody\NThe second line in subtitle
https://en.wikipedia.org/wiki/SubStation_Alpha
ASS字幕格式规范 - 简书
https://en.wikipedia.org/wiki/SubRip
FFmpeg Filters Documentation
FFmpeg Filters Documentation