Ask Your Question

Add subtitles to video

asked 2016-08-26 03:44:37 -0500

Mikl gravatar image


Can i add subtitles to video file, using OpenCV?

edit retag flag offensive close merge delete


do you mean just printing text on the frames (YES) or embedding subtitles as text in the container (so e.g. vlc will find them ? (NO.)

berak gravatar imageberak ( 2016-08-26 03:53:06 -0500 )edit

again, opencv is a computer-vision library. if you need extensive video editing, you'll have to look for something else.

berak gravatar imageberak ( 2016-08-26 03:54:23 -0500 )edit

No, i mean embedding subtitles as text in the container

Mikl gravatar imageMikl ( 2016-08-26 06:41:58 -0500 )edit

ok. wrong library for your purpose then, i guess.

berak gravatar imageberak ( 2016-08-26 06:43:53 -0500 )edit

Ok. Thanks. Do you know what i need to use? Maybe i can ADD extra library?

Mikl gravatar imageMikl ( 2016-08-26 07:18:28 -0500 )edit

You can always store the text into separate xml file and use frameIndex as key. Than you have to build a player that reads the frame, reads the text from the file and puttext(frame,text,position...) than imshow("Live",frame) ;)

pklab gravatar imagepklab ( 2016-08-26 10:58:26 -0500 )edit

VLC + .srt subtitles or FFmpeg?

Eduardo gravatar imageEduardo ( 2016-08-26 19:25:14 -0500 )edit

@Eduardo I need .srt. I don`t need to burn text. It is a video "metadata" and will be reused later. But can i keep it in the same video file?

Mikl gravatar imageMikl ( 2016-08-30 02:25:37 -0500 )edit

.srt subtitles are only text files, you can look here an example of the structure of the file.

You can embedded subtitles with videos easily using .mkv (Matroska video format) videos.

Eduardo gravatar imageEduardo ( 2016-08-30 11:48:25 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2020-04-22 13:08:12 -0500

McLed gravatar image

You can sort of do this by using subprocess to spawn FFmpeg to extract an "SRT" stream, then read the set file.

FFmpeg command is something like this:

ffmpeg i MyVideo.mp4 -map 0:1 if subs are in the 2nd stream or ffmpeg -i MyVideo.mp4 -vn -an -c:s:0 text

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-08-26 03:44:37 -0500

Seen: 1,214 times

Last updated: Aug 26 '16