java 获取视频时间
//先将视频保存到项目生成临时文件,获取时长后删除临时文件
// 使用fastdfs进行文件上传
@RequestMapping("/uploadVideoToFast")
@ResponseBody
public Map<String, Object> uploadVideoToFast(@RequestParam("file") MultipartFile file)
throws IOException, InterruptedException {
File toFile = null; InputStream ins = null;
ins = file.getInputStream();
toFile = new File(file.getOriginalFilename());
inputStreamToFile(ins, toFile);
ins.close(); String length = ReadVideoTime(toFile);
Map<String, Object> url = UploadVideoDemo.testUploadStream(accessKeyId, accessKeySecret, "视频",
file.getOriginalFilename(), file.getInputStream());
url.put("length", length);
return url;
} private String ReadVideoTime(File source) throws InterruptedException {
Encoder encoder = new Encoder();
String length = "";
try {
MultimediaInfo m = encoder.getInfo(source);
long ls = m.getDuration() / ;
int hour = (int) (ls / );
int minute = (int) (ls % ) / ;
int second = (int) (ls - hour * - minute * );
length = hour + ":" + minute + ":" + second;
} catch (Exception e) {
e.printStackTrace();
}
Thread.sleep();
System.out.println(source.getAbsolutePath());
System.out.println(source.getPath());
System.out.println(length);
System.out.println(source.delete());
return length;
} public static void inputStreamToFile(InputStream ins, File file) {
try {
OutputStream os = new FileOutputStream(file);
int bytesRead = ;
byte[] buffer = new byte[];
while ((bytesRead = ins.read(buffer, , )) != -) {
os.write(buffer, , bytesRead);
}
os.close();
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
}
java 获取视频时间的更多相关文章
- java获取视频播第一帧
FFMPEG 功能很强大,做视频必备的软件.大家可通过 http://ffmpeg.org/ 了解.Windows版本的软件,可通过 http://ffmpeg.zeranoe.com/builds/ ...
- java学习第13天( java获取当前时间,有关大数据的运算及精确数字运算,Date类)
一 java获取当前时间 学习一个函数,得到当前时间的准确值 System.currectTimeMillis(). 可以得到以毫秒为单位的当前时间.它主要用于计算程序运行时间,long start= ...
- java获取前一天时间SimpleDateFormat,java判断某个时间段
java获取前一天时间SimpleDateFormat SimpleDateFormat predf = new SimpleDateFormat("yyyy-MM-dd"); D ...
- Java获取系统时间少了八个小时
Java获取系统时间少了八个小时 今天忽然遇到需要获取当前时间的问题,我向来谨慎,先测试获取到的系统时间是否正确,结果竟然发现少了八个小时,晕死了,记得之前在页面用javascript获取过当前时间, ...
- java 获取当前时间,前一天时间
java获取当前时间,并按一定格式输出 1.用Calendar获取Date Calendar calendar=Calendar.getInstance(); SimpleDateFormat for ...
- java 显示视频时间--玩的
1.显示视频时间 package view.time; import it.sauronsoftware.jave.Encoder; import it.sauronsoftware.jave.Mul ...
- android java获取当前时间的总结
import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat (&q ...
- java获取当前日期时间代码总结
1.获取当前时间,和某个时间进行比较.此时主要拿long型的时间值. 方法如下: 要使用 java.util.Date .获取当前时间的代码如下 代码如下 复制代码 Date date = new ...
- Java获取指定时间的毫秒值的方法
有以下两种方法获取指定时间的毫秒值: 1.Calendar类 先由getInstance获取Calendar对象,然后用clear方法将时间重置为(1970.1.1 00:00:00),接下来用set ...
随机推荐
- Ruby on Rails 的模型 validates 验证
validate(), 这个方法在每次保存数据时都会被调用.如:def validate if name.blank? && email.blank? errors.add_to_b ...
- WPF Win32 API 嵌入Form 窗体
WIn32 API: public class Win32Native { [DllImport("user32.dll", SetLastError = true, CharSe ...
- GBK格式字符串右补空格
public class Test2 { public static void main(String[] s) throws IOException { List<User> l ...
- nodeslector使用
问题: node节点挂了一个, 无法切换到另一个node上 解决: .指定了 nodeslector .设置了下面: hostNetwork: true dnsPolicy: ClusterFirst ...
- Springboot--关于使用webapp目录
前我在学习springBoot集成springMVC的时候发现webapp目录, 1. 直接右键运行,访问不到页面,原来并不是不支持啊,只是默认没有把它放在编译路径里面. 我们可以在项目的packag ...
- Postman配置环境变量添加token
postman测试接口时,每次都需要获取token以后,复制到接口里,特别复杂. 这里通过把获取token接口的返回数据添加到环境变量,然后将环境变量名设置在其他接口的token中,获取一次token ...
- list-style-type:none是加在ul还是li中呢?
很多时候我们都需要多对列表元素进行初始化,方法是给列表元素添加list-style-type: none,但作为小白的我是经常纠结一个问题:是把它加在ul中还是li中呢 我试了一下,加在ul和li都能 ...
- readline安装
wget -c ftp://ftp.gnu.org/gnu/readline/readline-6.2.tar.gz tar -zxvf readline-6.2.tar.gz cd readline ...
- poj2299(归并排序求逆序对)
题目链接:https://vjudge.net/problem/POJ-2299 题意:给定一个序列,每次只能交换邻近的两个元素,问要交换多少次才能使序列按升序排列. 思路:本质就是求逆序对.我们用归 ...
- [bzoj3887][Usaco2015 Jan]Grass Cownoisseur_trajan_拓扑排序_拓扑序dp
[Usaco2015 Jan]Grass Cownoisseur 题目大意:给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过?(一个点在 ...