Subtitle Generation and Translation
Last updated: 2023-04-14 15:31:57Download PDF
Case 1: Generating subtitles for an existing file
1. Zero code generation in the console
1. Log in to the MPS console and go to Schemes. Add a content discovery action (which can be used for speech recognition and translation). Click ![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/c1261002cea311ed9d66525400c56988.png)
and select a template.
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/c1261002cea311ed9d66525400c56988.png)
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/c7b070b9da9511edbe2a525400088f3a.png)
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/cc4956a7da9511eda050525400c56988.png)
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/c7b070b9da9511edbe2a525400088f3a.png)
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/cc4956a7da9511eda050525400c56988.png)
MPS offers the following preset content discovery templates:
Template ID | Capability |
10101 | Chinese speech recognition |
10102 | English speech recognition |
10103 | Chinese speech to Chinese and English text |
10104 | English speech to English and Chinese text |
Note:
If the preset templates do not meet your requirements, please submit a ticket. We can customize a template for your needs.
2. Enable the scheme. Wait about five minutes for the configuration to take effect, and upload your file to the trigger bucket.
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/d6ead119da9511eda050525400c56988.png)
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/d6ead119da9511eda050525400c56988.png)
3. After the task is executed, a VTT file will be generated and saved to the output directory.
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/e0d8323cda9511eda050525400c56988.png)
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/e0d8323cda9511eda050525400c56988.png)
Chinese subtitle sample:![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/eb185554da9511edbe2a525400088f3a.png)
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/eb185554da9511edbe2a525400088f3a.png)
Chinese and English subtitle sample:
![](https://cloudcache.intl.tencent-cloud.com/cms/backend-cms/c136b96fcea311ed9d66525400c56988.png)
2. Generation via an API
1. Call ProcessMedia, specifying the input file information and the scheme ID.
Example:
{"InputInfo": {"Type": "COS","CosInputInfo": {"Bucket": "facedetectioncos-1251132611","Region": "ap-guangzhou","Object": "/video/123.mp4"}},"ScheduleId": 20073,"Action": "ProcessMedia","Version": "2019-06-12"}
2. If you have configured a callback address, for details about the data returned, see ParseNotification.
3. Embedding the subtitles into the video
Create a transcoding task, setting
SubtitleTemplate
to the VTT file generated in step 1 or step 2. For details, see Data Types.Example:
{"MediaProcessTask": {"TranscodeTaskSet": [{"Definition": 206390,"OverrideParameter": {"Container": "mp4","RemoveVideo": 0,"RemoveAudio": 0,"VideoTemplate": {"Codec": "libx264","Fps": 30,"Bitrate": 2346,"ResolutionAdaptive": "close","Width": 1920,"Height": 0,"Gop": 0,"FillType": "black"},"AudioTemplate": {"Codec": "libmp3lame","Bitrate": 0,"SampleRate": 32000,"AudioChannel": 2},"SubtitleTemplate": {"Path": "https://lily-1256342427.cos.ap-nanjing.myqcloud.com/mps_autotest/subtitle/1.vtt","StreamIndex": 2,"FontType": "simkai.ttf","FontSize": "10px","FontColor": "0xFFFFFF","FontAlpha": 0.9}}}]},"InputInfo": {"Type": "URL","UrlInputInfo": {"Url": "https://lily-1256342427.cos.ap-nanjing.myqcloud.com/mps_autotest/subtitle/123.mkv"}},"OutputStorage": {"Type": "COS","CosOutputStorage": {"Bucket": "lily-1256342427","Region": "ap-nanjing"}},"OutputDir": "/mps_autotest/output2/","Action": "ProcessMedia","Version": "2019-06-12"}
Case 2: Generating subtitles for a live stream
1. Configuring a callback that returns the text in real time.
1. Call ProcessLiveStream to start a speech recognition task using a preset subtitle generation template.
Example:
{"Url": "http://5000-wenzhen.liveplay.myqcloud.com/live/123.flv","AiRecognitionTask": {"Definition": 10101},"OutputStorage": {"CosOutputStorage": {"Bucket": "6c0f30dfvodgzp251000800-10022853","Region": "ap-guangzhou-2"},"Type": "COS"},"OutputDir": "/6c0f30dfvodgzp251000800/0d1409d34565514956657373652/","TaskNotifyConfig": {"NotifyType": "URL","NotifyUrl": "http://xxxx.qq.com/callback/qtatest/?token=xxxxxx"},"Action": "ProcessLiveStream","Version": "2019-06-12"}
2. Receive the callback. For details about the data returned, see ParseLiveStreamProcessNotification.
2. Embedding the subtitles into the live stream
1. Make sure you have activated Cloud Streaming Services and MPS.
2. Submit a ticket to enable the live subtitling feature for your account.
3. The publishing and playback logic remains unchanged. You can get subtitled streams simply by adding a suffix that specifies the subtitle language to the playback URL.
For example, suppose the stream ID is5000_test
.Original stream (with no subtitles)http://5000.liveplay.myqcloud.com/live/5000_test.flvChinese speech to Chinese text subtitleshttp://5000.liveplay.myqcloud.com/live/5000_test_chs2chs.flvChinese speech to Chinese and English text subtitleshttp://5000.liveplay.myqcloud.com/live/5000_test_chs2chseng.flvChinese speech to English text subtitleshttp://5000.liveplay.myqcloud.com/live/5000_test_chs2eng.flvEnglish speech to English text subtitleshttp://5000.liveplay.myqcloud.com/live/5000_test_eng2eng.flvEnglish speech to English and Chinese text subtitleshttp://5000.liveplay.myqcloud.com/live/5000_test_eng2chseng.flv