tencent cloud

Video on Demand

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Product Features
Features
Strengths
Scenarios
Solutions
Professional Edition
Introduction to Video On Demand Professional Edition
Quick Start
Console Guide
Development Guide
Purchase Guide
Billing Overview
Billing Modes
Purchase Guide
Viewing Bills
Renewal
Overdue Policy
Refund Policy
Getting Started
Console Guide
Console Overview
Service Overview
Application Management
Media Management
Package Management
License Management
Real-Time Log Analysis
Practical Tutorial
Media Upload
Smart Cold Storage of VOD Media Asset Files
Video Processing
Distribution and Playback
How to Receive Event Notification
How to Migrate Files from Origin Server to VOD
Live Recording
How to Pull from Custom Origin Servers
How to Use EdgeOne to Distribute Content in VOD
Development Guide
Media Upload
Media Processing
Video AI
Event Notification
Video Playback
Media Encryption and Copyright Protection
Broadcast Channel
CAM
Media File Download
Subapplication System
Error Codes
Player SDK
Overview
Basic Concepts
Features
Free Demo
Free Trial License
Purchase Guide
SDK Download
Licenses
Player Guide
Integration (UI Included)
Integration (No UI)
Advanced Features
API Documentation
Player Adapter
Player SDK Policy
Server APIs
History
Introduction
API Category
Other APIs
Media Processing APIs
Parameter Template APIs
Task Management APIs
Media Upload APIs
Media Management APIs
Event Notification Relevant API
Media Categorization APIs
Domain Name Management APIs
Distribution APIs
AI-based Sample Management APIs
Region Management APIs
Data Statistics APIs
Carousel-Related APIs
Just In Time Transcode APIs
No longer recommended APIs
Making API Requests
AI-based image processing APIs
Task Flow APIs
Data Types
Error Codes
Video on Demand API 2024-07-18
FAQs
Mobile Playback
Fees
Video Upload
Video Publishing
Video Playback
Web Playback
Full Screen Playback
Statistics
Access Management
Cold Storage
Agreements
Service Level Agreement
VOD Policy
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

How to Add Subtitles to a Video

PDF
Focus Mode
Font Size
Last updated: 2024-11-11 16:28:30
VOD supports adding (or deleting) standard multilingual subtitle files to HLS videos outputted from Adaptive Bitrate Streaming. During playback, users can switch between different language subtitles to enhance the viewing experience.
The process includes two steps: Add subtitles to the media files and Associate subtitles with the media files.
For ease of description, this article assumes the following specific scenario: add Chinese (zh) and English (en) subtitles to the output file from the adaptive streaming template ID (10) for FileId (1397757888586312345), so that when playing the file, you can choose to display the added Chinese or English subtitles.

Step 1. Add Subtitles to Media Files

This step adds subtitles to the media asset with FileId (1397757888586312345) and obtains a subtitle ID. Next, this subtitle ID will be used for subtitle association.
VOD provides two ways to add subtitles to media files: uploading subtitles and automatic subtitle generation.

Upload Subtitles

Upload existing subtitle files. After a successful upload, the subtitle information is automatically added to the media asset. There are two upload methods: console upload and server API upload.

Upload through console

1. log in to VOD console, go to the audio and video management page of the target application, and click manage the media asset you need to process.



2. Click Subtitle > Add Subtitles.



3. Upload the required subtitle file, and edit language and stream name (for display in the player), then click Confirm.



4. The Chinese and English subtitle IDs are qFXJrv and PPGQep, respectively.




Server API Upload

