|
@@ -77,7 +77,9 @@ public class VideoUtil {
|
|
|
if(!tagFile.exists()){
|
|
|
tagFile.mkdirs();
|
|
|
}
|
|
|
- String fileName = UUID.randomUUID().toString().replace("-","")+".mp4";
|
|
|
+ String fame = UUID.randomUUID().toString().replace("-","");
|
|
|
+ String fileName = fame+".mp4";
|
|
|
+ String imgName = fame+".jpg";
|
|
|
try {
|
|
|
List<String> voidTS = new ArrayList<>();
|
|
|
|
|
@@ -85,7 +87,7 @@ public class VideoUtil {
|
|
|
String format = "%s -y -i %s -vcodec copy -bsf:v h264_mp4toannexb -f mpegts %s";
|
|
|
String name = UUID.randomUUID().toString().replace("-","");
|
|
|
String command = String.format(format, "ffmpeg", fromVideoFile, newVideoFile +"/"+name + ".ts");
|
|
|
- CreateObjUtil.callshell(command);
|
|
|
+ ShellUtil.execCmd(command);
|
|
|
voidTS.add(newVideoFile +"/"+name + ".ts");
|
|
|
}
|
|
|
StringBuilder tsPath = new StringBuilder();
|
|
@@ -106,7 +108,8 @@ public class VideoUtil {
|
|
|
tsPath.append(" -movflags ");
|
|
|
tsPath.append(" +faststart ");
|
|
|
tsPath.append(newVideoFile).append("/").append(fileName);
|
|
|
- CreateObjUtil.callshell(tsPath.toString());
|
|
|
+ ShellUtil.execCmd(tsPath.toString());
|
|
|
+ ffmpegVideo(newVideoFile +"/"+ fileName,newVideoFile +"/"+ imgName,"200","200");
|
|
|
//删除生成的ts文件
|
|
|
for (String filePath : voidTS) {
|
|
|
File file = new File(filePath);
|
|
@@ -120,5 +123,23 @@ public class VideoUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param sourceFile 原文件路径
|
|
|
+ * @param thumbFile 目标文件路径
|
|
|
+ * @param thumbWidth 宽度
|
|
|
+ * @param thumbHigh 高度
|
|
|
+ * @return
|
|
|
+ * ffmpeg -i bb.mp4 -y -vframes 1 -vf scale=100:100/a thumb.jpg
|
|
|
+ */
|
|
|
+ public static boolean ffmpegVideo(String sourceFile, String thumbFile, String thumbWidth, String thumbHigh){
|
|
|
+ String cmd = " ffmpeg -i " + sourceFile + " -y -vframes 1 -vf scale=" + thumbWidth + ":" + thumbHigh + "/a " + thumbFile;
|
|
|
+ ShellUtil.execCmd(cmd);
|
|
|
+ File file = new File(thumbFile);
|
|
|
+ if(!file.exists()){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
}
|