Skip to main content

How to add and synchronize subtitles

This is tutorial on

  • Adding subtitle to a video clip and synchronizing it correctly. 
  • Shifting the subtitles correctly for out of sync subtitles.

Adding subtitle to a video clip


Lets say that the video clip is from a movie and we want to cut the subtitles from that portion of the movie and add it to this clip. The only problem is that the subtitles files are written in a continuous manner which makes it difficult to plain cut and paste operation of the relevant section. 
The steps involved are --

1.Get the subtitle file. 

2. Get the relevant portion of the subtitle file from the whole srt file and save it in another srt file.
If for eg. we want know some words at the beginning and the end we can extract the text from the srt file using grep.

Example file : The relevant section is in yellow.


1220
01:53:46,980 --> 01:53:48,140
Father-in-law!

1221
01:54:17,648 --> 01:54:23,780
I'm a foreigner,
I came from foreign...

1222
01:54:34,699 --> 01:54:40,569
For proud young men,
I left Washington...

1223
01:54:51,148 --> 01:54:53,673
.
.
.



1260

01:58:02,773 --> 01:58:08,541

New Zealand, Netherlands,

Thailand, Finland landed here....





1261

01:58:08,712 --> 01:58:11,078

Landed here?

What should we do now?



1262

01:58:11,415 --> 01:58:17,513

Put hand over hand
and dial the land line...



 We search for the term "foreign" because that is what we can recognize from the video. And extract till the word "Finland"


cat file.srt | grep foreign -A 160 -B 2 | grep Finland -B 160 > ringa.srt

What this command does : selects 160 lines AFTER the word "Foreign" from the srt file and 2 lines BEFORE it. Since the 160 lines were added ad hoc it has to then cut the lines before the word "Finland" which is done by the last grep command. Then the command dumps the text into a file which is named the same the video clip file with the extension changed to srt. 

3. Rename the clipped srt file so that the filenames are name.


4. Now open Gnome Subtitles. If it is not installed then install it

sudo apt-get install gnome-subtitles

Open the file clipped srt file. In this example it is ringa.srt 

As you see the timings for the srt are all messed up. It starts at 1hr 54 min 7sec. That is way too far. We need to readjust the starting time.

5. Adjust start time. We will use Timings -> Synchronize.

But first we need to select the frame where we want the subtitles to begin and then the frame where we want want it to end. Gnome-subtitles would appropriated stretch the subtitles by their interval ratios so that all text appear at the right moment.

Select the frame for the first sentence. 



As you can see it is not at the starting point.

Now goto Timings -> Synchronize. And press Add



6. Select the last line of the subtitle. Select the last frame where you want the subtitle to appear.

Repeat  procedure #5 with the end frame also. 

NOTE :- Remember to select the last line of the subtitle first otherwise the synchronize dialog would just replace the previous frame.

7. Save the subtitle file.



Adding subtitles into a video file

The subtitles can either be hard coded into the video or they can be soft coded into a container like mkv. The advantage of hard coding the subtitle file is that the subtitles are then viewable on all devices, even when the file is read by the TV from an USB device. The disadvantage is that it can never be turned off. The pros and cons of the soft coding is exactly the opposite. Since I play my files on my computer or phone and then stream them to the TV using Chromecast, I will adopt the latter procedure of soft encoding the subtitle file into the video file. This allows far greater flexibility. In fact, with modern smart/streaming devices and TVs hard-encoding is not required at all.

To soft-encode the subtitle file we need to create a container (like mkv) and include the video and the subtitle file in it. A simple tool called mkvmerge can do the job in Linux. If mkvmerge is not already installed then the mkv-toolbox needs to be installed first.

sudo apt-get install mkvtoolnix

Then we merge the video and the subtitle files. Let's say the video file is video.mp4 and the subtitle file is eng.srt.

mkvmerge -o output.mkv video.mp4 eng.srt

The file output.mkv should now have embedded subtitles.

Shifting subtitles

Shifting the subtitles when there is a lag with the video can achieved in the player itself. For example in mplayer the z and x keys would shift the subtitles in the backward and forward directions respectively (v disables subtitles in mplayer). In vlc the appropriate keys can be found and also modified in the preferences. 
But the players have the handicap that they cannot adjust for delays more than 10 mins or ever increasing delays.

For ever increasing delays just use the procedure of last section. For larger than 10 min delay use the Timing -> Shift option of the Gnome-subtitles.




Comments

Popular posts from this blog

Fastest way to send multiple drafts from gmail

People claim that the fastest way to send multiple email drafts is to use Gmail IMAP with email client like Outlook or Evolution or Thunderbird. But I have found this is not true. Because Thunderbird and Evolution etc. email clients treats the drafts as emails still to be edited. So it is not just simple select all and hit send. Each email draft has to be opened and sent separately. That is a lot of clicks and mouse movements, wasting precious time and energy. I have a better solution which involves minimum keystrokes and mouse usage. Efficiency booster technique for sending emails. If someone is feeling adventurous and want to try it from the Gmail interface itself, here's how to do it in the fastest possible manner. It involves using the mouse once. Select the first draft. Gmail would open a new email box and put the cursor inside the box to write. Press TAB once to go the Send button. Press ENTER to send. Now Gmail sends it and the box is gone but the highlight goes to the last

LYRICS OF CHANDRABINDOO

___________________________________________________________________ SWEET HEART FROM AAR JAANI NAA(T-SERIES) -- SWEETHEART -- Pratham college-er din ta Aajo thik e mone poRey scene ta Dada didi haath dhorey siNRi tei bose poRey Aamar chokh ta ghorey bon bon bon bon Sweetheart, I am seating alone Sweetheart, for me there is none DhoNk gile chole gelo pratham maas Meye dekhlei feli deergho-shwash DhoNk gile chole gelo pratham maas Meye dekhlei othe nabhishwash Meyera bheeshan smart poRey chhoto mini-skirt Aamar e je sheet korey kon kon kon kon Sweetheart, I am seating alone Sweetheart, for me there is none Taarporey kete gelo maas chaar Fuse holo je kato future Bandhura purse khule eke oke taake tole Aamar pran ta korey chon mon chon mon Sweetheart, I am seating alone Sweetheart, for me there is none Ekdin lawn theke beriye Ek tanayaar dike taakiye Hawt korey ki je holo magaj ta ghurey gelo Taar kaaner saamne kori ghyan ghyan ghyan ghyan Sweetheart, I am seating alone Sweethea

Changing the font size of section headings in LaTex

You have several ways to do so: 1.- A direct redefinition of \section: \makeatletter \renewcommand\section{\@startsection{section}{1}{\z@}%                                   {-3.5ex \@plus -1ex \@minus -.2ex}%                                   {2.3ex \@plus.2ex}%                                   {\normalfont\large\bfseries}} \makeatother 2.- By means of the titlesec package: \usepackage{titlesec} \titleformat{\section}{\large\bfseries}{\thesection}{1em}{} 3.- By means of the sectsty package: \usepackage{sectsty} \sectionfont{\large} source : http://www.latex-community.org/forum/viewtopic.php?f=4&t=3245   Now, I would explain the titlesec package a bit more (because it seems easier to me and with more options) : To change the section fonts with this package put the following lines in the preamble - \usepackage{titlesec} \titleformat{\ section }{\ large \ bfseries }{\thesection}{1em}{} Options available are- a> Font size - \normals