Combine video+text style with css

Hello guys, I trying to build an web app that add caption style with css on top of a video. Now, I can overlay the text on the video, but how I can save the video + the text together in mp4 format. One solution is using Python+Selenium and takes screenshots of each frames and combine them and add the audio. Is that a good solution if I want to deploy the app ?