除了可以使用我们提供的http接口之外,也可以直接通过java代码来构建任务、发送任务、查询任务。只需要导入我们的内部的jar包就可以
添加maven依赖
pom.xml 中添加依赖,其中的版本号可能会有变动
xml
<dependency>
<groupId>com.meishesdk</groupId>
<artifactId>cloudCompilesdk</artifactId>
<version>1.1.22</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/cloudCompileSdk-1.1.22-jar-with-dependencies.jar</systemPath>
</dependency>
编写java代码
以下只是一个简单的代码示例,主要是为了说明通过java代码的调用流程,并不能直接调用。如果有不明白或者不理解的地方,可以将具体的需求反馈出来,我们再提供对应的代码示例。
java
package com.meishesdk.cloudcompilesdk.samples;
import java.util.concurrent.TimeUnit;
import com.meishesdk.cloudcompilesdk.models.xml.timeline.Caption;
import com.meishesdk.cloudcompilesdk.models.xml.timeline.CaptionTrack;
import com.meishesdk.cloudcompilesdk.models.xml.timeline.TimelineDom;
import com.meishesdk.cloudcompilesdk.models.xml.timeline.Video;
import com.meishesdk.cloudcompilesdk.models.xml.timeline.VideoFx;
import com.meishesdk.cloudcompilesdk.models.xml.timeline.VideoTrack;
import com.meishesdk.cloudcompilesdk.task.CompileData;
import com.meishesdk.cloudcompilesdk.task.TaskClient;
import com.meishesdk.cloudcompilesdk.task.TaskInfo;
import com.meishesdk.cloudcompilesdk.task.TaskStateEnum;
import com.meishesdk.cloudcompilesdk.utils.Result;
public class TimelineSample {
public static void main(String[] args) throws Exception {
// 构建任务
TimelineDom dom = new TimelineDom();
// 设置导出的视频参数
dom.setResWidth(1080);
dom.setResHeight(1920);
dom.setDuration(4000000L);
dom.setOutputType("mp4");
dom.setNvenc(true);
// 创建视频轨
VideoTrack videoTrack = new VideoTrack();
dom.appendVideoTrack(videoTrack);
// 添加要使用的视频素材
Video video = new Video();
video.setPath("http://wslfile/demo.mp4");
// 将该视频的6-10秒添加到视频轨的0-4秒的位置上
video.setInPoint(0L);
video.setOutPoint(4000000L);
video.setTrimIn(6000000L);
video.setTrimOut(10000000L);
videoTrack.appendVideo(video);
// 给视频片段添加特效
VideoFx videoFx = new VideoFx();
videoFx.setType("property");
videoFx.setIntensity(1.0);
// 背景模糊
videoFx.appendFxParam("float", "Background Blur Radius", "50")
.appendFxParam("menu", "Background Mode", "Blur");
video.appendVideoFx(videoFx);
// 添加字幕轨
CaptionTrack captionTrack = new CaptionTrack();
dom.appendCaptionTrack(captionTrack);
Caption caption = new Caption();
caption.setType("general");
caption.setText("hello world");
caption.setFontSizeRatio(0.07);
caption.setInPoint(100000L);// 从第1秒开始出现
caption.setDuration(3000000L); // 持续3秒
captionTrack.appendCaption(caption);
// 发起任务
TaskClient client = TaskClient.instanceOf("http://localhost:9999");
String taskId = client.createTimelineCompileTask(dom);
System.out.println(taskId);
while (true) {
TimeUnit.SECONDS.sleep(1);
// 查询任务
TaskInfo taskInfo = client.taskInfo(taskId);
if (TaskStateEnum.FINISH.name().equalsIgnoreCase(taskInfo.getExecuteState())) {
if (Result.SUCCESS == taskInfo.getExecuteResultCode()) {
CompileData compileData = taskInfo.getCompileData();
System.out.println(taskId + " compile success,url is " + compileData.getUrl());
} else {
System.out.println(taskId + " compile error,msg is " + taskInfo.getExecuteResultMsg());
}
break;
} else if (TaskStateEnum.WORK.name().equalsIgnoreCase(taskInfo.getExecuteState())) {
System.out.println(taskId + " compile progress " + taskInfo.getTaskProgress());
}
}
System.exit(0);
}
}