FFmpeg添加字幕
首先需要科普下。vob,mkv等格式文件以流的形式存储字幕,而mp4不支持这种方式。如果希望生成带字幕的mp4文件,只能将字幕“烧录”到视频中。 也就是说我们需要将字幕流与视频流进行合成。最终只留下视频流。这样肯定会对原始的视频的画质造成一定影响。
直接将mkv及里面得转换成mp4
ffmpeg -i input.mkv -filter_complex [0:v][0:s]overlay[v] -map [v] -map 0:a -acodec libvo_aacenc -ac 2 -ar 48000 -ab 320k output.mp4
官网有一篇已经写的很详尽的文章 HowToBurnSubtitlesIntoVideo可以作为参考资料。
利用ffplay播放字幕和视频
ffplay -vf subtitles=subtitle.ass input.mp4
非常简单,其实就是指定使用字幕的avfilter除了ass也可以使用srt。
SRT格式
最简单的就是.srt格式的字幕了,如图所示,按照一定的格式规则编辑好字幕内容到记事本中,另存为.srt文件,文件名必须与影片名一致,用KMP或暴风影音播放影片,字幕会自动加载,相同的,把.srt字幕文件拖动到记事本中,就可以对字幕的内容,字幕出现的时间进行随意编辑;