rainerkeller.de

Add Subtitles to Videos

2017-12-30

Subtitles can be added to videos without modifying the video data itself. This allows to enable the subtitles in the video player on demand.

Create a subtitle file in srt or ass format

This example shows a srt file

1
00:00:02,440 --> 00:00:05,375
line A1
line B1

2
00:00:05,476 --> 00:00:08,501
next line

Embed Subtitles in Video

In order too keep the video as is the streams are copied to the output file. For the subtitles a separate data stream is added which contains the subtitle information. Adding subtitles to MPEG4 video from a srt file

ffmpeg -i <videoInputFile.mp4> -f srt -i <subtitles.srt> -map 0:v -map 0:a -c copy -map 1 -c:s mov_text <videoOutputFile.mp4>
Adding subtitles to MKV video from a srt file
ffmpeg -i <videoInputFile.mkv> -f srt -i <subtitles.srt> -map 0:v -map 0:a -c copy -map 1 -c:s srt <videoOutputFile.mkv>
For specific cases ffmpeg supports a lot more subtitle options. When using vlc for playing MKV videos make sure it contains libmatroska support, otherwise the subtitles will not be shown.


Anbieterkennzeichnung
Datenschutzhinweis

This work is licensed under a
Creative Commons Attribution-ShareAlike 4.0 International License.