|
|
@@ -44,7 +44,6 @@ import com.goafanti.common.controller.CertifyApiController;
|
|
|
import com.goafanti.common.enums.AttachmentType;
|
|
|
import com.goafanti.common.enums.VideoFields;
|
|
|
import com.goafanti.common.model.JtVideo;
|
|
|
-import com.goafanti.common.utils.FtpUtils;
|
|
|
import com.goafanti.common.utils.StringUtils;
|
|
|
import com.goafanti.core.shiro.token.TokenManager;
|
|
|
|
|
|
@@ -59,8 +58,6 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
private String ffmpegPath = null;
|
|
|
@Value(value = "${ffprobe.path}")
|
|
|
private String ffprobePath = null;
|
|
|
- @Value(value = "${video.path}")
|
|
|
- private String videoPath = null;
|
|
|
@Value(value = "${video.temppath}")
|
|
|
private String videoTemppath = null;
|
|
|
|
|
|
@@ -93,13 +90,13 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- private String createFileName(String local) {
|
|
|
+ private String createFileName() {
|
|
|
// 年月日
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
int year = now.get(Calendar.YEAR);
|
|
|
int month = now.get(Calendar.MONTH) + 1;
|
|
|
int day = now.get(Calendar.DAY_OF_MONTH);
|
|
|
- String dir = "/" + local + "/" + year + "/" + month + "/" + day;
|
|
|
+ String dir = "/" + year + "/" + month + "/" + day;
|
|
|
return dir;
|
|
|
}
|
|
|
|
|
|
@@ -149,16 +146,18 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
|
|
|
// 生成保存到数据库的url
|
|
|
String output = System.nanoTime() + ".mp4";
|
|
|
+
|
|
|
+ String filepath = createFileName();
|
|
|
|
|
|
- video.setUrl(createFileName(videoPath) + "/" + output);
|
|
|
+ video.setUrl(filepath + "/" + output);
|
|
|
|
|
|
video.setTranscoding(1);
|
|
|
// 保存到数据库
|
|
|
result.setData(adminVideoService.insertVideo(video));
|
|
|
|
|
|
- // 压缩视频并将视频
|
|
|
- //output = videoTemppath + "/convert_after";
|
|
|
- videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after");
|
|
|
+ // 压缩视频并将视频存储
|
|
|
+
|
|
|
+ videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after" + filepath );
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -196,7 +195,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
buildError( "视频已经发布不能删除", "视频已经发布不能删除"));
|
|
|
return result;
|
|
|
}else{
|
|
|
- deleteFtpVideo(oldVideo.getUrl());
|
|
|
+ deleteFtpVideo( videoTemppath + "/convert_after" + oldVideo.getUrl());
|
|
|
}
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(video.getUrl()) && !video.getUrl().equals(oldVideo.getUrl())) { // 如果修改了视频
|
|
|
@@ -204,11 +203,12 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
// 压缩视频并将视频
|
|
|
String filename = video.getUrl();
|
|
|
String output = System.nanoTime() + ".mp4";
|
|
|
- video.setUrl(createFileName(videoPath) + "/" + output);
|
|
|
- videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after");
|
|
|
+ String filepath = createFileName() ;
|
|
|
+ video.setUrl(filepath + "/" + output);
|
|
|
+ videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after" + filepath);
|
|
|
|
|
|
//删除原来远程的视频
|
|
|
- deleteFtpVideo(oldVideo.getUrl());
|
|
|
+ deleteFtpVideo(videoTemppath + "/convert_after" + oldVideo.getUrl());
|
|
|
|
|
|
|
|
|
}else{
|
|
|
@@ -220,14 +220,23 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
}
|
|
|
|
|
|
private Boolean deleteFtpVideo(String url){
|
|
|
- FtpUtils ftp = new FtpUtils();
|
|
|
- return ftp.deleteFile("",url);
|
|
|
+ boolean b = false;
|
|
|
+ //判断文件是否存在
|
|
|
+ File f= new File(url);
|
|
|
+ if(f.exists()){
|
|
|
+ System.out.println("+++++++++++++++++++++++++++++文件存在,删除视频"+url);
|
|
|
+ b = f.delete();
|
|
|
+ }
|
|
|
+ return b;
|
|
|
}
|
|
|
|
|
|
// 将文件转码
|
|
|
private String videoChange(String input, String output, String url,String outputdir) throws IOException,
|
|
|
InterruptedException, ExecutionException {
|
|
|
-
|
|
|
+ File file = new File(outputdir);
|
|
|
+ if(!file.isDirectory()){
|
|
|
+ file.mkdirs();//创建文件夹
|
|
|
+ }
|
|
|
FFmpeg ffmpeg = new FFmpeg(ffmpegPath);
|
|
|
FFprobe ffprobe = new FFprobe(ffprobePath);
|
|
|
|
|
|
@@ -236,7 +245,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
FFmpegBuilder builder = new FFmpegBuilder();
|
|
|
builder.setInput(in) // 输入文件
|
|
|
.overrideOutputFiles(true) // 覆盖重复文件
|
|
|
- .addOutput(outputdir+"/"+output) // 输出文件
|
|
|
+ .addOutput(outputdir + "/" + output) // 输出文件
|
|
|
.setFormat("mp4") // 设置格式
|
|
|
.setTargetSize(250_000) // 目标大小
|
|
|
.disableSubtitle() // 没有子标题
|
|
|
@@ -252,7 +261,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
|
|
|
ExecutorService service = Executors.newCachedThreadPool();
|
|
|
// 3.直接new一个FutureTask
|
|
|
- SubTask subTask = new SubTask(executor, builder, in, url, input, output, outputdir+"/"+output);
|
|
|
+ SubTask subTask = new SubTask(executor, builder, in, url, input, output, outputdir);
|
|
|
FutureTask<Boolean> result = new FutureTask<Boolean>(subTask);
|
|
|
// 4.提交任务
|
|
|
service.submit(result);
|
|
|
@@ -266,36 +275,16 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
|
|
|
private void updateSql(String url, String tempdir, String filename) {
|
|
|
// 修改数据
|
|
|
- File file = new File(tempdir);
|
|
|
+ File file = new File(tempdir+"/"+filename);
|
|
|
JtVideo video = new JtVideo();
|
|
|
video.setMd5(FileMD5(file));
|
|
|
video.setTranscoding(2);
|
|
|
video.setUrl(url);
|
|
|
url = url.substring(0,url.lastIndexOf("/"));
|
|
|
- if(videoChange(url, tempdir, filename)){
|
|
|
- System.out.println("修改数据库000000000000000000000");
|
|
|
- adminVideoService.updateByUrl(video);//修改状态
|
|
|
- }// 上传到远程
|
|
|
+ System.out.println("修改数据库000000000000000000000"+url);
|
|
|
+ adminVideoService.updateByUrl(video);//修改状态
|
|
|
}
|
|
|
-
|
|
|
- private boolean videoChange(String url, String tempdir, String filename) {
|
|
|
- System.out.println("文件路径url:============"+url);
|
|
|
- System.out.println("上传到ftpfilename:=============="+filename);
|
|
|
- System.out.println("本地tempdir:=============="+tempdir);
|
|
|
- boolean t =false;
|
|
|
- File f2 = new File(tempdir);// 临时压缩后的文件
|
|
|
- if (f2.exists()) {
|
|
|
- // 传到远程服务器
|
|
|
- FtpUtils ftp = new FtpUtils();
|
|
|
- System.out.println("上传到远程服务器............................");
|
|
|
- t = ftp.uploadFile(url, filename, tempdir);
|
|
|
- System.out.println("上传远程服务器完成/////////////////////////");
|
|
|
- // 删除视频
|
|
|
- f2.delete();
|
|
|
- }
|
|
|
- return t;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
// 获得文件md5
|
|
|
private String FileMD5(File file) {
|
|
|
try {
|