How to hardcode subtitles into a video in Manjaro Linux

Published on 2019/03/14 ‚óŹ Updated on 2019/04

Table of contents

.srt subtitles

Ever wondered how to hardcode .srt subtitles into a video?
Or how to modify the font size before fusing them?

This tutorial will show you how to do that.

From ISO-8859-1 to UTF-8

For the process to be successful, we need the .srt file to be UTF-8 encoded.
Spanish subtitles files are commonly encoded as ISO-8859-1.

So, is it ISO-8859-1 or UTF-8?
Find out with:

file some.srt

If it’s UTF-8 encoded, you’ll see something like:

some.srt: UTF-8 Unicode text, with CRLF line terminators

If it’s ISO-8859-1 it’d be:

some.srt: ISO-8859 text, with CRLF line terminators

To convert an .srt file from ISO-8859-1 encoding to UTF-8, use:

iconv -f ISO-8859-1 -t UTF-8 some.srt > utf8.srt

Now your UTF-8 encoded subs will be in the utf8.srt file.

Hardcode the .srt file

Let’s suppose your subtitleless video file is called video.mp4.

To merge the .srt and the .mp4 files together, type:

ffmpeg -i video.mp4 -vf subtitles=utf8.srt video-with-subs.mp4

But wait, before you use a .srt file, let me tell you about…

.ass subtitles

The downside to using a pure .srt file, is that you cannot format the subtitles.

From .srt to .ass

That’s why it’s better to convert them to .ass:

ffmpeg -i utf8.srt subs.ass

Hardcode the .ass file

To format the subtitles, just open the .ass file in a text editor and modify the font size, etc.

—I always change the font size from 16 to 24.

Then hardcode the subtitles with:

ffmpeg -i video.mp4 -vf ass=subs.ass video-with-subs.mp4

That’s it!

P.S. The process is CPU intensive and uses all the cores available, so the more you have the better!

Links


— lt

Feedback & comments

Get in touch on Twitter

Or by good ol' email at adriandcs@gmail.com