开发者指南
视频审核
VCR 支持对BOS视频、VOD媒资、URL视频审核。对于不同来源的视频,需要按照如下规则拼接视频路径source
:
- 对于 BOS 视频,
source=bos://{bucket}/{object}
- 对于 VOD 媒资原视频,
source=vod://{mediaId}
- 对于 VOD 媒资转码后视频,
source="vod://<vod-media-id>-<preset>"
- 对于 URL 视频,
source="<http(s)-url">
发起视频审核
指定视频路径发起视频审核。
审核 BOS 视频
根据BOS bucket和BOS key直接发起审核。需要说明,使用本方法需要将object配置公共GetObject权限,参考设置BOS bucket权限。简述为:在BOS 的控制台中 Bucket 设置-权限设置-自定义权限中添加 VCR 服务账号: fa5f9a177f54454b9076a57c6280f61b。
代码示例:
1public void putBosMedia(VcrClient vcrClient, String bucket, String object) {
2 vcrClient.putMedia("bos://" + bucket + "/" + object);
3}
审核 VOD 媒资原视频
根据 VOD 媒资ID直接发起审核。
代码示例:
1public void putVodMedia(VcrClient vcrClient, String mediaId) {
2 vcrClient.putMedia("vod://" + mediaId);
3}
审核 VOD 媒资转码后视频
根据 VOD 媒资ID和 VOD 转码模板名称发起审核。
代码示例:
1public void putVodMedia(VcrClient vcrClient, String mediaId, String preset) {
2 // preset is vod preset
3 vcrClient.putMedia("vod://" + mediaId + "-" + preset);
4}
审核 URL 视频
根据视频 URL 直接发起审核。
代码示例:
1public void putUrlMedia(VcrClient vcrClient, String url) {
2 vcrClient.putMedia(url);
3}
审核视频配置审核模板等参数
提交视频时可以配置视频描述、审核模板和通知名称等可选参数。
代码示例:
1public void putMedia(VcrClient vcrClient, String source, String preset, String notification) {
2 PutMediaRequest request = new PutMediaRequest();
3 request.setSource(source);
4 request.setDescription("this is a test media");
5 // preset is vcr preset
6 request.setPreset(preset);
7 request.setNotification(notification);
8 vcrClient.putMedia(request);
9}
说明:
审核包含鉴权参数的 URL 视频,将
PutMediaRequest
中auth
成员设置为鉴权参数即可。
查询视频审核结果
指定视频路径查询视频的审核结果。
代码示例:
1public void getMedia(VcrClient vcrClient, String source) {
2 GetMediaResponse response = vcrClient.getMedia(source);
3 String status = response.getStatus();
4 String label = response.getLabel();
5 for (CheckResult result : response.getResults()) {
6 String type = result.getType();
7 for (ResultItem item : result.getItems()) {
8 String target = item.getTarget();
9 Integer timeInSeconds = item.getTimeInSeconds();
10 String label = item.getLabel();
11 Double confidence = item.getConfidence();
12 String extra = item.getExtra();
13 String subType = item.getSubType();
14 Evidence evidence = item.getEvidence();
15 }
16 }
17}
说明:
- 视频审核结果格式和各字段含义参考VCR API。
- 对于包含鉴权参数的 URL 视频,在查询审核结果时,无需使用鉴权参数。
直播审核
发起直播审核
提交直播流审核时需要配置直播流地址、审核模板和通知名称等参数。 代码示例
1public void putStream(VcrClient vcrClient, String source, String preset, String notification) {
2 PutStreamRequest request = new PutStreamRequest();
3 request.setSource(source);
4 request.setPreset(preset);
5 request.setDescription("this is a test stream");
6 request.setNotification(notification);
7 PutStreamResponse response = vcrClient.putStreamV2(request);
8}
取消直播流审核
取消直播流审核时,需要配置直播流地址和回调地址参数
1public void cancelStream(VcrClient vcrClient, String source, String notification) {
2 CancelStreamRequest request = new CancelStreamRequest();
3 request.setSource(source);
4 request.setNotification(notification);
5 CancelStreamResponse response = vcrClient.cancelStreamV2(request);
6}
获取直播流审核结果
通过直播流地址获取审核结果
1public void getStream(VcrClient vcrClient, String source) {
2 GetStreamRequest request = new GetStreamRequest();
3 request.setSource(source);
4 GetStreamResponse response = vcrClient.getStreamV2(request);
5}
获取直播流审核任务列表
1public void getStreamCheckTaskList(VcrClient vcrClient, Integer maxKeys, String marker, String status) {
2 GetStreamCheckTaskListRequest request = new GetStreamCheckTaskListRequest();
3 request.setMaxKeys(maxKeys);
4 request.setMarker(marker);
5 request.setStatus(status);
6 GetStreamCheckTaskListResponse response = vcrClient.getStreamCheckTaskListV2(request);
7}
音频审核
发起音频审核
审核音频配置审核模板等参数
提交音频时可以配置音频描述、审核模板和通知名称等可选参数。
代码示例:
1public void putAudio(VcrClient vcrClient, String source, String preset, String notification) {
2 PutAudioRequest request = new PutAudioRequest();
3 request.setSource(source);
4 request.setDescription("this is a test audio");
5 // preset is vcr preset
6 request.setPreset(preset);
7 request.setNotification(notification);
8 vcrClient.putAudio(request);
9}
说明:
审核包含鉴权参数的 URL 音频,将
PutAudioRequest
中auth
成员设置为鉴权参数即可。
查询音频审核结果
指定音频路径查询音频的审核结果。
代码示例:
1public void getAudio(VcrClient vcrClient, String source) {
2 GetAudioResponse response = vcrClient.getAudio(source);
3 String status = response.getStatus();
4 String label = response.getLabel();
5 for (CheckResult result : response.getResults()) {
6 String type = result.getType();
7 for (ResultItem item : result.getItems()) {
8 String target = item.getTarget();
9 Integer timeInSeconds = item.getTimeInSeconds();
10 String label = item.getLabel();
11 Double confidence = item.getConfidence();
12 String extra = item.getExtra();
13 String subType = item.getSubType();
14 Evidence evidence = item.getEvidence();
15 }
16 }
17}
说明:
- 音频审核结果格式和各字段含义参考VCR API。
- 对于包含鉴权参数的 URL 音频,在查询审核结果时,无需使用鉴权参数。
图片审核
VCR支持 BOS 图片、HTTP图片审核。对于不同来源的图片,需要按照如下规则拼接图片路径source
:
- 对于BOS图片,
source=bos://{bucket}/{object}
- 对于HTTP图片,
source={url}
图片同步审核
图片同步审核,审核结果在HTTP Response中返回。
代码示例:
1public void putImage(VcrClient vcrClient, String source) {
2 PutImageResponse response = vcrClient.putImage(source);
3 String label = response.getLabel();
4 for (CheckResult result : response.getResults()) {
5 String type = result.getType();
6 for (ResultItem item : result.getItems()) {
7 String target = item.getTarget();
8 String label = item.getLabel();
9 Double confidence = item.getConfidence();
10 String extra = item.getExtra();
11 String subType = item.getSubType();
12 Evidence evidence = item.getEvidence();
13 }
14 }
15}
图片指定模板审核。
代码示例:
1public void putImage(VcrClient vcrClient, PutImageRequest request) {
2 PutImageResponse response = vcrClient.putImage(request);
3 String label = response.getLabel();
4 for (CheckResult result : response.getResults()) {
5 String type = result.getType();
6 for (ResultItem item : result.getItems()) {
7 String target = item.getTarget();
8 String label = item.getLabel();
9 Double confidence = item.getConfidence();
10 String extra = item.getExtra();
11 String subType = item.getSubType();
12 Evidence evidence = item.getEvidence();
13 }
14 }
15}
图片异步审核
图片异步审核,支持GIF图片(帧数不能超过100张)审核,审核结果通过通知服务进行回调。
代码示例:
1public void putImageAsync(VcrClient vcrClient, String source, String preset, String notification) {
2 PutImageAsyncResponse response = vcrClient.putImageAsync(source, preset, notification);
3}
图片异步审核查询
图片异步审核结果查询,结果保存时间10分钟。
代码示例:
1public void getImageAsync(VcrClient vcrClient, String source, String preset) {
2 GetImageAsyncResponse response = vcrClient.getImageAsync(source, preset);
3 String label = response.getLabel();
4 String status = response.getStatus();
5 for (CheckResult result : response.getResults()) {
6 String type = result.getType();
7 for (ResultItem item : result.getItems()) {
8 String target = item.getTarget();
9 String label = item.getLabel();
10 Double confidence = item.getConfidence();
11 String extra = item.getExtra();
12 String subType = item.getSubType();
13 Evidence evidence = item.getEvidence();
14 }
15 }
16 }
图片审核结果格式和各字段含义参考VCR API。
文本审核
对文本进行审核。
代码示例:
1public void putText(VcrClient vcrClient, String text) {
2 PutTextResponse response = vcrClient.putText(text);
3 String label = response.getLabel();
4 for (CheckResult result : response.getResults()) {
5 String type = result.getType();
6 for (ResultItem item : result.getItems()) {
7 String label = item.getLabel();
8 Double confidence = item.getConfidence();
9 String subType = item.getSubType();
10 String extra = item.getExtra();
11 }
12 }
13}
文本指定模板审核。
代码示例:
1public void putText(VcrClient vcrClient, PutTextRequest request) {
2 PutTextResponse response = vcrClient.putText(request);
3 String label = response.getLabel();
4 for (CheckResult result : response.getResults()) {
5 String type = result.getType();
6 for (ResultItem item : result.getItems()) {
7 String label = item.getLabel();
8 Double confidence = item.getConfidence();
9 String subType = item.getSubType();
10 String extra = item.getExtra();
11 }
12 }
13}
文本审核结果格式和各字段含义参考VCR API。
自定义face库
face库集素材添加
添加库集图片。
代码示例:
1public void addFaceImage(VcrClient vcrClient, String lib, String brief, String image) {
2 vcrClient.addFaceImage(lib, brief, image);
3}
face库集素材删除
删除指定的face库集素材,需指定face库集名称。
代码示例:
1public void delFaceImage(VcrClient vcrClient, String lib, String brief, String image) {
2 vcrClient.delFaceImage(lib, brief, image);
3}
face库集素材列表
根据face库集名称查询face库集素材列表。
代码示例:
1public void getFaceBrief(VcrClient vcrClient, String lib, String brief) {
2 LibImageResponse response = vcrClient.getFaceBrief(lib, brief);
3 for (String image : response.getImages()) {
4 String imageUrl = image;
5 }
6}
face库集删除
根据face库集名称删除face库集。
代码示例:
1public void delFaceBrief(VcrClient vcrClient, String lib, String brief) {
2 vcrClient.delFaceBrief(lib, brief);
3}
face库列表查询
根据face库名查询库集合。
代码示例:
1public void getFaceLib(VcrClient vcrClient, String lib) {
2 LibBriefResponse response = vcrClient.getFaceLib(lib);
3 for (String brief : response.getBriefs()) {
4 String briefName = brief;
5 }
6}
文本审核结果格式和各字段含义参考VCR API。
自定义logo库
logo库集素材添加
添加库集图片。
代码示例:
1public void addLogoImage(VcrClient vcrClient, String lib, String brief, String image) {
2 vcrClient.addLogoImage(lib, brief, image);
3}
logo库集素材删除
删除指定的logo库集素材。
代码示例:
1public void delLogoImage(VcrClient vcrClient, String lib, String image) {
2 vcrClient.delLogoImage(lib, image);
3}
logo库集素材列表
根据logo库集名称查询logo库集素材列表。
代码示例:
1public void getLogoBrief(VcrClient vcrClient, String lib, String brief) {
2 LibImageResponse response = vcrClient.getLogoBrief(lib, brief);
3 for (String image : response.getImages()) {
4 String imageUrl = image;
5 }
6}
logo库集删除
删除指定的logo库集。
代码示例:
1public void delLogoBrief(VcrClient vcrClient, String lib, String brief) {
2 vcrClient.delLogoBrief(lib, brief);
3}
logo库列表查询
根据logo库名查询库集合。
代码示例:
1public void getLogoLib(VcrClient vcrClient, String lib) {
2 LibBriefResponse response = vcrClient.getLogoLib(lib);
3 for (String brief : response.getBriefs()) {
4 String briefName = brief;
5 }
6}
文本审核结果格式和各字段含义参考VCR API。
日志
VCR Java SDK发布版本中增加了logback作为slf4j
的实现,开发者可以直接使用。如果工程中有其他框架实现,例如log4j
,也可以用来替代logback。
默认日志
如果使用默认的logback,需要配置logback.xml到classpath中。不做配置时,日志级别默认为DEBUG。
1 <configuration>
2 <property name="LOG_HOME" value="./log/"/>
3 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4 <!-- encoders are assigned the type
5 ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
6 <encoder>
7 <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
8 </encoder>
9 </appender>
10 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
11 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
12 <FileNamePattern>${LOG_HOME}/VCRUnitTest.%d{yyyy-MM-dd}.log</FileNamePattern>
13 <MaxHistory>30</MaxHistory>
14 </rollingPolicy>
15 <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
16 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
17 </encoder>
18 <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
19 <MaxFileSize>10MB</MaxFileSize>
20 </triggeringPolicy>
21 </appender>
22
23 <root level="info">
24 <appender-ref ref="STDOUT"/>
25 <appender-ref ref="FILE"/>
26 </root>
27 </configuration>
自有日志模块
如果使用自己的日志实现模块,例如项目依赖于Maven,则可以参考下面的配置到pom.xml中来去除logback。
1<?xml version="1.0" encoding="utf-8"?>
2
3<dependency>
4 <groupId>com.baidubce</groupId>
5 <artifactId>bce-java-sdk</artifactId>
6 <version>${bce.sdk.version}</version>
7 <exclusions>
8 <exclusion>
9 <groupId>ch.qos.logback</groupId>
10 <artifactId>logback-classic</artifactId>
11 </exclusion>
12 <exclusion>
13 <artifactId>logback-core</artifactId>
14 <groupId>ch.qos.logback</groupId>
15 </exclusion>
16 <exclusion>
17 <groupId>org.slf4j</groupId>
18 <artifactId>jcl-over-slf4j</artifactId>
19 </exclusion>
20 </exclusions>
21</dependency>