ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Coding Snacks

[Solved] Adjust Subtitle (SRT) Timestamps

(1/2) > >>

Deozaan:
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:

highend01:
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

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

Deozaan:
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"
-highend01 (December 20, 2020, 08:00 AM)
--- End quote ---

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
-skwire (December 20, 2020, 08:46 AM)
--- End quote ---

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

highend01:
Show me the exact command line you've used and a link to the .srt file to download it, please.

Navigation

[0] Message Index

[#] Next page

Go to full version