Embedding, editing and extracting subtitles

Subtitles! When dubs aren't avaliable (or ideal), that's our fallback. But are they made? Or how can they be fixed if they're broken? Let's take a look.

Subtitle formats

There are a couple prevailing formats we can choose from, depending on our goal.

SRT

This format supports basic text formatting, including italic, bold and underlined text, setting position and font. SRT saves subtitles in a very basic way. On the first line we have the ID (sequential number) of the subtitle, on the next – the timestamp, and lastly – the subtitles themselves. That's how they look like:

1
00:00:27,533 --> 00:00:28,766
First subtitles

2
00:00:29,233 --> 00:00:29,966
Second subtitles that
are on two lines

3
00:00:30,933 --> 00:00:31,266
<i>Italic subtitles</i>

4
00:00:32,533 --> 00:00:34,433
<b>Bold subtitles</b>

ASS

The ASS format supports more advanced formatting: subtitles can be animated, colored, cut by a mask (that can also be animated), different styles can be defined, and more. To take advantage of all that, you'll have to do more than just write text. Some subtitle authors even track the motion of the subtitles to the motion of objects in a shot to create the illusion that they are a part of the video.

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:14.44,0:00:18.18,Default,,0,0,0,,{\K34}След {\K34}300 {\K23}ме{\K21}тра
Dialogue: 0,0:00:18.18,0:00:21.86,Default,,0,0,0,,{\K16}За{\K23}вий{\K16}те {\K13}на{\K16}ля{\K16}во
Dialogue: 0,0:00:21.86,0:00:25.59,Default,,0,0,0,,{\kf28}Пос{\kf24}ле
Dialogue: 0,0:00:25.59,0:00:29.90,Default,,0,0,0,,{\K18}Ще {\K66}пристигнете {\K15}на {\K92}местоназначението {\K16}си

Writing subtitles

There are different programs for writing subtitles. We'll use Aegisub, a free, open source program. There are three main parts of the UI: The video preview, the audio view, and underneath – the subtitles. You can change the size of the video preview. You'll have to apply any changes or they'll be undone. On the left there are transformation tools (moving, rotating, skewing and masking) for the subtitles. You can switch between frames with the left and right arrow keys. With Ctrl+3 and Ctrl+4 you can set the beginning and ending time of the subtitles to the current frame. When you are in the audio panel, left-clicking sets the beginning time, right-clicking – the ending time, and middle-clicking (mouse wheel) skips to the corresponding time. When we're ready, we can export the subtitles as SRT, ASS, SUB and other formats.

Editing subtitles in Aegisub

It's not necessary to use a program specialized for subtitling. Video editing software like Kdenlive also has this functionality, albeit more limited. But if we just want to translate speech, that's more than enough. Also, recently Kdenlive started supporting multiple subtitle tracks. To add subtitles, go to View > Subtitles. That will open the subtitle panel, if it's not open already. From there we can add subtitles with the "+" button. To export the subtitles, go to Project > Subtitles > Export Subtitle File… With Kdenlive we can export only in SRT, but in most cases that's all we need.

Editing subtitles in Kdenlive

Embedding subtitles

Our subtitles are ready, but if we want to see them, we have to manually add them each time. It would be much easier if we had the subtitles in the video itself. A video container holds different data: video tracks, audio tracks, subtitle tracks. If we add a subtitle track in the container, we won't need to manually open them when we play the video.

To achieve that we can use programs like HandBrake, or even command-line tools like FFmpeg. In HandBrake we can just click "Open source" and then go to Subtitles > Tracks > Add New Track. From there we choose a language, character code and a file, from which the subtitles should be loaded.

Embedding subtitles with HandBrake

With FFmpeg we can use the following command:

ffmpeg -i my_video.mp4 -i subtitles.srt -c copy -c:s mov_text my_video_with_subtitles.mp4

We can specify language information like so:

ffmpeg -i my_video.mp4 -i subtitles.srt -c:a copy -c:v copy -c:s mov_text -metadata:s:s:0 language=bul my_video_with_subtitles.mp4

There's another way of inserting subtitles where they are rasterized and become an inseparable part of the video – then they can't be turned off. We can do that only if we don't plan on translating into more languages. To do this in Kdenlive, we just have to leave the subtitle track visible when exporting. Then it will remain visible in the final render. With HandBrake we only need to check "Burn into video" when adding a track. And with FFmpeg we use this command:

ffmpeg -i my_video.mp4 -vf "subtitles=subtitles.srt" my_video_with_subtitles.mp4

Extracting subtitles from video

With FFmpeg we can extract subtitles with this command:

ffmpeg -i video_with_subtitles.mp4 -map 0:s:0 subtitles.srt

Then we can open the file and edit it in Aegisub or any other program, as shown above.