0

I have the following :

  • a mkv file (let's call it A) with video, audio and subtitles correctly synchronized.
  • another mkv file (let's call it B) with video and audio also synchronized but without subtitles.

Both files are the showing same content but with different video/audio quality (B is much better than A). I would like to transfer subtitles from A to B. Both video streams are at 25 FPS but B contains a duplicate frame every 24 frames (it's probably the result of a 24 to 25 FPS conversion). Other than that, frames perfectly match (if we ignore the fact resolution is different).

I was wondering if there was a tool/method/script (even commercial) that would allow to me to sync subtitles with B automatically, using A video stream as reference and knowing it's perfectly synchronized.

For every frame in A, it's possible to find an almost 1:1 matching frame in B, so theoretically it should be possible to sync subtitles automatically.


What I already tried :

With Subtitle Edit : slowing down subtitles from 25 to 24 FPS and applying a given offset (since A and B do not start at same time). At first glance, it seems to work but after 15-20 minutes, subtitles start being unsync and it just get worse with time.

Additionally, I have notified that B contains additional content that A does no have (eg: there is a 10 seconds intermission in the middle of the stream).

EDIT: downvoters are invited to tell or explain what's wrong with this question.

tigrou
  • 871
  • 5
  • 14
  • 23
  • extract them to an .srt with ffmpeg https://superuser.com/questions/583393/how-to-extract-subtitle-from-video-using-ffmpeg give the .srt the same name and put it in the same folder as the new video and enjoy – Gantendo Jul 28 '22 at 11:53
  • did you read my question ? What you suggest is only going to work if FPS and content are exactly 1:1 – tigrou Jul 28 '22 at 12:15
  • @tigrou ffmpeg is capable of that and much more. Subtitles are synced to the video via timestamps, not frames. Find a way to synchronize the video files and you are good. If one video is significantly different, e.g. the 10min part you've mentioned, you are out of luck. Have a look at subtitle edit for manual adjustment. – mashuptwice Jul 28 '22 at 16:39
  • @tigrou Bit of a weird response to someone who gave the correct answer to the question. Have *you* read the question? – Gantendo Jul 28 '22 at 20:02

1 Answers1

0

After searching and trying things for countless hours, I choose to write my own Python 3 script to do the job. I have decided to share it here. Here is a link to it : https://gist.github.com/tigrouind/8cd1564568b7582feb776ad21edc8fff

Requirements :

  • opencv-python
  • srt

What it does: It take a subtitle and related frame from movie A and search the best matching frame in movie B. Once it find it, it adjust subtitle timings accordingly (it proceed like that for every subtitle). The search is limited to a certains number of frames in forward and backward direction.

I have applied it over to a 2:30 hours movie (which contains many small differences with reference movie and over 2000 subtitles) and it worked very well.

tigrou
  • 871
  • 5
  • 14
  • 23