topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday March 3, 2021, 6:48 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: [Solved] Adjust Subtitle (SRT) Timestamps  (Read 1015 times)

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,270
    • View Profile
    • Donate to Member
[Solved] Adjust Subtitle (SRT) Timestamps
« on: December 20, 2020, 02:26 AM »
Hi all,

I've got a movie that would be pretty tame (PG in the USA) were it not for the fact that inexplicably it has about 30 seconds of nudity in a scene that has absolutely no bearing on any part of the film. Okay, I said the reason was inexplicable, but it's a French film, so I guess it should go without saying. Anyway, in an effort to make it more family friendly, I've ripped the DVD and cut out the scene with nudity. But, seeing as it's a French film, and I don't speak French, now all the timings for the subtitles are off by a significant enough amount that it's hard to follow.

Actually, editing the file made me lose the subtitles, but I downloaded new ones (in SRT format).

The idea of manually adjusting the time for each line of text that appears is just far too daunting a task for me to even begin. Surely there must be some way to do this automatically? Or perhaps someone who is knowledgeable with Regular Expressions can whip something up for me that will find all timestamps, do a calculation on them, and then replace them with the new values?

Here are my requirements:

  • Allow me to enter the "start time" or the time after which all future timestamps should be modified. Or in other words, don't modify the timestamps for anything before this time.
  • Allow me to enter an adjustment amount by which to modify the timestamps. The timestamps are down to the millisecond precision level, FYI.
  • Allow me to press "Go" and have it do its work.
  • Bonus points if it erases any subtitles that may exist in the resulting "limbo zone" (the time between the "start time" and the "start time + adjustment amount" time) and double bonus points if it also renumbers any following subtitles to compensate for deleted ones.
  • Either present me with the changed text in a textarea I can copy to my clipboard or allow me to output the text to a file of my choosing (so I can choose to keep the original file if I want). Or, essentially, don't destroy any data without my explicit consent.

I actually don't need all of that. If it just let me enter the amount to shift every timestamp by, with precision down to one second, I would happily work with that. I'd be able to run it on the file and then copy and paste everything after the "start time" from the new times over the original times, and manually edit out the relatively few "limbo zone" subtitles.

Thanks in advance! :Thmbsup:
« Last Edit: December 20, 2020, 11:39 AM by Deozaan »

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 180
    • View Profile
    • Donate to Member
Re: Adjust Subtitle (SRT) Timestamps
« Reply #1 on: December 20, 2020, 08:00 AM »
Something like this should work...

It needs to be invoked via command line parameters:
"Adjust .srt times.exe" "D:\1.srt" "00:00:04,049" 200

Arg 1: The .srt file to parse
Arg 2: The first (from) timestamp where the time shifting should begin
Arg 3: The amount of time in milliseconds (either positive or negative) to shift
          If you need a shifting of multiple seconds, e.g -2.3 -> -2300 ms, use "-2300"

This is the content of a test .srt file:
1
00:00:00,230 --> 00:00:02,939
hi this is Roger in Finland and today

2
00:00:02,939 --> 00:00:04,049
we're gonna take a look at how to add

3
00:00:04,049 --> 00:00:05,730
subtitles to your videos either for

10
00:00:15,990 --> 00:00:18,660
[Music]
not playing loud
zzzZZZzzz

11
00:00:18,660 --> 00:00:21,180
solution is to go through generate an

12
00:00:21,180 --> 00:00:23,160
srt subtitles file it can be done



and this is what gets copied to the clipboard:
1
00:00:00,230 --> 00:00:02,939
hi this is Roger in Finland and today

2
00:00:02,939 --> 00:00:04,049
we're gonna take a look at how to add

3
00:00:04,249 --> 00:00:05,930
subtitles to your videos either for

4
00:00:16,190 --> 00:00:18,860
[Music]
not playing loud
zzzZZZzzz

