Adding subtitles to videos has become quite convenient nowadays with the help of Automatic Speech Recognition (ASR) technology. Especially, OpenAI's Whisper series models excel in speech-to-text conversion, making automatic subtitle generation possible.
However, extracting existing hard subtitles (subtitles embedded in the video frame) from videos still poses many 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 poses a severe challenge to OCR processing capabilities.
Google's Gemini-2.0-flash model supports not only text generation but also video and image recognition and processing. It also provides a large number of free credits daily, 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 to select the video file for which you need to extract subtitles. 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", but you can also select "Top", "Middle", or "All" areas.
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. There are 1500 free calls per day, but you need to use a proxy to use it in China. You can fill in multiple keys separated by English commas.
You can register for free and get an API Key on the Zhipu AI platform: https://bigmodel.cn/usercenter/proj-mgmt/apikeys
You can get Gemini's API key on this page: https://aistudio.google.com/app/apikey
Select Model: Zhipu AI supports the free GLM-4V-FLASH model. GeminiAI supports the
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 Extraction: Click the "Start" button, and the progress and log information will be displayed in the text box below 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. Choosing a 1-second interval instead of frame-by-frame extraction can greatly reduce the number of images that need to be recognized. On the other hand, considering that subtitles usually last for no less than 1 second, too many frames will also increase the difficulty of deduplication.
- OCR Recognition: Send the segmented image frames to the AI model for OCR recognition to extract the text in the images.
- Subtitle Deduplication: Since consecutive image frames may contain the same subtitle content, to avoid repetition, 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 subtitles have the same content, and deduplication is performed.
- Generate Subtitle File: Finally, the deduplicated subtitle text is spliced according to the corresponding timestamps and saved as an SRT format subtitle file.