1. Invoke the server API ModifyMediaInfo, input parameters AddSubtitles to specify the subtitles to be uploaded:
"AddSubtitles": [
{
"Name": "demo_cn.vtt",
"Language": "zh",
"Format": "vtt",
"Content": "V0VCVlRUCgowMDowMDowMC4wMDAgLS0+IDAwOjAwOjAyLjA0MArkvaDlpb3lkJfvvJ8KCjAwOjAwOjAyLjEwMCAtLT4gMDA6MDA6MDQuOTUwCuaIkeW+iOWlve+8jOiwouiwou+8jOS9oOWRou+8nwoKMDA6MDA6MDQuOTgwIC0tPiAwMDowMDowNi45MDAK5oiR5Lmf5b6I5aW944CCCg=="
},
{
"Name": "demo_en.vtt",
"Language": "en",
"Format": "vtt",
"Content": "V0VCVlRUCgowMDowMDowMC4wMDAgLS0+IDAwOjAwOjAyLjA0MApIb3cgYXJlIHlvdT8KCjAwOjAwOjAyLjEwMCAtLT4gMDA6MDA6MDQuOTUwCkZpbmUsIHRoYW5rIHlvdSwgYW5kIHlvdT8KCjAwOjAwOjA0Ljk4MCAtLT4gMDA6MDA6MDYuOTAwCkknbSBmaW5lIHRvby4K"
}
]
2. Example of interface output (other fields omitted), from which the Chinese and English subtitle IDs are qFXJrv and PPGQep, respectively.
{
"Response": {
"AddedSubtitleSet": [
{
"Id": "qFXJrv",
"Name": "demo_cn",
"Language": "en",
"Format": "vtt",
"Url": "http://123.vod2.myqcloud.com/vodgzp123/1397757888586312345/subtitles/qFXJrv.vtt"
},
{
"Id": "PPGQep",
"Name": "demo_en",
"Language": "en",
"Format": "vtt",
"Url": "http://123.vod2.myqcloud.com/vodgzp123/1397757888586312345/subtitles/PPGQep.vtt"
}
],
"RequestId": "90b40581-bf44-4455-a238-c8fe614c20ca"
}
}

Intelligent Recognition Subtitle Generation

Through Audio and Video CR, automatically generate subtitles and add subtitle information to media assets. The process includes: preparing Audio and Video CR Templates,Task Initiation, and Result Acquisition. The key points are as follows:

1. Preparing Audio and Video CR Templates

There are two ways to create templates: console creation and server API creation.
1.1. Console Creation of Templates
1.1.1. Log in to VOD Console, after entering the target application, click Media Processing > Template Settings > Intelligent Recognition Template, click Create Intelligent Recognition Template.



1.1.2. Supports selecting "Speech to Text" to output the source language subtitle file, or "Speech Translation" to output the subtitle file in the target translation language. The following screenshot scenario describes converting source video speech to CR and translating it to the target language subtitle file.



1.1.3. After creating, you can see the newly created template ID 72314 in the template list.



1.2. Create template via Server API
1.2.1. Invoke the server API to create an audio/video CR template. The input parameter AsrTranslateConfigure specifies the speech translation task parameters:
"AsrTranslateConfigure": {
"Switch": "ON",
"SrcLanguage": "zh",
"DstLanguage": "en",
"SubtitleFormats": ["vtt"]
}
Note, if subtitle translation is not needed, you can use Speech Full Text Recognition (AsrFullTextConfigure) to specify generating subtitles in the video source language:
"AsrFullTextConfigure": {
"Switch": "ON",
"SrcLanguage": "zh",
"SubtitleFormats": ["vtt"]
}
1.2.2. According to this scenario, we specified Speech Translation (AsrTranslateConfigure). The interface output example (other fields omitted) provides the template ID (72314).
{
"Response": {
"Definition": 72314,
"RequestId": "12ae8d8e-dce3-4151-9d4b-5594145287e1"
}
}

2. Task Initiation

Multiple methods are supported to initiate intelligent recognition tasks:
Invoke server API
Initiate task flow from the console
Specify task flow upon upload
Upload from server
Upload from client
Upload through console
For the above methods, please refer to the Developer Guide Task Initiation. Additionally, you can directly initiate an II task through the console as follows:
2.1. Log in to VOD console, go to the Audio and Video Management page of the target application, select the FileId for subtitle generation, and click Intelligent Recognition.



2.2. Click Select template.



2.3. Select the recognition template you want to use and then click Confirm.






The page will indicate that the task has been successfully created:



2.4. On the Task Center page, you can see the task ID and task status of the subtitle generation task.



When the task status shows Completed, the subtitles have been successfully generated and automatically added to the media assets.

3. Result Acquisition

