main
黄海 7 months ago
parent ba15f6a6ca
commit fe0d7b0d4c

@ -0,0 +1,47 @@
package com.dsideal.QingLong.Render;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.jfinal.render.Render;
/**
*
*
* @author CC11001100
*/
public class ImageRender extends Render {
/**
*
*/
private File imgFile;
public ImageRender(File imgFile) {
super();
this.imgFile = imgFile;
}
public File getImgFile() {
return imgFile;
}
public void setImgFile(File imgFile) {
this.imgFile = imgFile;
}
/**
*
*/
public void render() {
response.setContentType("image/jpeg");
try {
FileUtils.copyFile(imgFile, response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -1,9 +1,11 @@
package com.dsideal.QingLong.YunXiao.Controller;
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Render.ImageRender;
import com.dsideal.QingLong.Util.CommonUtil;
import com.dsideal.QingLong.YunXiao.Model.YunXiaoModel;
import com.dsideal.QingLong.YunXiao.Util.YunXiaoExportExcelUtil;
import com.dsideal.QingLong.YunXiao.Util.YunXiaoVideoUtil;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
@ -112,7 +114,7 @@ public class YunXiaoController extends Controller {
//获取系统临时目录
String tmpDir = System.getProperty("java.io.tmpdir");
//使用guid生成一个临时文件名然后拼接到tmpDir后面生成完整的临时文件路径
String tmpFile = tmpDir + File.separator + UUID.randomUUID() + ".xlsx";
String tmpFile = tmpDir + UUID.randomUUID() + ".xlsx";
exporter.LessonConstructionExportExcel(tmpFile, list1, list2, list3);
//提供下载
renderFile(new File(tmpFile), "课程建设情况报表.xlsx");
@ -133,9 +135,25 @@ public class YunXiaoController extends Controller {
//获取系统临时目录
String tmpDir = System.getProperty("java.io.tmpdir");
//使用guid生成一个临时文件名然后拼接到tmpDir后面生成完整的临时文件路径
String tmpFile = tmpDir + File.separator + UUID.randomUUID() + ".xlsx";
String tmpFile = tmpDir + UUID.randomUUID() + ".xlsx";
exporter.LessonConstructionInfoByXzqhSchool(tmpFile, list1, list2, list3, list4);
//提供下载
renderFile(new File(tmpFile), "【区域+学校】课程建设情况报表.xlsx");
}
/**
*
* @param url
*/
// http://10.10.21.20:9000/QingLong/yx/getLessonCover?url=
@Before(GET.class)
public void getLessonCover(String url) {
//获取系统临时目录
String tmpDir = System.getProperty("java.io.tmpdir");
//使用guid生成一个临时文件名然后拼接到tmpDir后面生成完整的临时文件路径
String tmpFile = tmpDir + UUID.randomUUID() + ".jpg";
YunXiaoVideoUtil.getCover(url, tmpFile);
File imgFile = new File(tmpFile);
render(new ImageRender(imgFile));
}
}

@ -2,11 +2,15 @@ package com.dsideal.QingLong.YunXiao.Util;
import cn.hutool.core.util.RuntimeUtil;
import java.io.File;
public class YunXiaoVideoUtil {
//MP4的片头长10秒
public static final int MP4 = 10;
//MU38的片头长7秒
public static final int M3U8 = 16;
public static final int M3U8 = 5;
//ffmpeg路径
public static final String FFMPEG_PATH = "D:\\ffmpeg\\ffmpeg.exe";
/**
*
@ -16,23 +20,48 @@ public class YunXiaoVideoUtil {
* @param videoOutputPath
* @return
*/
private static String getCmd(String ffmpegPath, int seconds, String videoInputPath, String videoOutputPath) {
private static String getCmdMp4(String ffmpegPath, int seconds, String videoInputPath, String videoOutputPath) {
return ffmpegPath + " -ss " + seconds + " -i " + videoInputPath + " -frames:v 1 -q:v 2 -s 1280x720 " + videoOutputPath;
}
/**
* m3u8
*
* @param ffmpegPath
* @param seconds
* @param videoInputPath
* @param videoOutputPath
* @return
*/
private static String getCmdM3u8(String ffmpegPath, int seconds, String videoInputPath, String videoOutputPath) {
return ffmpegPath + " -i " + videoInputPath + " -ss " + seconds + " -vframes 1 -s 1280x720 " + videoOutputPath;
}
/**
*
*
* @param ffmpegPath ffmpeg
* @param videoInputPath
* @param videoOutputPath
* @return
*/
public static String getCmd(String ffmpegPath, String videoInputPath, String videoOutputPath) {
if (videoInputPath.toLowerCase().equals(".m3u8")) {
return getCmd(ffmpegPath, M3U8, videoInputPath, videoOutputPath);
public static String getCmd(String videoInputPath, String videoOutputPath) {
if (videoInputPath.toLowerCase().endsWith(".m3u8")) {
return getCmdM3u8(FFMPEG_PATH, M3U8, videoInputPath, videoOutputPath);
}
return getCmd(ffmpegPath, MP4, videoInputPath, videoOutputPath);
return getCmdMp4(FFMPEG_PATH, MP4, videoInputPath, videoOutputPath);
}
/**
*
* @param url
* @param JpegPath
*/
public static void getCover(String url, String JpegPath) {
String cmd = getCmd(url, JpegPath);
//使用java调用ffmpeg命令行工具生成图片
RuntimeUtil.exec(cmd);
System.out.println(JpegPath);
}
public static void main(String[] args) {
@ -43,9 +72,9 @@ public class YunXiaoVideoUtil {
"https://ccmsyk-video.edusoa.com/down/M3u8/9A/9A69A401-BF92-433D-AB96-7B9965BDDD87.m3u8"
};
for (int i = 0; i < a.length; i++) {
String cmd = getCmd("D:\\ffmpeg\\ffmpeg.exe", a[i], "c:\\" + (i + 1) + ".jpg");
//使用java调用ffmpeg命令行工具生成图片
RuntimeUtil.exec(cmd);
File f = new File("c:\\" + (i + 1) + ".jpg");
if (f.exists()) f.delete();
getCover(a[i], f.getAbsolutePath());
}
}
}

Loading…
Cancel
Save