0

I'm trying to trim an SRT file, changing the starting time and duration.

The file subtitles.srt has these lines midway through:

185
00:13:34,880 --> 00:13:39,130
one

186
00:13:39,680 --> 00:13:41,962
two

187
00:13:42,200 --> 00:13:44,562
three

I run these two commands:

ffmpeg -ss 817 -t 3 -i subtitles.srt pre.srt
ffmpeg -i subtitles.srt -ss 817 -t 3 post.srt

And I get these two files:

pre.srt:

1
00:00:00,000 --> 00:00:04,250
one

2
00:00:04,800 --> 00:00:07,082
two

3
00:00:07,320 --> 00:00:09,682
three

...on through the rest of the source file

post.srt:

1
00:00:02,680 --> 00:00:04,962
two

Clearly neither of these are correct.

The first file is shifting all the lines forward 2.12s so that the opening line can keep its full duration -- in other words, it's moving the ss back to the beginning of the first line in its range. (Plus, it's not trimming the end at all; it just goes all the way to the end of the source)

The second file is much closer to being accurate, but it throws out the opening line entirely and picks up from the second line.

The output I'm expecting should look like this:

1
00:00:00,000 --> 00:00:02,130
one

2
00:00:02,680 --> 00:00:04,962 (or 00:00:03,000)
two

Any ideas how I can make ffmpeg trim the file properly?

Unfortunately it does have to be ffmpeg, but I can rearrange the subtitles in whatever way, e.g. I can change them to .ass or I can add them as a stream in a video file and trim that, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.