0

I am trying to write subtitles on a video. The problem is , with cv2(opencv-python), I am unable to write text on different time frames , lets say for first two seconds I want "Hello", and for another 3 seconds the video will show "this is the introduction" and so on.

My question is, how can I achieve this with opencv-python. The thing why I want to use cv2 only is it creates an object for that video and do not create a new file, and that is important for my project.

If you guys have any idea how we can write subtitles on a video without creating another file, please do let me know.

I also tried ffmpeg it worked absolutely fine for me and I used a .srt file for that, but again it was creating a new file and same happened with moviepy library so in any case if you could show me a way how can we overwrite the file in ffmpeg or moviepy, it would be very helpful.

THANKS.

  • Without a file containing the text to place at pre-assigned points within the video, how do you propose the text should be introduced? – Rolf of Saxony Mar 22 '23 at 11:12
  • I do have a file that contains this information, that is a .srt file, I can modify that into the list of python or whatever needed, but exactly how would I pass that information in code through cv2, I could not understand. – sarveshsta Mar 22 '23 at 11:28
  • 1
    use ffmpeg. OpenCV is not for video file manipulation but for computer vision. – Christoph Rackwitz Mar 22 '23 at 12:10
  • Thanks @ChristophRackwitz, I used ffmpeg but see I don't want another output file , so is their any way I can do on the same file using ffmpeg ? – sarveshsta Mar 22 '23 at 12:19
  • with PyAV there might be a way to generate the subtitle stream, same as you'd generate the video stream. – Christoph Rackwitz Mar 22 '23 at 12:25
  • If (elapsedTime between A and B) set state = STATE1; else If (elapsedTime between B and C) set state = STATE2; and so on. Later ask for current state and print the text depending on in which state you are. – Micka Mar 23 '23 at 08:51

0 Answers0