0

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 Answer 1

0
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello Roland, thank you for the quick response. I found out about itsoffset later that day but could manage to use that using the filter method (as you just explained to me). Although I was able to delay the subtitles by using the pysrt library, using the shift method: python subs = pysrt.open(f"Subtitles/{post_id}/sub.srt") subs.shift(seconds=2.5) subs.save() And it does the same. I will test your solution when I have time for that, thank you again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.