Merge branch 'main' of http://10.10.14.176:3000/huanghai/QingLong
commit
7c7053c6f6
@ -0,0 +1,23 @@
|
||||
package UnitTest;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class TestGetUrl {
|
||||
public static void main(String[] args) {
|
||||
//m3u8的lessonId
|
||||
//String lessonId = "931303979da03dfa291ed5e6531b82e5";
|
||||
//mp4的lessonId
|
||||
String lessonId = "2144ddfe45ef13b94eb06dd4e9bdee2b";
|
||||
|
||||
String sourceUrl = "https://yx.ccsjy.cn/api/cloud-school/v1/cloudLesson/getById?lessonId=" + lessonId;
|
||||
String content = HttpUtil.get(sourceUrl);
|
||||
JSONObject jo = JSONObject.parseObject(content);
|
||||
String fileUrl = jo.getJSONObject("data").getJSONArray("lessonResources").getJSONObject(0).getString("fileUrl");
|
||||
if (fileUrl.contains(".mp4")) {
|
||||
fileUrl = "https://ccschool.edusoa.com/" + fileUrl;
|
||||
}
|
||||
|
||||
System.out.println(fileUrl);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.dsideal.QingLong.YunXiao.Util;
|
||||
|
||||
import cn.hutool.core.util.RuntimeUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class YunXiaoVideoUtil {
|
||||
//MP4的片头长10秒
|
||||
public static final int MP4 = 10;
|
||||
//MU38的片头长7秒
|
||||
public static final int M3U8 = 5;
|
||||
//ffmpeg路径
|
||||
public static final String FFMPEG_PATH = "D:\\ffmpeg\\ffmpeg.exe";
|
||||
|
||||
/**
|
||||
* 获取视频封面
|
||||
*
|
||||
* @param ffmpegPath
|
||||
* @param videoInputPath
|
||||
* @param videoOutputPath
|
||||
* @return
|
||||
*/
|
||||
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 videoInputPath 输入的视频路径
|
||||
* @param videoOutputPath 输出的图片路径
|
||||
* @return
|
||||
*/
|
||||
public static String getCmd(String videoInputPath, String videoOutputPath) {
|
||||
if (videoInputPath.toLowerCase().endsWith(".m3u8")) {
|
||||
return getCmdM3u8(FFMPEG_PATH, M3U8, videoInputPath, videoOutputPath);
|
||||
}
|
||||
return getCmdMp4(FFMPEG_PATH, MP4, videoInputPath, videoOutputPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取视频封面
|
||||
*
|
||||
* @param url
|
||||
* @param JpegPath
|
||||
*/
|
||||
public static void getCover(String url, String JpegPath) throws InterruptedException {
|
||||
String cmd = getCmd(url, JpegPath);
|
||||
//使用java调用ffmpeg命令行工具生成图片
|
||||
Process process = RuntimeUtil.exec(cmd);
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据课程id获取它的视频地址
|
||||
* @param lessonId 课程id
|
||||
* @return
|
||||
*/
|
||||
public static String getUrlByLessonId(String lessonId){
|
||||
String sourceUrl = "https://yx.ccsjy.cn/api/cloud-school/v1/cloudLesson/getById?lessonId=" + lessonId;
|
||||
String content = HttpUtil.get(sourceUrl);
|
||||
JSONObject jo = JSONObject.parseObject(content);
|
||||
String fileUrl = jo.getJSONObject("data").getJSONArray("lessonResources").getJSONObject(0).getString("fileUrl");
|
||||
if (fileUrl.contains(".mp4")) {
|
||||
fileUrl = "https://ccschool.edusoa.com/" + fileUrl;
|
||||
}
|
||||
return fileUrl;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
String[] a = {
|
||||
"https://ccschool.edusoa.com/cloud_file/project/ccyx-0012/material/5b/c5/5bc51a9075751b69a9c1c5d722c39485.mp4",
|
||||
"https://ccmsyk-video.edusoa.com/down/M3u8/BE/BECBF507-1EAF-4301-A417-AE25593A62F1.m3u8",
|
||||
"https://ccmsyk-video.edusoa.com/down/M3u8/73/7311BCC2-D260-4D34-9B70-3722DB884CB6.m3u8",
|
||||
"https://ccmsyk-video.edusoa.com/down/M3u8/9A/9A69A401-BF92-433D-AB96-7B9965BDDD87.m3u8"
|
||||
};
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
File f = new File("c:\\" + (i + 1) + ".jpg");
|
||||
if (f.exists()) f.delete();
|
||||
getCover(a[i], f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue