byroot / pysrt

Python parser for SubRip (srt) files
GNU General Public License v3.0
451 stars 69 forks source link

Subtitle synchronization with input video files. #93

Open qaixerabbas opened 1 year ago

qaixerabbas commented 1 year ago

Hi everyone.

I have transcribed a video using transformers library. Now I have a temporary .txt file for video transcription. I am using pysrt for creating a .srt file for subtitles. I have created a .srt file successfully using following code.

srt_file = pysrt.SubRipFile()
srt_file.append(
    pysrt.SubRipItem(
        index=1,
        text=transcription,
        start=pysrt.SubRipTime(0, 0, 0),
        end=pysrt.SubRipTime(hours=0, minutes=0, seconds=59),
    )
)

and I am saving the resulting file using following line. srt_file.save("video.srt", encoding="utf-8")

but I am not sure how to synchronize the video with the start and end time. I know that I can play with following two lines

        start=pysrt.SubRipTime(0, 0, 0),
        end=pysrt.SubRipTime(hours=0, minutes=0, seconds=59),

for syncing video with the .srt file. My question is that when my audio file is longer than 25 seconds, I am not able to sync it with the whole video. Is there any external library or code that I can use or any information about how can I sync the resulting .srt file with the input video?

Thanks in advance.