百度及腾讯活体验证视频压缩工具及java代码
标签:
•
文件类型: .zip
•
文件大小: 40.99MB
•
下载次数: 1
•
压缩包里面工具和代码可以压缩人脸识别的视频之后给百度和腾讯接口识别出结果,减少视频传输时间并不影响识别结果。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 63118848 2018-07-13 09:36 ffmpeg.exe
文件 6714 2018-08-15 09:59 FFmpegUtil.java
文件 63971848 2018-07-13 09:36 ffmpeg
package com.face.test;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
public class FFmpegUtil {
/**
*
* @param ffmpegPath ffmpeg压缩工具路径
* @param faceVideo 上传的视频
* @return
*/
public static byte[] FFmpeg(String ffmpegPath MultipartFile faceVideo){
byte[] byteVideo = null;
File oldFile = null newFile = null;
try {
String suffix = “mp4“;
String fileName = faceVideo.getOriginalFilename();
int index = fileName.lastIndexOf(“.“);
if(index > 0) {
suffix = fileName.substring(index);
}
oldFile = File.createTempFile(“oldVideo“ suffix);
faceVideo.transferTo(oldFile);
if (!oldFile.isFile()) {
return byteVideo;
}
String inputPath = oldFile.getPath();
newFile = File.createTempFile(“newVideo“ suffix);
String outputPath = newFile.getPath();
int type = checkContentType(inputPath);
List command = getFFmpegCommand(type ffmpegPath inputPath outputPath);
if (command.size() > 0) {
boolean result = process(command);
if(result) {
byteVideo = getBytes(outputPath);
}
}
}
catch (Exception e){
e.printStackTrace();
}
finally {
if(oldFile != null) {
oldFile.deleteOnExit();
}
if(newFile != null) {
newFile.deleteOnExit();
}
}
return byteVideo;
}
private static int checkContentType(String inputPath) {
String type = inputPath.substring(inputPath.lastIndexOf(“.“) + 1 inputPath.length()).toLowerCase();
// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
if (type.equals(“avi“)) {
return 1;
} else if (type.equals(“mpg“)) {
return 1;
} else if (type.equals(“wmv“)) {
return 1;
} else if (type.equals(“3gp“)) {
return 1;
} else if (type.equals(“mov“)) {
return 1;
} else if (type.equals(“mp4“)) {
return 1;
} else if (type.equals(“mkv“)) {
return 1;
} else if (type.equals(“asf“)) {
return 0;
} else if (type.equals(“flv“)) {
return 0;
} else if (type.equals(“rm“)) {
return 0;
} else if (type.equals(“rmvb“)) {
return 1;
}
return 9;
}
private static boolean process(List command) throws Exception {
try {
Process videoProcess = new ProcessBuilder(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 63118848 2018-07-13 09:36 ffmpeg.exe
文件 6714 2018-08-15 09:59 FFmpegUtil.java
文件 63971848 2018-07-13 09:36 ffmpeg
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)