Polyv Help Center

Help Center

subtitleService

Updated: 2026-03-09 16:11:55

1. Upload Subtitle File for VOD Video

Description

通过视频id上传点播视频字幕文件
接口地址(仅做说明使用):https://api.polyv.net/v2/video/%s/srt/upload

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.

Unit Test

    @Test
    public void testUploadSubtitle() throws IOException, NoSuchAlgorithmException {
        VodUploadSubtitleRequest vodUploadSubtitleRequest = new VodUploadSubtitleRequest();
        Boolean vodUploadSubtitleResponse = null;
        try {
            String srtCN = getClass().getResource("/subtitle/srt(zh_CN).srt").getPath();
            vodUploadSubtitleRequest.setVideoId("1b448be3234406608b7838c7ef6b597c_1")
                    .setFile(new File(srtCN))
                    .setAsDefault("N")
                    .setTitle("subtitle")
                    .setLanguage(null);
            vodUploadSubtitleResponse = new VodSubtitleServiceImpl().uploadSubtitle(vodUploadSubtitleRequest);
            Assert.assertTrue(vodUploadSubtitleResponse);
            if (vodUploadSubtitleResponse) {
                log.debug("测试上传点播视频字幕文件成功");
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a Boolean object is returned. The B-end uses this object to handle business logic.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Validation failed for input parameter [xxx.chat.VodxxxRequest], failed fields: [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Error returned by Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
videoId true String Video ID [Corresponds to the vid field in the API documentation]
title true String Subtitle name
file true File Subtitle file, supports UTF-8 encoding
asDefault false String Whether to set as default subtitle, Y: Yes, N: No. Default is N: No. The first uploaded subtitle is Y: Yes.
language false String Language, defaults to auto-detect. Supported languages: Chinese, Traditional Chinese, English, Japanese, Korean, French, German, Russian, Spanish, Arabic, Portuguese, Other

Return Object Description

true indicates successful upload, false indicates failed upload.




2. Query Video Subtitles

Description

通过视频id查询视频字幕
接口地址(仅做说明使用):https://api.polyv.net/v2/video/%s/srt/list

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.

Unit Test

    @Test
    public void testGetSubtitleList() throws IOException, NoSuchAlgorithmException {
        VodGetSubtitleListRequest vodGetSubtitleListRequest = new VodGetSubtitleListRequest();
        VodGetSubtitleListResponse vodGetSubtitleListResponse = null;
        try {
            vodGetSubtitleListRequest.setVideoId(super.getTestVideoId());
            vodGetSubtitleListResponse = new VodSubtitleServiceImpl().getSubtitleList(vodGetSubtitleListRequest);
            Assert.assertNotNull(vodGetSubtitleListResponse);
            if (vodGetSubtitleListResponse != null) {
                log.debug("测试查询视频字幕成功,{}", JSON.toJSONString(vodGetSubtitleListResponse));
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a VodGetSubtitleListResponse object is returned. The B-end uses this object to handle business logic.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Validation failed for input parameter [xxx.chat.VodxxxRequest], failed fields: [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Error returned by Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
videoId true String Video ID [Corresponds to the vid field in the API documentation]

Return Object Description

Parameter Name Type Description
subtitles Array Query result list [Corresponds to the srts field in the API documentation] [See Subtitle Parameter Description]
Subtitle Parameter Description
Parameter Name Type Description
rank Integer Sequence number, starting from 1
name String Subtitle name






3. Merge Subtitle Files

Description

通过视频id与字幕信息合并字幕文件
接口地址(仅做说明使用):https://api.polyv.net/v2/video/%s/srt/merge

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.

Unit Test

    @Test
    public void testMergeSubtitle() throws IOException, NoSuchAlgorithmException {
        VodMergeSubtitleRequest vodMergeSubtitleRequest = new VodMergeSubtitleRequest();
        Boolean vodMergeSubtitleResponse = null;
        try {
            String videoId = super.getTestVideoId();
            //准备测试数据
            String sourceSubtitleNames = super.getSourceSubtitleNames(videoId);
            vodMergeSubtitleRequest.setVideoId(videoId)
                    .setSourceSubtitleNames(sourceSubtitleNames)
                    .setMergedSubtitleName("双语")
                    .setSetAsDefault(Boolean.TRUE);
            vodMergeSubtitleResponse = new VodSubtitleServiceImpl().mergeSubtitle(vodMergeSubtitleRequest);
            Assert.assertTrue(vodMergeSubtitleResponse);
            if (vodMergeSubtitleResponse) {
                log.debug("测试合并字幕文件成功");
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a Boolean object is returned. The B-end uses this object to handle business logic.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Validation failed for input parameter [xxx.chat.VodxxxRequest], failed fields: [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Error returned by Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
videoId true String Video ID [Corresponds to the vid field in the API documentation]
sourceSubtitleNames true String Original subtitle names, must provide two values. Separated by commas. The content of the first subtitle appears at the top after merging. [Corresponds to the sourceSrtNames field in the API documentation]
mergedSubtitleName false String Name of the merged subtitle, default: Bilingual. Maximum 5 Chinese characters. [Corresponds to the mergedSrtName field in the API documentation]
setAsDefault false Boolean Whether to set as the default displayed subtitle. Default value: true.

Return Object Description

true indicates successful subtitle file merge, false indicates failed merge.




4. Delete Video Subtitles

Description

通过视频id与字幕序号列表删除视频字幕
接口地址(仅做说明使用):https://api.polyv.net/v2/video/%s/srt/delete

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.

Unit Test

    @Test
    public void testDeleteSubtitle() throws IOException, NoSuchAlgorithmException {
        VodDeleteSubtitleRequest vodDeleteSubtitleRequest = new VodDeleteSubtitleRequest();
        Boolean vodDeleteSubtitleResponse = null;
        try {
            //准备测试数据
            String videoId = super.getTestVideoId();
            if (super.getSubtitleList(videoId).isEmpty()) {
                uploadSubtitle(videoId, false);
            }
            String ranks = getRanks(videoId);
            vodDeleteSubtitleRequest.setVideoId(videoId).setRanks(ranks);
            vodDeleteSubtitleResponse = new VodSubtitleServiceImpl().deleteSubtitle(vodDeleteSubtitleRequest);
            Assert.assertTrue(vodDeleteSubtitleResponse);
            if (vodDeleteSubtitleResponse) {
                log.debug("测试删除视频字幕成功");
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a Boolean object is returned. The B-end uses this object to handle business logic.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Validation failed for input parameter [xxx.chat.VodxxxRequest], failed fields: [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Error returned by Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
videoId true String Video ID [Corresponds to the vid field in the API documentation]
ranks true String List of subtitle sequence numbers, starting from 1. Multiple values separated by commas, e.g., 2,3

Return Object Description

true indicates successful subtitle deletion, false indicates failed deletion.




5. Create Smart Subtitle Task

Description

通过视频id创建智能字幕任务,为视频自动生成一份智能字幕文件
接口地址(仅做说明使用):https://api.polyv.net/vod/v4/smart-subtitle/create

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.
  2. Creating a smart subtitle task requires the VOD video to be published and its duration not to exceed the API limit. Refer to the API documentation for details.

Unit Test

    @Test
    public void testCreateSmartSubtitleTask() throws IOException, NoSuchAlgorithmException {
        VodSubtitleServiceImpl service = new VodSubtitleServiceImpl();
        String videoId = super.getTestVideoId();
        Long taskId = null;
        try {
            VodCreateSmartSubtitleTaskRequest createRequest = new VodCreateSmartSubtitleTaskRequest()
                    .setVid(videoId)
                    .setLanguage("chinese")
                    .setAutoApplyEnabled("N")
                    .setRepetitionEnabled("Y");
            taskId = service.createSmartSubtitleTask(createRequest);
            Assert.assertNotNull(taskId);
            log.debug("测试创建智能字幕任务成功, taskId={}", taskId);
        } catch (PloyvSdkException e) {
            log.error(e.getMessage(), e);
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a Long type subtitle task ID is returned. The B-end uses this ID for subsequent queries, updates, or publishing of smart subtitles.
  2. If request parameter validation fails, a PloyvSdkException is thrown.
  3. If the server encounters an error, a PloyvSdkException is thrown.

Request Parameter Description

Parameter Name Required Type Description
vid true String Video ID, corresponds to the vid field in the API documentation
autoApplyEnabled false String Whether to automatically apply the subtitle to the corresponding video after generation, Y or N. Default follows backend configuration.
language false String Language for intelligent recognition. Supported enum values are detailed in the API documentation. If not provided or an unsupported value is given, Chinese is used.
repetitionEnabled false String Whether to allow duplicate tasks, Y-Allow, N-Do not allow, default Y.

Return Object Description

Returns a Long type, representing the ID of the successfully created smart subtitle task.






6. Query Smart Subtitle Content

Description

通过字幕任务id,查询智能字幕的下载链接及逐条字幕内容
接口地址(仅做说明使用):https://api.polyv.net/vod/v4/smart-subtitle/get

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.
  2. Ensure the subtitle task has completed parsing. The API will return a corresponding error code if the task is incomplete.

Unit Test

    @Test
    public void testQuerySmartSubtitle() throws IOException, NoSuchAlgorithmException {
        VodSubtitleServiceImpl service = new VodSubtitleServiceImpl();
        // 这里依赖调用方预先准备好的有效 taskId
        Long taskId = 1L;
        try {
            VodQuerySmartSubtitleRequest queryRequest = new VodQuerySmartSubtitleRequest()
                    .setTaskId(taskId);
            VodQuerySmartSubtitleResponse queryResponse = service.querySmartSubtitle(queryRequest);
            Assert.assertNotNull(queryResponse);
            log.debug("测试查询智能字幕内容成功,{}", JSON.toJSONString(queryResponse));
        } catch (PloyvSdkException e) {
            log.error(e.getMessage(), e);
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a VodQuerySmartSubtitleResponse object is returned. The B-end handles business logic based on the link and subtitles fields in this object.
  2. If request parameter validation fails, a PloyvSdkException is thrown.
  3. If the server encounters an error, a PloyvSdkException is thrown.

Request Parameter Description

Parameter Name Required Type Description
taskId true Long Smart subtitle task ID, returned when creating the task.

Return Object Description

Parameter Name Type Description
taskId Long Smart subtitle task ID
link String Subtitle file download link
autoApplyEnabled String Whether to automatically apply the subtitle to the video after generation, Y/N
subtitleName String Subtitle title
preferenceEnabled String Whether it is the default preferred subtitle, Y/N
subtitles Array List of subtitle content, individual subtitle information

Where the subtitles element structure:

Parameter Name Type Description
start Long Start time of a single subtitle relative to video playback, in milliseconds
end Long End time of a single subtitle relative to video playback, in milliseconds
content String Content of a single subtitle






Description

通过视频id查询该视频关联的智能字幕任务及字幕链接列表
接口地址(仅做说明使用):https://api.polyv.net/vod/v4/smart-subtitle/subtitle-link/get

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.

Unit Test

    @Test
    public void testQuerySmartSubtitleLink() throws IOException, NoSuchAlgorithmException {
        VodSubtitleServiceImpl service = new VodSubtitleServiceImpl();
        String videoId = super.getTestVideoId();
        try {
            VodQuerySmartSubtitleLinkRequest linkRequest = new VodQuerySmartSubtitleLinkRequest()
                    .setVid(videoId);
            List<VodQuerySmartSubtitleLinkResponse> linkResponseList = service.querySmartSubtitleLink(linkRequest);
            Assert.assertNotNull(linkResponseList);
            log.debug("测试查询智能字幕链接成功,{}", JSON.toJSONString(linkResponseList));
        } catch (PloyvSdkException e) {
            log.error(e.getMessage(), e);
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a list of smart subtitle links is returned.
  2. A PloyvSdkException is thrown if request parameter validation fails or a server error occurs.

Request Parameter Description

Parameter Name Required Type Description
vid true String Video ID

Return Object Description

Returns List<VodQuerySmartSubtitleLinkResponse>, each element structure:

Parameter Name Type Description
taskId Long Smart subtitle task ID
link String Subtitle file download link
vid String Video ID






8. Update Smart Subtitle Content

Description

通过字幕任务id更新智能字幕内容,可用于人工校对后覆盖原有字幕
接口地址(仅做说明使用):https://api.polyv.net/vod/v4/smart-subtitle/update

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.
  2. The subtitle task must be in an updatable state. Specific restrictions are detailed in the API documentation.

Unit Test

    @Test
    public void testUpdateSmartSubtitle() throws IOException, NoSuchAlgorithmException {
        VodSubtitleServiceImpl service = new VodSubtitleServiceImpl();
        Long taskId = 1L;
        try {
            VodUpdateSmartSubtitleRequest.SubtitleItem item = new VodUpdateSmartSubtitleRequest.SubtitleItem()
                    .setStart(0L)
                    .setEnd(1000L)
                    .setContent("智能字幕测试");
            VodUpdateSmartSubtitleRequest updateRequest = new VodUpdateSmartSubtitleRequest()
                    .setTaskId(taskId)
                    .setSubtitleName("智能字幕测试")
                    .setAutoApplyEnabled("N")
                    .setPreferenceEnabled("Y")
                    .setSubtitles(Collections.singletonList(item));
            Boolean updateResult = service.updateSmartSubtitle(updateRequest);
            Assert.assertTrue(updateResult);
            log.debug("测试更新智能字幕内容成功");
        } catch (PloyvSdkException e) {
            log.error(e.getMessage(), e);
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a Boolean is returned. true indicates a successful update.
  2. A PloyvSdkException is thrown if request parameter validation fails or a server error occurs.

Request Parameter Description

Parameter Name Required Type Description
taskId true Long Smart subtitle task ID
autoApplyEnabled false String Whether to automatically publish the subtitle after modifying its content, Y/N. If not provided, the task's preset value is used.
subtitleName false String Subtitle title, maximum 20 characters.
preferenceEnabled false String Whether to default to this subtitle after publishing, Y/N. If not provided, the task's preset value is used.
subtitles true List List of subtitle content

subtitles element structure:

Parameter Name Required Type Description
start true Long Start time of a single subtitle, in milliseconds
end true Long End time of a single subtitle, in milliseconds
content true String Content of a single subtitle

Return Object Description

true indicates a successful update, false indicates a failed update.






9. Publish Smart Subtitle

Description

通过字幕任务id将智能字幕应用到视频上
接口地址(仅做说明使用):https://api.polyv.net/vod/v4/smart-subtitle/publish

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.
  2. Publishing is only possible when the task status allows it.

Unit Test

    @Test
    public void testPublishSmartSubtitleTask() throws IOException, NoSuchAlgorithmException {
        VodSubtitleServiceImpl service = new VodSubtitleServiceImpl();
        Long taskId = 1L;
        try {
            VodPublishSmartSubtitleTaskRequest publishRequest = new VodPublishSmartSubtitleTaskRequest()
                    .setTaskId(taskId)
                    .setPreferenceEnabled("Y");
            Boolean publishResult = service.publishSmartSubtitleTask(publishRequest);
            Assert.assertTrue(publishResult);
            log.debug("测试发布智能字幕成功");
        } catch (PloyvSdkException e) {
            log.error(e.getMessage(), e);
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a Boolean is returned. true indicates a successful publish.
  2. A PloyvSdkException is thrown if request parameter validation fails or a server error occurs.

Request Parameter Description

Parameter Name Required Type Description
taskId true Long Smart subtitle task ID
preferenceEnabled false String Whether to default to the current subtitle, Y/N. If not provided, the task's preset value is used.

Return Object Description

true indicates a successful publish, false indicates a failed publish.






10. Delete Smart Subtitle Task

Description

通过字幕任务id删除智能字幕任务及对应字幕文件
接口地址(仅做说明使用):https://api.polyv.net/vod/v4/smart-subtitle/delete

Call Constraints

  1. API calls are rate-limited. Click here for details. For common exceptions, click here.
  2. Deletion is only possible when the task status allows it.

Unit Test

    @Test
    public void testDeleteSmartSubtitleTask() throws IOException, NoSuchAlgorithmException {
        VodSubtitleServiceImpl service = new VodSubtitleServiceImpl();
        Long taskId = 1L;
        try {
            VodDeleteSmartSubtitleTaskRequest deleteRequest = new VodDeleteSmartSubtitleTaskRequest()
                    .setTaskId(taskId);
            Boolean deleteResult = service.deleteSmartSubtitleTask(deleteRequest);
            Assert.assertTrue(deleteResult);
            log.debug("测试删除智能字幕任务成功");
        } catch (PloyvSdkException e) {
            log.error(e.getMessage(), e);
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. On a successful request, a Boolean is returned. true indicates a successful deletion.
  2. A PloyvSdkException is thrown if request parameter validation fails or a server error occurs.

Request Parameter Description

Parameter Name Required Type Description
taskId true Long Smart subtitle task ID

Return Object Description

true indicates a successful deletion, false indicates a failed deletion.

联系客服,在线咨询