Linux.com

Home Linux Community Community Blogs General Linux How to Merge Subtitles to a Movie

How to Merge Subtitles to a Movie

My refusal to use Windows is what makes me learn to do everything using only Linux, even though it usually requires long times in front of the computer researching and tweaking the hints google.com/linux gives me. But, at least I can say that at the end the results are satisfying, I end up learning more about Linux and how powerful a command line application can be compared to a most GUI application. I must admit that I do prefer GUI in the majority of the cases, is just that from time to time I am amazed by the power of the CLI. My latest adventure was learning how to merge a .srt (movie subtitle file) with a .avi (movie file). How I did it? Well, first we need to have mplayer installed, which on Arch Linux can be done as follows:

# pacman -Sy mplayer codecs

After that you might need to create the mplayer folder (if it isn't there already) so we can add the fonts we would like to use for the displaying of the subtitles in the movie, with that purpose we issue the following command:

$ mkdir .mplayer && cp /usr/share/fonts/TTF/LiberationSans-Regular.ttf .mplayer/subfont.ttf

Change the LiberationSans-Regular.ttf with the font you want to use. If you want to use the Liberation font, install the ttf-liberation package which is available in the community repository.

# pacman -Sy ttf-liberation

OK, we have gone a bit off the curse here with the fonts thing, but by now we should have the mencoder application installed, hopefully this makes us still on track for the merging that is about to happen. The mencoder application is part of the mplayer application we just installed, mencoder is the tool we are going to use to merge the subtitles with the movie. Now, to the better part of this tutorial, how we merge the subtitles with the movie files, the following script should do the trick:

$ mencoder -o fileiwantatend.avi -sub subtitlesfile.srt -oac copy -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell theactualmovie.avi

The first .avi we refer to in the above script is the file we want to create at the end of the merge (the resulting file), which could be named movie_subtitle.avi, now, the .srt file referred to in the script is the subtitles file which do not necessarily need to be on .srt format, it could be for example in .sub format, and the latests .avi file referred to in the command is the original movie file which you want to merge with the subtitles.

This command is very simple and has few options so it preserves the original movie file quality without much alterations, if any.
Legend:
# = as root
$ = as user

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFD320 Linux Kernel Internals and Debugging
    04 Aug » 08 Aug - Virtual
    Details
  2. LFD405 Embedded Linux Development with Yocto Project
    04 Aug » 07 Aug - Santa Clara, CA
    Details
  3. LFD312 Developing Applications For Linux
    18 Aug » 22 Aug - Virtual
    Details

View All Upcoming Courses


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board