|
|
@@ -61,6 +61,8 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
private String ffprobePath = null;
|
|
|
@Value(value = "${video.path}")
|
|
|
private String videoPath = null;
|
|
|
+ @Value(value = "${video.temppath}")
|
|
|
+ private String videoTemppath = null;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -72,7 +74,8 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
AttachmentType attachmentType = AttachmentType.getField(sign);
|
|
|
if (attachmentType == AttachmentType.VIDEO) {
|
|
|
// 先将视频存在本地文件中
|
|
|
- String filename = handleVideoFiles(res, req, videoPath);
|
|
|
+ String dir = videoTemppath + "/convert_before";
|
|
|
+ String filename = handleVideoFiles(res, req, dir);
|
|
|
res.setData(filename);
|
|
|
} else if (attachmentType == AttachmentType.VIDEO_COVER) {
|
|
|
String picturebase = req.getParameter("picturebase");
|
|
|
@@ -146,6 +149,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
|
|
|
// 生成保存到数据库的url
|
|
|
String output = System.nanoTime() + ".mp4";
|
|
|
+
|
|
|
video.setUrl(createFileName(videoPath) + "/" + output);
|
|
|
|
|
|
video.setTranscoding(1);
|
|
|
@@ -153,7 +157,8 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
result.setData(adminVideoService.insertVideo(video));
|
|
|
|
|
|
// 压缩视频并将视频
|
|
|
- videoChange(filename, output, video.getUrl());
|
|
|
+ //output = videoTemppath + "/convert_after";
|
|
|
+ videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after");
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -200,7 +205,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
String filename = video.getUrl();
|
|
|
String output = System.nanoTime() + ".mp4";
|
|
|
video.setUrl(createFileName(videoPath) + "/" + output);
|
|
|
- videoChange(filename, output, video.getUrl());
|
|
|
+ videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after");
|
|
|
|
|
|
//删除原来远程的视频
|
|
|
deleteFtpVideo(oldVideo.getUrl());
|
|
|
@@ -220,7 +225,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
}
|
|
|
|
|
|
// 将文件转码
|
|
|
- private String videoChange(String input, String output, String url) throws IOException,
|
|
|
+ private String videoChange(String input, String output, String url,String outputdir) throws IOException,
|
|
|
InterruptedException, ExecutionException {
|
|
|
|
|
|
FFmpeg ffmpeg = new FFmpeg(ffmpegPath);
|
|
|
@@ -231,7 +236,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
FFmpegBuilder builder = new FFmpegBuilder();
|
|
|
builder.setInput(in) // 输入文件
|
|
|
.overrideOutputFiles(true) // 覆盖重复文件
|
|
|
- .addOutput(output) // 输出文件
|
|
|
+ .addOutput(outputdir+"/"+output) // 输出文件
|
|
|
.setFormat("mp4") // 设置格式
|
|
|
.setTargetSize(250_000) // 目标大小
|
|
|
.disableSubtitle() // 没有子标题
|
|
|
@@ -247,7 +252,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);
|
|
|
+ SubTask subTask = new SubTask(executor, builder, in, url, input, output, outputdir+"/"+output);
|
|
|
FutureTask<Boolean> result = new FutureTask<Boolean>(subTask);
|
|
|
// 4.提交任务
|
|
|
service.submit(result);
|
|
|
@@ -259,9 +264,9 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
return "SUCESS";
|
|
|
}
|
|
|
|
|
|
- private void updateSql(String url, String filename) {
|
|
|
+ private void updateSql(String url, String tempdir, String filename) {
|
|
|
// 修改数据
|
|
|
- File file = new File(filename);
|
|
|
+ File file = new File(tempdir);
|
|
|
JtVideo video = new JtVideo();
|
|
|
video.setMd5(FileMD5(file));
|
|
|
video.setTranscoding(2);
|
|
|
@@ -269,17 +274,17 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
int c = adminVideoService.updateByUrl(video);
|
|
|
if (c > 0){
|
|
|
url = url.substring(0,url.lastIndexOf("/"));
|
|
|
- videoChange(url, filename);// 上传到远程
|
|
|
+ videoChange(url, tempdir, filename);// 上传到远程
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void videoChange(String url, String filename) {
|
|
|
+ private void videoChange(String url, String tempdir, String filename) {
|
|
|
|
|
|
- File f2 = new File(filename);// 临时压缩后的文件
|
|
|
+ File f2 = new File(tempdir);// 临时压缩后的文件
|
|
|
if (f2.exists()) {
|
|
|
// 传到远程服务器
|
|
|
FtpUtils ftp = new FtpUtils();
|
|
|
- ftp.uploadFile(url, filename, filename);
|
|
|
+ ftp.uploadFile(url, filename, tempdir);
|
|
|
// 删除视频
|
|
|
f2.delete();
|
|
|
}
|
|
|
@@ -315,16 +320,18 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
private String url;
|
|
|
private String input;
|
|
|
private String output;
|
|
|
+ private String tempdir;
|
|
|
|
|
|
public SubTask(FFmpegExecutor executor, FFmpegBuilder builder,
|
|
|
FFmpegProbeResult probeResult, String url, String input,
|
|
|
- String output) {
|
|
|
+ String output, String tempdir) {
|
|
|
this.executor = executor;
|
|
|
this.builder = builder;
|
|
|
this.probeResult = probeResult;
|
|
|
this.url = url;
|
|
|
this.input = input;
|
|
|
this.output = output;
|
|
|
+ this.tempdir = tempdir;
|
|
|
}
|
|
|
|
|
|
public FFmpegExecutor getExecutor() {
|
|
|
@@ -379,7 +386,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
// System.out.println("设置 sate");
|
|
|
// latch.wait();
|
|
|
state = true;
|
|
|
- updateSql(url, output);
|
|
|
+ updateSql(url, tempdir,output);
|
|
|
// 删除未压缩的视频
|
|
|
File f1 = new File(input);
|
|
|
f1.delete();
|