Updated: November 29, 2024
The problem you're facing is as follows. You would like to watch a movie in foreignese, and for that you need subtitles. Nowadays, it's quite trivial finding subtitle files for whichever movie you want, in a whole range of languages. You just need to grab an SRT (.srt) file, name it the same as your movie, and Bob's your uncle. Any self-respecting media player - or failing that, go for VLC, which is the best - will automatically load and display subtitles. But what if they are out of sync?
I talked about Linux and subtitles a long, long time ago. Most of what I wrote in that guide still holds. But I didn't cover the topic of time shift in the subtitle files. Perhaps you have the right words, but they are shown too late or too early. Even as little as 300ms difference can make the watching rather annoying. Anything above that is simply unplayable. Well, let me show you how you can quickly, and easily fix subtitles. After me.
Name of the game: ffmpeg
In general, in life, if in doubt, and you're handling media files, ffmpeg. This can and should be your one-stop shop for all things video, audio, whatever. Most media editing programs are just elaborate frontends for ffmpeg. It's present in pretty much any and every tool that does some sort of moving pictures or sound out there. If you're using Linux, you're doubly in luck, because ffmpeg is available in pretty much all repositories.
I'm going to demonstrate the use of the program in Linux. The commands will be the same on all other operating systems, wherever you can run and install ffmpeg. The only difference is in how you obtain the program. Well, in Linux, it boils down to:
(sudo) [package manager] install ffmpeg
For example, in the Debian- and Ubuntu-based family of distros:
sudo apt install ffmpeg
Now, we need to fix the subtitle offset. I've already written a guide on ffmpeg, and it's reasonably comprehensive, and there's my memes in HD article, too. Alas, much like the subtitle tutorial, it doesn't cover the time offset change. All right, the functionality is there, you just need a new flag. To wit:
ffmpeg -itsoffset [time] -i [subtitle file] -c copy [edited subtitle file]
A practical example:
ffmpeg -itsoffset -13.6 -i sub1.srt -c copy subs2.srt
What do we have here?
- -itsoffset allows you to shift the input streams. It can be used for single-stream files like .srt (basically text), or for video and audio files, with multiple streams, like say a typical movie, which has the video track and the associated audio track, usually one each. You could look at my different media editing articles, where I use KDEnlive, to see this in practice.
- -13.6 indicates the actual offset. The notation is ss.mmm, so you can go as low as 1 ms if you need to. In my case, I manually played a file, checked when the subtitles show and/or ought to show with an easy scene, and made the necessary adjustment. It took me a couple of trials to get the right offset. This isn't precise science, so -13.7 or -13.55 would also work quite well. In my case, the offset is negative.
- Finally, I specify the input stream, the original subtitle file, I use no codec (copy), as this option doesn't really mean much for SRT, and finally, the output file, which will eventually become the correctly positioned subtitles I will use with the (namesake) movie.
Conclusion
Using Linux can be difficult sometimes. But then, there are also situations where it's pure blessing. In general, if you have various maintenance tasks, especially around media files, it offers a wealth of easily accessible tools and utilities to get the job done. No need to heedlessly wander around the net downloading random programs from weird websites, especially not in this modern age of everything-is-fake Internet.
Well, if you happen to be a consumer of worldwide media and not just plain ole English, sometimes, you may come across a film or three that you won't be able to understand natively, and some subtitles be necessary. You want those subtitles to fit the narrative. Should that not be the case, ffmpeg can easily solve the issue for you. The offset function is simple, fast, elegant. One or two seconds [sic], and you're done. That would be all for today, fellas.
Cheers.