Add subtitles starting at a specific timestamp using Ffmpeg-Python

283 Views Asked by At

I want to add a .srt file (subtitles) to a .mp4 video. How can I add the subtitles at a specific timestamp?

As an example, my .mp4 video starts the talking part at 00:00:25, so thats there where I want to have the subtitles appearing with the audio.

I have this at the moment to add the subtitles in the video (and it works):

video_clip = ffmpeg.input("background_video.mp4")
video_clip.filter("subtitles", f"Subtitles/{post_id}/sub.srt",
                                           fontsdir="fonts/Roboto-Black.ttf",
force_style="Alignment=10,FontName=Roboto-Regular,FontSize=12")
                            

Thanks in advance.

What I have above adds the subtitles in the beginning of the video (instead of in the 25th second)

1

There are 1 best solutions below

1
 RolandReff On
video_clip.filter("subtitles", f"Subtitles/{post_id}/sub.srt",
                                        fontsdir="fonts/Roboto-Black.ttf",
force_style="Alignment=10,FontName=Roboto-Regular,FontSize=12",itsoffset = "00:00:25.0")

itsoffset = "00:00:25.0" at the end of the filter should do the trick perhaps, im used to another ffmpeg python binding but might be worth a shot.