Adding subtitles to videos has become quite convenient thanks to voice recognition technology (ASR). OpenAI's Whisper series models, in particular, excel at speech-to-text conversion, making it possible to automatically generate subtitles.
However, extracting existing hard subtitles (subtitles embedded in the video image) still poses significant challenges.
Videos are essentially composed of continuous image frames. A common video frame rate is 30fps (30 frames per second), which means that a 1-hour video contains 108,000 images. For high-definition videos, the number of frames will be even higher. Such a large amount of data presents a severe test for OCR processing capabilities.
Google's Gemini-2.0-flash model not only supports text generation, but also supports the recognition and processing of videos and images, and provides a large number of free credits every day, which can be used as an OCR tool.
The domestic Zhipu AI glm-4v-flash model is not only free, but also has powerful image understanding capabilities and can be used as an OCR tool. Although it currently only supports Chinese and English recognition, it is sufficient for most scenarios.
A hard subtitle extraction software based on Gemini and Zhipu AI has been developed.
Download Address GVS Chinese and English Video Hard Subtitle Extraction Software (640MB)
Baidu Netdisk Download: https://pan.baidu.com/s/1SDKm5tWsr6dkajhsf8T5Ew?pwd=95i4
Github Download: https://github.com/jianchang512/stt/releases/download/0.0/GVS-v0.2-AI.7z
Software Usage Guide
The following are the steps to use the software:
Download and Extract: Download the software package, extract it, and double-click
app.exe
to run it.Select Video: Click the button at the top of the software interface, and select the video file for which you need to extract subtitles. Please make sure there are hard subtitles in the video.
Select Subtitle Position: Select the position of the subtitles in the video. The default is "Bottom", you can also select "Top", "Middle" or "All" area.
Fill in API Key:
You can fill in the API key of Zhipu AI, which is free in China.
You can also fill in the API key of Gemini AI, which has 1500 free calls per day, but scientific internet access is required in China. Multiple keys can be filled in, separated by English commas.
The Zhipu AI platform can be registered for free and obtain an API Key: https://bigmodel.cn/usercenter/proj-mgmt/apikeys
Gemini can go to this page to get it https://aistudio.google.com/app/apikey
Select Model: Zhipu AI supports the free GLM-4V-FLASH model. GeminiAI supports
gemini-2.0-flash-exp
andgemini-1.5-flash
models.If you use GeminiAI, you need to fill in the proxy IP and port, or enable system proxy in the vpn software.
Start Extracting: Click the "Start" button, and the progress and log information will be displayed in the text box at the bottom of the software. After the extraction is completed, an SRT subtitle file with the same name will be generated in the directory where the video file is located.
Technical Principles
The core steps of the software to extract hard subtitles are as follows:
- Video Frame Cutting: First, use the FFmpeg tool to cut the video into image frames at 1-second intervals. Selecting 1-second intervals instead of frame-by-frame extraction can greatly reduce the number of images that need to be recognized. On the other hand, considering that the duration of subtitles is usually not less than 1 second, too many frames will also increase the difficulty of deduplication.
- OCR Recognition: Send the cut image frames to the AI model for OCR recognition to extract the text in the image.
- Subtitle Deduplication: Since consecutive image frames may contain the same subtitle content, in order to avoid duplication, we use the sentence-transformers model to calculate the similarity between the currently recognized subtitle and the previous subtitle. If the similarity exceeds 60%, it is considered that the two subtitle contents are the same and deduplication is performed.
- Generate Subtitle File: Finally, stitch the deduplicated subtitle text according to the corresponding timestamps, and save it as an SRT format subtitle file.