Thumbnail-Job缩略图任务
更新时间:2022-09-22
缩略图是图片、视频经压缩方式处理后的小图。因其小巧,加载速度非常快,故用于快速浏览。缩略图任务可用于为BOS中的多媒体资源创建缩略图。
创建Thumbnail Job
通过pipeline,BOS Key以及其他配置信息为指定媒体生成缩略图,并获取返回的缩略图任务jobId。可以参考如下代码:
public void createThumbnailJob(MediaClient client, String pipelineName, String sourceKey) {
ThumbnailTarget target = new ThumbnailTarget().withFormat("jpg").withSizingPolicy("keep");
ThumbnailCapture capture =
new ThumbnailCapture().withMode("manual")
.withStartTimeInSecondDouble(0.0D)
.withEndTimeInSecondDouble(5.0D)
.withIntervalInSecondDouble(1.0D);
String jobId =
mediaClient.createThumbnailJob(pipelineName, sourceKey, target, capture).getJobId();
}
创建去水印、去黑边的缩略图,可以参考如下代码:
public void createThumbnailJob(MediaClient client, String pipelineName, String sourceKey, Area delogoArea,
Area crop) {
ThumbnailTarget target = new ThumbnailTarget().withFormat("gif").withSizingPolicy("keep");
ThumbnailCapture capture =
new ThumbnailCapture().withMode("split").withFrameNumber(10);
String jobId =
mediaClient.createThumbnailJob(pipelineName, sourceKey, target, capture, delogoArea, crop).getJobId();
}
查询指定Thumbnail Job
如果需要获取一个已创建的缩略图任务的信息,可以参考如下代码:
public void getThumbnailJob(MediaClient client, String jobId) {
GetThumbnailJobResponse resp = mediaClient.getThumbnailJob(jobId);
System.out.println(" jobId = " + resp.getJobId());
System.out.println(" pipelineName = " + resp.getPipelineName());
System.out.println(" jobStatus = " + resp.getJobStatus());
System.out.println(" source.key = " + resp.getSource().getKey());
System.out.println(" target.keyPrefix = " + resp.getTarget().getKeyPrefix());
System.out.println(" target.format = " + resp.getTarget().getFormat());
System.out.println(" target.sizingPolicy = " + resp.getTarget().getSizingPolicy());
System.out.println(" target.heightInPixel = " + resp.getTarget().getHeightInPixel());
System.out.println(" target.widthInPixel = " + resp.getTarget().getWidthInPixel());
System.out.println(" target.keys = " + resp.getTarget().getKeys());
System.out.println(" capture.mode = " + resp.getCapture().getMode());
System.out.println(" capture.startTimeInSecond = " + resp.getCapture().getStartTimeInSecond());
System.out.println(" capture.endTimeInSecond = " + resp.getCapture().getEndTimeInSecond());
System.out.println(" capture.intervalInSecond = " + resp.getCapture().getIntervalInSecond());
System.out.println(" capture.frameNumber = " + resp.getCapture().getFrameNumber());
}
查询指定队列的Thumbnail Jobs
如果需要获取一个队列里的全部缩略图任务的信息,可以参考如下代码:
public void listThumbnailJobs(MediaClient client, String pipelineName) {
ListThumbnailJobsResponse resp = mediaClient.listThumbnailJobs(pipelineName);
for (ThumbnailJobStatus job : resp.getThumbnails()) {
System.out.println(" jobId = " + job.getJobId());
System.out.println(" pipelineName = " + job.getPipelineName());
System.out.println(" jobStatus = " + job.getJobStatus());
System.out.println(" source.key = " + job.getSource().getKey());
System.out.println(" target.keyPrefix = " + job.getTarget().getKeyPrefix());
System.out.println(" target.format = " + job.getTarget().getFormat());
System.out.println(" target.sizingPolicy = " + job.getTarget().getSizingPolicy());
System.out.println(" target.heightInPixel = " + job.getTarget().getHeightInPixel());
System.out.println(" target.widthInPixel = " + job.getTarget().getWidthInPixel());
System.out.println(" target.keys = " + job.getTarget().getKeys());
System.out.println(" capture.mode = " + job.getCapture().getMode());
System.out.println(" capture.startTimeInSecond = " + job.getCapture().getStartTimeInSecond());
System.out.println(" capture.endTimeInSecond = " + job.getCapture().getEndTimeInSecond());
System.out.println(" capture.IntervalInSecond = " + job.getCapture().getIntervalInSecond());
System.out.println();
}
}