srtresync: easy correction of linear drift for srt files

We’ve just open-sourced some code we’ve been using in-house in the form of srtresync, a smart and easy-to-use utility that can correct both traditional “fixed offset” errors as well as the more complicated “linear drift” issues that can affect srt subtitle files.

srtresync has been released under the terms of the MIT license, and is available on github, waiting to be forked and made even more awesome in the way that only open source software can be. It’s cross-platform (written in rust), and can be used on Windows, Mac, Linux, or FreeBSD. Use is quite straightforward in both modes, and the accompanying detailed README file should quite-easily double-up as a man file.

If you have cargo, the rust package manager, installed, you can install srtresync by simply executing

cargo install srtresync

Unlike most other utilities, srtresync can be used to correct both a fixed offset (say subtitles are consistently five and a half seconds behind) or linear drift (the difference between the subtitles and the audible dialog changes at a fixed rate, so that the difference/delay between audio and subtitles at the start of a film or clip is different than at the end).

Most srt synchronization utilities can handle fixed offset – where you need to just shift all subtitles by xxx milliseconds either forward or backwards to make them match the spoken dialog. But what is linear drift and why is this feature so special?

A common anomaly is to have a subtitle file which starts off either in-sync with the spoken audio track or deviating from it by only a fixed offset, but then to have the difference between the two either increase or decrease at a constant pace, such that by the end of the clip the difference is no longer whatever it started out as. For example, if you have a clip and corresponding srt where the subtitles currently displaying at 00:00:10.500 should actually be shown at 00:00:07.200 and the subtitles showing at 02:14:03.007 should actually be shown at 02:22:17.400, you will be starting off with the subtitles 3.3 seconds behind and end with the subtitles 494.4 seconds ahead, meaning we can’t just add or subtract a fixed amount from the display time and call it a day.

In cases like these, srtresync will automatically calculate the linear drift parameters and adjust the output accordingly. In addition, it’ll print the calculated variables to stderr for use as a quick sanity check:

> srtresync ./input.srt 00:00:10.500-00:00:07.200 02:14:03.007-02:22:17.400
 
Offset will be 00:00:03,950 scaled by time at a rate of -0.06195986

srtresync is our first foray into the world of rust development, and we hope to soon have a piece on our first experience using this intriguing new language. In the meantime, go forth and enjoy your newly-synchronized subtitles!

  • Similar Posts

    Craving more? Here are some posts a vector similarity search turns up as being relevant or similar from our catalog you might also enjoy.
    1. Using SIMD acceleration in rust to create the world's fastest tac
    2. Scripting in rust with self-interpreting source code
    3. rsevents: manual and auto reset events for rust
  • Leave a Reply

    Your email address will not be published. Required fields are marked *