From d6fabacd0229d164bcb3ec00ded008060e4d42e3 Mon Sep 17 00:00:00 2001 From: xiaohanzi Date: Mon, 26 Apr 2021 17:21:04 +0800 Subject: [PATCH] add aliyun video --- .../main/resources/mapper/WxCashOutMapper.xml | 6 + mallinkVideo/pom.xml | 31 +- .../com/iformall/video/FormallTess4j.java | 290 ------------------ .../iformall/video/FormallTess4jTrain.java | 135 -------- .../com/iformall/video/UploadVideoDemo.java | 126 ++++++++ .../java/com/iformall/video/VideoExcutor.java | 6 + .../java/com/iformall/video/VideoFactory.java | 33 ++ .../video/aliyun/AliyunVideoExcutor.java | 10 + .../aliyun/config/AliyunVideoConfig.java | 51 +++ 9 files changed, 262 insertions(+), 426 deletions(-) delete mode 100644 mallinkVideo/src/main/java/com/iformall/video/FormallTess4j.java delete mode 100644 mallinkVideo/src/main/java/com/iformall/video/FormallTess4jTrain.java create mode 100644 mallinkVideo/src/main/java/com/iformall/video/UploadVideoDemo.java create mode 100644 mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java create mode 100644 mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java create mode 100644 mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java create mode 100644 mallinkVideo/src/main/java/com/iformall/video/aliyun/config/AliyunVideoConfig.java diff --git a/mallinkService/src/main/resources/mapper/WxCashOutMapper.xml b/mallinkService/src/main/resources/mapper/WxCashOutMapper.xml index d47469ba4..78160292d 100644 --- a/mallinkService/src/main/resources/mapper/WxCashOutMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCashOutMapper.xml @@ -94,6 +94,12 @@ set `status` = #{status}, `fail_remark` = #{failRemark}, + + + `audio_remark` = #{audioRemark}, + + + `audio_date` = #{audioDate}, `update_date` = #{updateDate} where id=#{id} diff --git a/mallinkVideo/pom.xml b/mallinkVideo/pom.xml index 1e706c42f..ea55c892e 100644 --- a/mallinkVideo/pom.xml +++ b/mallinkVideo/pom.xml @@ -12,7 +12,36 @@ mallinkVideo - + + com.aliyun + aliyun-java-sdk-core + 4.5.1 + + + com.aliyun.oss + aliyun-sdk-oss + 3.10.2 + + + com.aliyun + aliyun-java-sdk-vod + 2.15.11 + + + com.alibaba + fastjson + 1.2.28 + + + org.json + json + 20170516 + + + com.google.code.gson + gson + 2.8.2 + \ No newline at end of file diff --git a/mallinkVideo/src/main/java/com/iformall/video/FormallTess4j.java b/mallinkVideo/src/main/java/com/iformall/video/FormallTess4j.java deleted file mode 100644 index d5912dfb7..000000000 --- a/mallinkVideo/src/main/java/com/iformall/video/FormallTess4j.java +++ /dev/null @@ -1,290 +0,0 @@ -package com.iformall.ocr; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; - -import com.baomidou.mybatisplus.core.toolkit.IdWorker; -import com.recognition.software.jdeskew.ImageDeskew; -import net.sourceforge.tess4j.ITessAPI.TessPageIteratorLevel; -import net.sourceforge.tess4j.ITesseract; -import net.sourceforge.tess4j.ITesseract.RenderedFormat; -import net.sourceforge.tess4j.Tesseract; -import net.sourceforge.tess4j.Word; -import net.sourceforge.tess4j.util.ImageHelper; -import net.sourceforge.tess4j.util.LoggHelper; -import net.sourceforge.tess4j.util.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * https://www.cnblogs.com/pejsidney/p/9487881.html - * Tess4J是对Tesseract OCR API.的Java JNA 封装。使java能够通过调用Tess4J的API来使用Tesseract OCR。支持的格式:TIFF,JPEG,GIF,PNG,BMP,JPEG,and PDF - Tesseract 的github地址:https://github.com/tesseract-ocr/tesseract - Tess4J的github地址:https://github.com/nguyenq/tess4j - - Tess4J API 提供的功能: - 1、直接识别支持的文件 - 2、识别图片流 - 3、识别图片的某块区域 - 4、将识别结果保存为 TEXT/ HOCR/ PDF/ UNLV/ BOX - 5、通过设置取词的等级,提取识别出来的文字 - 6、获得每一个识别区域的具体坐标范围 - 7、调整倾斜的图片 - 8、裁剪图片 - 9、调整图片分辨率 - 10、从粘贴板获得图像 - 11、克隆一个图像(目的:创建一份一模一样的图片,与原图在操作修改上,不相 互影响) - 12、图片转换为二进制、黑白图像、灰度图像 - 13、反转图片颜色 - * @author alascor - */ -public class FormallTess4j { - - - private static final Logger logger = LoggerFactory.getLogger(new LoggHelper().toString()); - static final double MINIMUM_DESKEW_THRESHOLD = 0.05d; - - private static final String datapath = "src/main/resources"; - private static final String testResourcesLanguagePath = datapath+"/tessdata"; - private static final String tempfile = "/ocrtempfile/"; - - private static ITesseract instance = new Tesseract(); - - static { - instance.setDatapath(new File(datapath).getPath()); - } - - private static File urlImgToFile(String fileUrl) { - InputStream ins = null; - OutputStream os = null; - try { - URL url = new URL(fileUrl); - URLConnection c = url.openConnection(); - ins = c.getInputStream(); - File folder = new File (tempfile) ; - if (!folder.exists()) { - folder.mkdirs(); - } - File f = new File(tempfile+System.currentTimeMillis()+"-"+IdWorker.get32UUID()+".jpg"); - if (f.exists()) { - f.delete(); - } - f.createNewFile(); - os = new FileOutputStream(f); - int bytesRead = 0; - byte[] buffer = new byte[8192]; - while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { - os.write(buffer, 0, bytesRead); - } - os.close(); - ins.close(); - return f; - } catch (MalformedURLException e) { - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }finally { - if (null != os) { - try { - os.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (null != ins) { - try { - ins.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return null; - } - - private static void deletetempFile(File file) { - if (file.exists()) { - file.delete(); - } - } - - private static String ocrLocalImgFile(String languagePath,String filePath,String fontName) throws Exception { - File imageFile = new File(filePath); - String result = testDoOCR_File(languagePath,imageFile,fontName); - deletetempFile(imageFile); - return result; - } - - public static String ocrNetImgFile(String languagePath,String fileUrl,String fontName) throws Exception { - File imageFile = urlImgToFile(fileUrl); - String result = testDoOCR_File(languagePath,imageFile,fontName); - deletetempFile(imageFile); - return result; - } - - /** - * Test of doOCR method, of class Tesseract. - * 根据图片文件进行识别 - * @throws Exception while processing image. - */ - public static String testDoOCR_File(String languagePath,File imageFile,String fontName) throws Exception { - logger.info("doOCR on a jpg image"); - //set language - instance.setDatapath(languagePath); - instance.setLanguage(fontName); - String result = instance.doOCR(imageFile); - return result; - } - - - public static void main(String[] args) { - try { - //System.out.println(ocrNetImgFile(testResourcesLanguagePath,"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.my0832.com%2Fattachments%2Fbbs%2F20140424%2F201442413083356803_740_1186.jpg&refer=http%3A%2F%2Fimg.my0832.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1613903848&t=985fc4c6c7b7ee82cb98f97ab5bf1459","test1")); - System.out.println(ocrLocalImgFile(testResourcesLanguagePath,"C:\\Users\\iformall\\Desktop\\01.jpg","test1")); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - -// -// /** -// * Test of doOCR method, of class Tesseract. -// * 根据图片流进行识别 -// * @throws Exception while processing image. -// */ -// public void testDoOCR_BufferedImage() throws Exception { -// logger.info("doOCR on a buffered image of a PNG"); -// File imageFile = new File(this.testResourcesDataPath, "ocr.png"); -// BufferedImage bi = ImageIO.read(imageFile); -// -// //set language -// instance.setDatapath(testResourcesLanguagePath); -// instance.setLanguage("chi_sim"); -// -// String result = instance.doOCR(bi); -// logger.info(result); -// } -// -// /** -// * Test of getSegmentedRegions method, of class Tesseract. -// * 得到每一个划分区域的具体坐标 -// * @throws java.lang.Exception -// */ -// public void testGetSegmentedRegions() throws Exception { -// logger.info("getSegmentedRegions at given TessPageIteratorLevel"); -// File imageFile = new File(testResourcesDataPath, "ocr.png"); -// BufferedImage bi = ImageIO.read(imageFile); -// int level = TessPageIteratorLevel.RIL_SYMBOL; -// logger.info("PageIteratorLevel: " + Utils.getConstantName(level, TessPageIteratorLevel.class)); -// List result = instance.getSegmentedRegions(bi, level); -// for (int i = 0; i < result.size(); i++) { -// Rectangle rect = result.get(i); -// logger.info(String.format("Box[%d]: x=%d, y=%d, w=%d, h=%d", i, rect.x, rect.y, rect.width, rect.height)); -// } -// -// assertTrue(result.size() > 0); -// } -// -// -// /** -// * Test of doOCR method, of class Tesseract. -// * 根据定义坐标范围进行识别 -// * @throws Exception while processing image. -// */ -// public void testDoOCR_File_Rectangle() throws Exception { -// logger.info("doOCR on a BMP image with bounding rectangle"); -// File imageFile = new File(this.testResourcesDataPath, "ocr.png"); -// //设置语言库 -// instance.setDatapath(testResourcesLanguagePath); -// instance.setLanguage("chi_sim"); -// //划定区域 -// // x,y是以左上角为原点,width和height是以xy为基础 -// Rectangle rect = new Rectangle(84, 21, 15, 13); -// String result = instance.doOCR(imageFile, rect); -// logger.info(result); -// } -// -// /** -// * Test of createDocuments method, of class Tesseract. -// * 存储结果 -// * @throws java.lang.Exception -// */ -// public void testCreateDocuments() throws Exception { -// logger.info("createDocuments for png"); -// File imageFile = new File(this.testResourcesDataPath, "ocr.png"); -// String outputbase = "target/test-classes/docrenderer-2"; -// List formats = new ArrayList(Arrays.asList(RenderedFormat.HOCR, RenderedFormat.TEXT)); -// -// //设置语言库 -// instance.setDatapath(testResourcesLanguagePath); -// instance.setLanguage("chi_sim"); -// -// instance.createDocuments(new String[]{imageFile.getPath()}, new String[]{outputbase}, formats); -// } -// -// /** -// * Test of getWords method, of class Tesseract. -// * 取词方法 -// * @throws java.lang.Exception -// */ -// public void testGetWords() throws Exception { -// logger.info("getWords"); -// File imageFile = new File(this.testResourcesDataPath, "ocr.png"); -// -// //设置语言库 -// instance.setDatapath(testResourcesLanguagePath); -// instance.setLanguage("chi_sim"); -// -// //按照每个字取词 -// int pageIteratorLevel = TessPageIteratorLevel.RIL_SYMBOL; -// logger.info("PageIteratorLevel: " + Utils.getConstantName(pageIteratorLevel, TessPageIteratorLevel.class)); -// BufferedImage bi = ImageIO.read(imageFile); -// List result = instance.getWords(bi, pageIteratorLevel); -// -// //print the complete result -// for (Word word : result) { -// logger.info(word.toString()); -// } -// } -// -// /** -// * Test of Invalid memory access. -// * 处理倾斜 -// * @throws Exception while processing image. -// */ -// public void testDoOCR_SkewedImage() throws Exception { -// //设置语言库 -// instance.setDatapath(testResourcesLanguagePath); -// instance.setLanguage("chi_sim"); -// -// logger.info("doOCR on a skewed PNG image"); -// File imageFile = new File(this.testResourcesDataPath, "ocr_skewed.jpg"); -// BufferedImage bi = ImageIO.read(imageFile); -// ImageDeskew id = new ImageDeskew(bi); -// double imageSkewAngle = id.getSkewAngle(); // determine skew angle -// if ((imageSkewAngle > MINIMUM_DESKEW_THRESHOLD || imageSkewAngle < -(MINIMUM_DESKEW_THRESHOLD))) { -// bi = ImageHelper.rotateImage(bi, -imageSkewAngle); // deskew image -// } -// -// String result = instance.doOCR(bi); -// logger.info(result); -// } - -} diff --git a/mallinkVideo/src/main/java/com/iformall/video/FormallTess4jTrain.java b/mallinkVideo/src/main/java/com/iformall/video/FormallTess4jTrain.java deleted file mode 100644 index d2006fd4c..000000000 --- a/mallinkVideo/src/main/java/com/iformall/video/FormallTess4jTrain.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.iformall.ocr; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.LineNumberReader; - -/** - * 训练 - * @author iformall - */ -public class FormallTess4jTrain { - - private static final String newFileFolder = "C:\\Users\\iformall\\Desktop\\newfile"; - - private static final String huanhangstr = " \n "; - - private static String getprefix(String lang,String fontName) { - String realFileName = lang+"."+fontName+".exp0"; - return realFileName; - } - - private static String createBoxFile(String tifFileName,String lang,String fontName) { - String prefix = getprefix(lang,fontName); - String realFileName = prefix+".tif"; - if (tifFileName.equals(realFileName)) { - String cmdstr = "tesseract "+tifFileName+" "+prefix+" -l chi_sim batch.nochop makebox"; - return cmdstr; - //String result = executeLocalCmd(cmdstr, null); - - //System.out.println("Done createBoxFile"+result); - }else { - return "文件必须是.tif"; - } - } - - private static String createTranFile(String lang,String fontName) { - String prefix = getprefix(lang,fontName); - String realFileName = prefix+".tif"; - String trainCmdstr = "tesseract "+realFileName+" "+prefix+" nobatch box.train"; - return trainCmdstr; - } - - private static String getBoxFont(String lang,String fontName) { - String prefix = getprefix(lang,fontName); - String extractorCmdstr = "unicharset_extractor "+prefix+".box [other .box files...]"; - return extractorCmdstr; - } - - /** - * 第六步,执行完成后生成以下几个文件加前缀 - * unicharset、inttemp、pffmtable、shapetable、normproto 添加这几个文件的前缀为fontName - * @param lang - * @param fontName - * @return - */ - private static String renameTrainFiles(String fontName) { - StringBuffer sb = new StringBuffer(); - String renCmdstr = "REN unicharset "+fontName+".unicharset"; - sb.append(renCmdstr).append(huanhangstr); - - renCmdstr = "REN inttemp "+fontName+".inttemp"; - sb.append(renCmdstr).append(huanhangstr); - - renCmdstr = "REN pffmtable "+fontName+".pffmtable"; - sb.append(renCmdstr).append(huanhangstr); - - renCmdstr = "REN shapetable "+fontName+".shapetable"; - sb.append(renCmdstr).append(huanhangstr); - - renCmdstr = "REN normproto "+fontName+".normproto"; - sb.append(renCmdstr).append(huanhangstr); - return sb.toString(); - } - - /** - * 第七步:合并5个文件 - * @param lang - * @param fontName - * @return - */ - private static String mergeTrainFiles(String fontName) { - String mergeCmdstr = "combine_tessdata "+fontName+"."; - return mergeCmdstr; - } - - - public static String getTrainSteps(String lang,String fontName) { - - StringBuffer sb = new StringBuffer("请先安装tess4j(4.0以上),配置好环境变量. 下载jTessBoxEditor(用于训练,带FX的支持中文)").append(huanhangstr); - sb.append("请进入到样本图片文件夹用doc命令执行.").append(huanhangstr); - sb.append("第一步,用jTessBoxEditor --> Tools --> Merge 多选图片,保存为tif格式 .命名格式为[lang].[fontName].exp0.tif. 命名:").append(lang).append(".").append(fontName).append(".exp0.tif ").append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第二步,用tif生成box ").append(huanhangstr); - sb.append(createBoxFile(lang+"."+fontName+".exp0.tif", lang, fontName)).append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第三步,用jTessBoxEditor 打开.box文件进行矫正 ").append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第四步:用box文件生成。tr文件 ").append(huanhangstr); - sb.append(createTranFile(lang,fontName)).append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("@@@!!!!从此处开始,可以处理多个字库处理。如原来的字库现在做升级,需要把老的字库的。tif,.box,.tr文件重新命名也放到同目录文件夹, ").append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第五步:提取box字符 ").append(huanhangstr); - sb.append(getBoxFont(lang,fontName)).append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第六步:新建font_properties(没有.txt后缀), 把所有box对应的字体特征加进去。").append(huanhangstr); - sb.append("fontname为字体名称,保持和 图片集文件 .tif 和.box文件的前缀名一致 .的取值为1或0,表示字体是否具有这些属性。 ").append(huanhangstr); - sb.append("如以下内容: ").append(huanhangstr); - sb.append("fontName1 0 0 0 0 0 ").append(huanhangstr); - sb.append("fontName2 0 1 0 0 0 ").append(huanhangstr); - sb.append("fontName3 1 1 0 0 0 ").append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第六步:批量执行系列命令。多个文件在后面累加。 ").append(huanhangstr); - String prefix = getprefix(lang,fontName); - String shapeCmdStr = "### shapeclustering -F font_properties -U unicharset "+prefix+".tr [other .tr files...] "; - sb.append(shapeCmdStr).append(huanhangstr); - String mftraingCmdstr = "mftraining -F font_properties -U unicharset -O unicharset "+prefix+".tr [other .tr files...] "; - sb.append(mftraingCmdstr).append(huanhangstr); - String cntrainCmdstr = "cntraining "+prefix+".tr [other .tr files...] "; - sb.append(cntrainCmdstr).append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第七步,执行完成后生成以下几个文件加前缀: unicharset、inttemp、pffmtable、shapetable、normproto 添加这几个文件的前缀为[fontName] ").append(huanhangstr); - sb.append(renameTrainFiles(fontName)); - sb.append("............ ").append(huanhangstr); - sb.append("第七步:合并5个文件").append(huanhangstr); - sb.append(mergeTrainFiles(fontName)).append(huanhangstr); - sb.append("............ ").append(huanhangstr); - sb.append("第八步:将").append(fontName).append(".traineddata 文件拷贝到后端服务器ocr_data(项目配置fm.ocr_data)目录下。 .tif、。box、。tr文件也需要保留,后面如果这个字库有更新,需要用到这些文件。").append(huanhangstr); - return sb.toString(); - } - -} diff --git a/mallinkVideo/src/main/java/com/iformall/video/UploadVideoDemo.java b/mallinkVideo/src/main/java/com/iformall/video/UploadVideoDemo.java new file mode 100644 index 000000000..860a09c2e --- /dev/null +++ b/mallinkVideo/src/main/java/com/iformall/video/UploadVideoDemo.java @@ -0,0 +1,126 @@ +package com.iformall.video; + + +public class UploadVideoDemo { + //账号AK信息(必选) + private static final String accessKeyId = ""; + //账号AK信息(必选) + private static final String accessKeySecret = ""; + + public static void main(String[] args) { + //1.音视频上传-本地文件上传 + //视频标题(必选) + String title = "测试标题"; + //本地文件上传和文件流上传时,文件名称为上传文件绝对路径,如:/User/sample/文件名称.mp4 (必选) + //文件名必须包含扩展名 + String fileName = "测试文件名称.mp4"; + //本地文件上传 + testUploadVideo(accessKeyId, accessKeySecret, title, fileName); + + //2.图片上传-本地文件上传 + testUploadImageLocalFile(accessKeyId, accessKeySecret); + } + + /** + * 本地文件上传接口 + * + * @param accessKeyId + * @param accessKeySecret + * @param title + * @param fileName + */ + private static void testUploadVideo(String accessKeyId, String accessKeySecret, String title, String fileName) { +// UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName); + /*可指定分片上传时每个分片的大小,默认为1M字节*/ +// request.setPartSize(1 * 1024 * 1024L); + /*可指定分片上传时的并发线程数,默认为1(注:该配置会占用服务器CPU资源,需根据服务器情况指定)*/ +// request.setTaskNum(1); + /*是否开启断点续传,默认断点续传功能关闭。当网络不稳定或者程序崩溃时,再次发起相同上传请求,可以继续未完成的上传任务,适用于超时3000秒仍不能上传完成的大文件。 + 注意: 断点续传开启后,会在上传过程中将上传位置写入本地磁盘文件,影响文件上传速度,请您根据实际情况选择是否开启*/ +// request.setEnableCheckpoint(false); + /*OSS慢请求日志打印超时时间,是指每个分片上传时间超过该阈值时会打印debug日志,如果想屏蔽此日志,请调整该阈值。单位: 毫秒,默认为300000毫秒*/ + //request.setSlowRequestsThreshold(300000L); + /*可指定每个分片慢请求时打印日志的时间阈值,默认为300s*/ + //request.setSlowRequestsThreshold(300000L); + /*是否使用默认水印(可选),指定模板组ID时,根据模板组配置确定是否使用默认水印*/ + //request.setIsShowWaterMark(true); + /*自定义消息回调设置(可选),参数说明参考文档 https://help.aliyun.com/document_detail/86952.html#UserData*/ + // request.setUserData("{\"Extend\":{\"test\":\"www\",\"localId\":\"xxxx\"},\"MessageCallback\":{\"CallbackURL\":\"http://test.test.com\"}}"); + + /*视频分类ID(可选)*/ + //request.setCateId(0); + /*视频标签,多个用逗号分隔(可选)*/ + //request.setTags("标签1,标签2"); + /*视频描述(可选)*/ + //request.setDescription("视频描述"); + /*封面图片(可选)*/ + //request.setCoverURL("http://cover.sample.com/sample.jpg"); + /*模板组ID(可选)*/ + //request.setTemplateGroupId("8c4792cbc8694*****d5330e56a33d"); + /*点播服务接入点*/ + //request.setApiRegionId("cn-shanghai"); + /*ECS部署区域,如果与点播存储(OSS)区域相同,则自动使用内网上传文件至存储*/ + // request.setEcsRegionId("cn-shanghai"); + /*存储区域(可选)*/ + //request.setStorageLocation("in-2017032*****18266-5sejdln9o.oss-cn-shanghai.aliyuncs.com"); + /*开启默认上传进度回调*/ + // request.setPrintProgress(true); + /*设置自定义上传进度回调(必须继承 ProgressListener)*/ + // request.setProgressListener(new PutObjectProgressListener()); +// UploadVideoImpl uploader = new UploadVideoImpl(); +// UploadVideoResponse response = uploader.uploadVideo(request); +// System.out.print("RequestId=" response.getRequestId() "\n"); //请求视频点播服务的请求ID +// if (response.isSuccess()) { +// System.out.print("VideoId=" response.getVideoId() "\n"); +// } else { +// /* 如果设置回调URL无效,不影响视频上传,可以返回VideoId同时会返回错误码。其他情况上传失败时,VideoId为空,此时需要根据返回错误码分析具体错误原因 */ +// System.out.print("VideoId=" response.getVideoId() "\n"); +// System.out.print("ErrorCode=" response.getCode() "\n"); +// System.out.print("ErrorMessage=" response.getMessage() "\n"); +// } + } + + /** + * 图片上传接口,本地文件上传示例 + * 参数参考文档 https://help.aliyun.com/document_detail/55619.html + * + * @param accessKeyId + * @param accessKeySecret + */ + private static void testUploadImageLocalFile(String accessKeyId, String accessKeySecret) { + //图片类型(必选)取值范围:default(默认),cover(封面),watermark(水印) + String imageType = "cover"; +// UploadImageRequest request = new UploadImageRequest(accessKeyId, accessKeySecret, imageType); +// /*图片文件扩展名(可选)取值范围:png,jpg,jpeg*/ +// //request.setImageExt("png"); +// /*图片标题(可选)长度不超过128个字节,UTF8编码*/ +// //request.setTitle("图片标题"); +// /*图片标签(可选)单个标签不超过32字节,最多不超过16个标签,多个用逗号分隔,UTF8编码*/ +// //request.setTags("标签1,标签2"); +// /*存储区域(可选)*/ +// //request.setStorageLocation("out-4f3952f78c021*****013e7.oss-cn-shanghai.aliyuncs.com"); +// /*流式上传时,InputStream为必选,fileName为源文件名称,如:文件名称.png(可选)*/ +// //request.setFileName("测试文件名称.png"); +// /*开启默认上传进度回调*/ +// // request.setPrintProgress(true); +// /*设置自定义上传进度回调(必须继承 ProgressListener)*/ +// // request.setProgressListener(new PutObjectProgressListener()); +// /*点播服务接入点*/ +// //request.setApiRegionId("cn-shanghai"); +// /*ECS部署区域,如果与点播存储(OSS)区域相同,则自动使用内网上传文件至存储*/ +// // request.setEcsRegionId("cn-shanghai"); +// +// UploadImageImpl uploadImage = new UploadImageImpl(); +// UploadImageResponse response = uploadImage.upload(request); +// System.out.print("RequestId=" response.getRequestId() "\n"); +// if (response.isSuccess()) { +// System.out.print("ImageId=" response.getImageId() "\n"); +// System.out.print("ImageURL=" response.getImageURL() "\n"); +// } else { +// System.out.print("ErrorCode=" response.getCode() "\n"); +// System.out.print("ErrorMessage=" response.getMessage() "\n"); +// } + + + } +} \ No newline at end of file diff --git a/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java b/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java new file mode 100644 index 000000000..905e61d2e --- /dev/null +++ b/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java @@ -0,0 +1,6 @@ +package com.iformall.video; + +public interface VideoExcutor { + + +} diff --git a/mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java b/mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java new file mode 100644 index 000000000..5f1ac6035 --- /dev/null +++ b/mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java @@ -0,0 +1,33 @@ +package com.iformall.video; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.iformall.video.aliyun.AliyunVideoExcutor; + + +@Service +public class VideoFactory { + + private Map excutorMap = null; + + @Autowired + AliyunVideoExcutor aliyunExcutor; + + private Map getExcutorMap() { + if (null == excutorMap) { + excutorMap = new ConcurrentHashMap(); + excutorMap.put("aliyun", aliyunExcutor); + } + return excutorMap; + } + + + public VideoExcutor getExcutor(String type) { + VideoExcutor service = getExcutorMap().get(type); + return service; + } +} diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java new file mode 100644 index 000000000..1d684a28d --- /dev/null +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java @@ -0,0 +1,10 @@ +package com.iformall.video.aliyun; + +import org.springframework.stereotype.Component; + +import com.iformall.video.VideoExcutor; + +@Component +public class AliyunVideoExcutor implements VideoExcutor { + +} diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/config/AliyunVideoConfig.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/config/AliyunVideoConfig.java new file mode 100644 index 000000000..87c1ea1a2 --- /dev/null +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/config/AliyunVideoConfig.java @@ -0,0 +1,51 @@ +package com.iformall.video.aliyun.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import lombok.Data; + +@Data +@Configuration +@ConfigurationProperties(prefix = "video.aliyun") +public class AliyunVideoConfig { + private String access; + + private String secret; + + private String clientRegion; + + private String bucketName; + + public String getAccess() { + return access; + } + + public void setAccess(String access) { + this.access = access; + } + + public String getSecret() { + return secret; + } + + public void setSecret(String secret) { + this.secret = secret; + } + + public String getClientRegion() { + return clientRegion; + } + + public void setClientRegion(String clientRegion) { + this.clientRegion = clientRegion; + } + + public String getBucketName() { + return bucketName; + } + + public void setBucketName(String bucketName) { + this.bucketName = bucketName; + } +}