Category Archives: Video

How To Create and Embed Subtitles – Or – How to spend half of a weekend to help a friend

A friend of mine asked me to help him with a presentation,
Part of the presentation includes several movies – you know the fast paced movies you see in Youtube? Where there isĀ  a narrator and it’s like he draw the lecture on the board? Just like that.
Now my friend uses these but not all of his designated audiences knows English that well, so he requested of me a help with embedding subtitles (So the video will have subtitles no matter where it is showed)

Now in the past I used to translate existing subtitles to my native language of Hebrew, But that was only to take existing subtitles and translating them – which is not that hard.
In this situation I had 2 new issues to address – how to create the subs themselves and how to embed them into the video (which learning how to actually took me longer then translating and creating a subtitle to one video)

Create Subtitles

Note: This is a very simple explanation – I’m not very fluent in this software and I use it very basically – so don’t expect advance explanations and changes to existing subtitles.

Download and Install aegisub – This is a simple and open source version to create subtitles.

After starting it up you will see a bit confusing array of options, don’t worry – although this software can do much I used it in very minimal fashion and so can you.

The window combine 3 main sections:

  • On the upper left – where you can watch the video with the created subtitles.
  • On the upper right – where you can create new subtitles sections based on the sound
  • On the bottom – where you see and select all your subtitles.

The first thing you need to do is to open a video you want to create translation to:

After opening the video you will get to the working environment where you can add new lines of subtitles:

From here the job is easy (though tedious):

  • Run “Play Section” in the audio section
  • See if the section is ok for you – if not use the bars in the sound section (the red and blue bars) to adjust the section you want the subtitle in.
  • When you are satisfied with the timing enter the text in the box (use shift+enter for a new line) and in the end finish this line by pressing:
  • This will create a new line following the existing one – and that’s it.
  • This is a simple way to create some subtitles for your videos
  • Don’t forget to save your project (in ass format) – You can export it in srt format if needed.
Simple Example:

Although this is a very basic way to do it this suffice me for what my friend wanted help with.

I might play with this software (aegisub) a bit more to be able to change and update subtitles (and also add neat features for the subtitles)

The plot thickens

When I’ve finished creating the subtitles for one of the videos I’ve sent it to my friend and asked him to test it. However I got a message from him telling me that the subtitles don’t show. Apparently his pc doesn’t have VLC installed. Not only that, when he will add the videos to the presentation it won’t work (because the player of the presentation software might not support ass format subtitles.

So how can we make sure the subtitles work?

Well the easy method is just add them to a container – for example change the movie from AVI or MP4 format to the MKV format – one that can have the subtitles inside (support multi subtitles and audio to be encased in one file). Although I think this is the best method of work I can’t be sure the person on the other end using this video/player/presentation will know how to operate it so this option is invalid.

So now I need to embed the subtitles directly to video, fine let’s just use what I always use: ffmpeg.
I thought this will be easy – ffmpeg is widely used and I’ve used it many times to create several encoding encase audio into videos and more. Alas for unknown reason trying to embed a Hebrew srt/ass file to the video did not succeed.
So what to do now? Well I’ve found a simple yet effective software to achieve what I needed: VidCoder

Embed the subtitles with the videos

Download VidCoder.

  • Run the software (VidCoder).
  • Select file to encode
  • Edit the subtitles
    • Import .srt file (aegisub can export to srt format)
    • Select:
      • Burn In
      • Language
      • Encoding
    • Press OK
  • Select your destination.
  • Add to Queue
  • And just encode!
Simple Example:

Appendix: How to make ffmpeg work!

Well after writing all of this (and it is working fine) I was annoyed – Well I’m an IT guy – fuck this I’m gonna solve the ffmpeg issue!

So I sat down and tried to understand why the encoding didn’t work.

Took me a while to understand that due to the fact that the font config was not there it didn’t manage to set the subtitles (although it didn’t need it when tried using encapsulating the subtitles in the format).

So what helped me? This guy: https://github.com/FiveYellowMice/how-to-convert-videos-with-ffmpeg-zh/tree/master/etc/fontconfig-windows

I basically downloaded his fonts.conf put it in the ffmpeg folder and then added it to the environment:

After that I only needed to encode (Linux example can be found here: https://wiki.archlinux.org/index.php/Font_configuration#Example_fontconfig_configurations or https://www.freedesktop.org/software/fontconfig/fontconfig-user.html)

Now you only need to use ffmpeg to convert your video!
Now there are many examples exist on the web on how to do that but I will provide a small examples here.

Attach Subtitles to Container

MP4:

1
2
3
ffmpeg -i input.mp4 -f srt -i input.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s mov_text output.mp4

Unfortunately this method missing the “Default” parameter which mean the you need to select the subtitle manually instead of a default subtitle showing up.

MKV (without default subtitle):

1
2
3
ffmpeg -i input.mp4 -f srt -i input.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s mov_text output.mp4

MKV (with default subtitle):

1
2
3
4
ffmpeg -i input.mp4 -f srt -i input.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s srt -metadata:s:s:0 language=LANGUAGE -disposition:s:s:0 default \
output.mkv

(example: ffmpeg -i gaga.mp4 -f srt -i gaga.srt -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s srt -metadata:s:s:0 language=Hebrew -disposition:s:s:0 default Test2.mkv)

Sources:

Embed (Burn) Subtitles to the Video

ffmpeg -i video.avi -vf subtitles=subtitle.srt out.mp4

Source: https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo