java实现截取视频方法
添加依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
1、代码
package org.dser;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
public class TestCutView {
public static void main(String[] args) {
clipVideo("/data/video/user.mp4","/data/video/test.mp4","00:01:30","00:02:30","192.168.18.155","9090");
}
/**
* 截取视频
* 范例:http://192.168.188.125:8080/clipVideo?src_video=q.mp4&dst_video=2.mp4&start_time=00:01:30&end_time=00:02:30
* @param videoPathName 原始视频路径包含文件名
* @param alarmVideo 截取后视频存放路径包含文件名
* @param startDate 开始截取时间
* @param stopDate 截取至时间
* @param mediaServerIp 服务器ip
* @param mediaServerHttpPort 服务器端口
* @return
*/
public static int clipVideo(String videoPathName, String alarmVideo, String startDate, String stopDate,String mediaServerIp,String mediaServerHttpPort) {
try {
String clipVideoUrl = "http://" + mediaServerIp + ":" + mediaServerHttpPort + "/" +
"clipVideo?src_video=" + videoPathName + "&dst_video=" + alarmVideo + "&start_time=" + startDate + "&end_time=" + stopDate;
System.out.println("clipVideo cut alarm video url :" + clipVideoUrl);
RestTemplate client = new RestTemplate();
String clipResult = client.getForEntity(clipVideoUrl, String.class).getBody();
System.out.println("clipVideo result:" + clipResult);
return 0;
}catch (RestClientException e) {
System.out.println("cutAlarmVideo err e:" + e.getMessage());
throw new RestClientException("clipVideo 报错",e);
}
}
}