Add Subtitles

Last update:2024-01-15 14:29:13

This feature allows you to add subtitles into your videos. You can either hardcode the subtitles into the video or softcode them to allow viewers to select their preferred language. This process can be used in conjunction with other media processing operations within a single API call.
At CDNetworks, we provide support for adding subtitles to a variety of video formats and codecs, including:

  • Supported formats: MP4, FLV, M3U8, TS, MKV, MOV, WMV, AVI, VP8, VP9, RealVideo, Windows Media Video, and more.
  • Supported codecs: H.265, H.264, H.263, MPEG, and more.

This process can be used in conjunction with other media processing operations within a single API call.

How to Use

Structure your fops in the request body as follows:

<op>/<Format>
    /subtitle/<value>
    /subtitleType/<value>
    /subtitleAttr/<value>
    |saveas/<Urlsafe_Base64_Encode(bucket:filekey)>

Parameters

Parameter Required Description
op Yes Operation type. For media video/audio processing, set the operation type to avthumb.
format Yes Target format for output, such as flv, mp4, m3u8, etc.
subtitle Yes The subtitle file to be embedded into the video. The subtitle file can be in any of the following formats:
1. SRT format (encoded with UTF-8).
2. MKV format with subtitles (subtitles must be extracted from the MKV video file before being embedded into the target video).
3. Embed format (embed the subtitle stream from the original video into the target video).
The parameter must be formatted in the <bucket>:<path> manner and then securely encoded using URL-safe Base64. For instance, test:1.srt refers to the 1.srt subtitle file located in the test bucket, which is slated for embedding into the video. After Base64 encoding, the end value of this parameter is dGVzdDoxLnNydA==.
You can also configure multiple subtitle files for the same video by concatenating different subtitle files with a comma in the parameter. For example, subtitle=aHR0cDovL2VuY29kZS5jaGFodW8uY29tLw,aHR0cDovL2VuY29kZS5jaGFodW8uY29tLw.
subtitleType No How subtitles are added to a video:
1 - Subtitles are soft-coded, meaning they can be toggled on or off by the viewer.
2 - Subtitles are hard-coded and thus permanently embedded into the video, making them unremovable.
0(Default) - The system autonomously chooses whether to soft-code or hard-code the subtitles based on its automated recognition system.
subtitleAttr No To add attributes to subtitles, it is only applicable when the output is in adaptive bitrate m3u8 format and the subtitles are softcoded. Individual attributes should be separated by commas and encoded using URL-safe Base64. The format is: subtitleAttr=base64_encode(lang=xx1,name=yy1), where lang represents the subtitle language attribute and name is the subtitle name.
When adding multiple subtitles, you can incorporate multiple subtitle attributes simultaneously, separated by commas. The format is as follows:
subtitleAttr=base64_encode(lang=xx1,name=yy1),base64_encode(lang=xx2,name=yy2),...
Important: For successful integration, make sure the number of subtitleAttr values aligns perfectly with the number of subtitle files available. Any discrepancy will lead to unsuccessful subtitle addition.
saveas No This parameter defines the output location and filename as a URL-safe Base64-encoded string with the pseudocode Urlsafe_Base64_Encode(bucket:savedfilename).

Request Example

This example demonstrates the addition of subtitles to the test.flv video file in the bucket named vod-wcs-test001. The subtitles are sourced from the same bucket, from a file called zimu.srt. After the subtitles are added, the video is converted into MP4 format and then stored in the vod-wcs-test001 bucket, under the name test_file.mp4.

Pseudocode format for the request:

curl -v -X POST 
–d "bucket=Urlsafe_Base64_Encode(vod-wcs-test001)&key=Urlsafe_Base64_Encode(test.flv)&fops=Urlsafe_Base64_Encode(avthumb/mp4/subtitle/Urlsafe_Base64_Encode(vod-wcs-test001:zimu.srt)|saveas/Urlsafe_Base64_Encode(vod-wcs-test001:test_file.mp4))&force=1&separate=1" 
–H "Authorization:AccessKey:EncodeSign" 
--url "http://mgrDomain/fops"

Actual request format:

-curl -v -X POST 
-d "bucket=dm9kLXdjcy10ZXN0MDAx&key=dGVzdC5mbHY=&fops=YXZ0aHVtYi9tcDQvc3VidGl0bGUvZG05a0xYZGpjeTEwWlhOME1EQXhPbnBwYlhVdWMzSjBDZz09fHNhdmVhcy9kbTlrTFhkamN5MTBaWE4wTURBeE9uUmxjM1JmWm1sc1pTNXRjRFFLQ2c9PQ==&force=1&separate=1"
-H "Authorization:AccessKey:EncodeSign" 
--url "http://mgrDomain/fops"
Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!