5
00:00:18,860 --> 00:00:21,380
solution is to go through generate an

6
00:00:21,380 --> 00:00:23,360
srt subtitles file it can be done

« Last Edit: December 20, 2020, 08:14 AM by highend01 »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,230
    • View Profile
    • Donate to Member
Re: Adjust Subtitle (SRT) Timestamps
« Reply #2 on: December 20, 2020, 08:46 AM »
I use Subtitle Edit for all...uhhh...subtitle editing.   :P

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,270
    • View Profile
    • Donate to Member
Re: Adjust Subtitle (SRT) Timestamps
« Reply #3 on: December 20, 2020, 11:37 AM »
Something like this should work...

It needs to be invoked via command line parameters:
"Adjust .srt times.exe" "D:\1.srt" "00:00:04,049" 200

Arg 1: The .srt file to parse
Arg 2: The first (from) timestamp where the time shifting should begin
Arg 3: The amount of time in milliseconds (either positive or negative) to shift
          If you need a shifting of multiple seconds, e.g -2.3 -> -2300 ms, use "-2300"

I'm not sure what I'm doing wrong, but even after several attempts experimenting with different arguments, my output always looks like this:

1
 -->

2
 -->

3
 -->

I use Subtitle Edit for all...uhhh...subtitle editing.   :P

Thanks for pointing me toward this. Using it, I was able to splice something together that seems to have done the trick. :Thmbsup:

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 180
    • View Profile
    • Donate to Member
Re: [Solved] Adjust Subtitle (SRT) Timestamps
« Reply #4 on: December 20, 2020, 12:32 PM »
Show me the exact command line you've used and a link to the .srt file to download it, please.

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,270
    • View Profile
    • Donate to Member
Re: [Solved] Adjust Subtitle (SRT) Timestamps
« Reply #5 on: December 20, 2020, 10:05 PM »
Show me the exact command line you've used and a link to the .srt file to download it, please.

I'm new to the whole subtitle thing, so I just did a search and found an admittedly sketchy looking site that I'm not sure can be trusted. So instead of linking you to that site, I've attached the file I downloaded, which I renamed to make it easier to type in the command line and have zipped since the site doesn't allow attaching SRT files.

I also renamed your AHK file to "adjust srt times.exe" to make it slightly easier to deal with.

The command I used was:

"adjust srt times.exe" J.srt "00:34:09,263" -95000

It tells me the details are copied to the clipboard, but when I paste it into a text file, I get what I posted above; all entries are blank.

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 180
    • View Profile
    • Donate to Member
Re: [Solved] Adjust Subtitle (SRT) Timestamps
« Reply #6 on: December 21, 2020, 01:54 AM »
It didn't like the linebreaks in your j.srt file, hence the output
The timestamp you're using on the command line doesn't exist in the file so I've changed the logic to:
It begins to shift times beginning with the first timestamp that is larger (or equal to) than the one you're giving on the command line.
Before it was: Once the given timestamp matches one in the file, begin to shift from there...

So with "00:34:09,263" it will turn this (from j.srt):
304
00:33:21,776 --> 00:33:25,361
No! I have lice.

305
00:35:17,846 --> 00:35:20,847
We'll sing again together,
just like before.

into this (clipboard):
304
00:33:21,776 --> 00:33:25,361
No! I have lice.

305 -> These (and all following) timestamps will be shifted by -95 seconds
00:33:42,846 --> 00:33:45,847
We'll sing again together,
just like before.
« Last Edit: December 21, 2020, 08:19 AM by highend01 »

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,476
    • View Profile
    • Donate to Member
Re: [Solved] Adjust Subtitle (SRT) Timestamps
« Reply #7 on: December 21, 2020, 01:59 AM »
I use Subtitle Edit for all...uhhh...subtitle editing.   :P

Me too but I've found myself using VS Code with a subtitle extension more lately.

Only really resort to Subtitle Editor if I need to change the frame rate now.