Using the task ID obtained from Back 'Task Initiation' and following the development guide Result Acquisition, you can obtain the subtitle generation results, which are located in the AiRecognitionResultSet array (type AiRecognitionResult) within the ProcedureTask structure:
When Type is AsrFullTextRecognition, it indicates that the full text translation result is saved in AsrFullTextTask.
When Type is AsrTranslateRecognition, it indicates that the translation result is saved in AsrTranslateTask.
Example of AsrTranslateTask:
{
"Status": "SUCCESS",
"ErrCode": 0,
"ErrCodeExt": "",
"Message": "SUCCESS",
"Progress": 100,
"BeginProcessTime": "2024-10-16T12:21:04Z",
"FinishTime": "2024-10-16T12:21:47Z",
"Input": {
"Definition": 102270
},
"Output": {
"SegmentSet": [
{
"Text": "How are you?",
"Translation": "How are you?",
"StartTimeOffset": 0,
"EndTimeOffset": 2.04,
"Confidence": 100
},
{
"Text": "I am good, thank you. How about you?",
"Translation": "Fine, thank you, and you?",
"StartTimeOffset": 2.1,
"EndTimeOffset": 4.95,
"Confidence": 100
},
{
"Text": "I am good too.",
"Translation": "I'm fine too.",
"StartTimeOffset": 4.98,
"EndTimeOffset": 6.9,
"Confidence": 100
}
],
"SegmentSetFileUrl": "http://251000800.vod2.myqcloud.com/6c0f30dfvodgzp251000800/397dbd234424135347904691234/75a7a19e-abaa-4af4-affb-04e76b3bc9bd.txt",
"SegmentSetFileUrlExpireTime": "2024-10-19T12:21:44.525Z",
"SubtitleSet": [
{
"Id": "qFXJrv",
"Name": "zh",
"Language": "zh",
"Format": "vtt",
"Url": "https://123.vod-qcloud.com/vodgzp123/1397757888586312345/subtitles/qFXJrv.vtt"
},
{
"Id": "PPGQep",
"Name": "en",
"Language": "en",
"Format": "vtt",
"Url": "https://123.vod-qcloud.com/vodgzp123/1397757888586312345/subtitles/PPGQep.vtt"
}
]
}
}
The example above shows that the Chinese and English subtitle IDs are qFXJrv and PPGQep, respectively.
When the task is successful, the generated subtitle information has been automatically added to the media assets.

Step 2. Associate subtitles with the media files

There are two ways to associate subtitles with the media files: associating subtitles via the console and associating subtitles via server APIs. The former only supports associating subtitles with already generated Adaptive Bitrate output files, while the latter supports associating subtitles with both stock and incremental files.

Console Subtitle Association

1. log in to VOD console, go to the audio and video management page of the target application. Click Manage > Subtitles > Edit for the Media Asset with FileId (1397757888586312345).






2. After clicking Confirm, an Operation Successful prompt will pop up in the upper right corner of the page, indicating that the subtitle association was successful.

Server API Associated Subtitles

Including associating subtitles with existing files and incremental files.

1. Associating subtitles with existing files

To associate subtitles with the output files of adaptive bitrate conversion, please invoke the server API Associated Media Subtitles. Input parameters are as follows:
{
"Action": "AttachMediaSubtitles",
"Version": "2018-07-17",
"FileId": "1397757888586312345",
"Operation": "Attach",
"AdaptiveDynamicStreamingDefinition": 10,
"SubtitleIds": ["qFXJrv", "PPGQep"]
}

2. Associating subtitles with incremental files

When initiating an Adaptive Bitrate Streaming task, specify the subtitle ID list in the input parameters of the Adaptive Bitrate Streaming task: MediaProcessTask -> AdaptiveDynamicStreamingTaskSet -> SubtitleSet.
The input parameter example for MediaProcessTask is as follows:
{
"AdaptiveDynamicStreamingTaskSet": [
{
"Definition": 10,
"SubtitleSet": ["qFXJrv", "PPGQep"]
}
]
}
Once the task is completed, the output file of the adaptive bitrate streaming will be associated with subtitles.

Step 3. Playback Effect

After successfully associating subtitles, you can choose to display subtitles in different languages while playing the video. Refer to the effect in the image below:






Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback