CreateObjUtil.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. package com.fdkankan.model.utils;
  2. import cn.hutool.core.io.FileUtil;
  3. import com.fdkankan.model.constants.ConstantCmd;
  4. import com.fdkankan.model.constants.ConstantFileName;
  5. import com.fdkankan.model.constants.ConstantFilePath;
  6. import com.fdkankan.model.proto.BigSceneProto;
  7. import com.fdkankan.model.proto.Common;
  8. import com.fdkankan.model.proto.Visionmodeldata;
  9. import com.fdkankan.model.proto.format.JsonFormat;
  10. import com.google.protobuf.TextFormat;
  11. import lombok.extern.slf4j.Slf4j;
  12. import java.io.*;
  13. import java.util.*;
  14. import java.util.stream.Collectors;
  15. import lombok.extern.slf4j.Slf4j;
  16. @Slf4j
  17. public class CreateObjUtil {
  18. // private static Logger log = LoggerFactory.getLogger(CreateObjUtil.class);
  19. public void saveuploadImgs(String folderName) throws IOException, Exception
  20. {
  21. log.info("开始计算");
  22. String command = "bash /home/ubuntu/photoscan-pro/build_model.sh "+folderName;
  23. callshell(command);
  24. boolean flag = false;
  25. String sPath = ConstantFilePath.CREATE_MODEL_PATH+folderName+File.separator+"mesh"+File.separator+"mesh.obj";
  26. while(!flag)
  27. {
  28. flag = isModel(sPath,folderName);
  29. }
  30. log.info("计算完毕");
  31. }
  32. public void saveuploadImgs2(String folderName) throws IOException, Exception
  33. {
  34. log.info("开始计算");
  35. String command = "bash /home/ubuntu/photoscan-pro/build_bigscene.sh "+folderName;
  36. callshell(command);
  37. boolean flag = false;
  38. String sPath = ConstantFilePath.CREATE_BIG_SCENE_PATH+folderName+File.separator+"mesh"+File.separator+"mesh.obj";
  39. while(!flag)
  40. {
  41. flag = isModel(sPath,folderName);
  42. }
  43. log.info("计算完毕");
  44. log.info("obj和camera转换成大场景要的格式");
  45. convertobjTotxt( folderName);
  46. }
  47. //开始建模
  48. public static void unRar(String rarPath,String dataPath) throws Exception{
  49. log.info("解压rar开始");
  50. String command = "unrar e " + rarPath + " " + dataPath;
  51. callshell(command);
  52. log.info("解压rar完毕:" + command);
  53. }
  54. public static void unRarWithPath(String rarPath,String dataPath) throws Exception{
  55. log.info("解压rar开始");
  56. String command = "unrar x " + rarPath + " " + dataPath;
  57. callshell(command);
  58. log.info("解压rar完毕:" + command);
  59. }
  60. public static void unZip(String zipPath,String dataPath) throws Exception{
  61. log.info("解压zip开始");
  62. String command = "unzip -O GBK/GB18030CP936 " + zipPath + " -d " + dataPath;
  63. callshell(command);
  64. log.info("解压zip完毕:" + command);
  65. }
  66. //开始建模
  67. public static void build3dModel(String folderName,String isModel) throws Exception{
  68. log.info("开始建模");
  69. String command = ConstantCmd.BUILD_MODEL_COMMAND+folderName;
  70. callshell(command);
  71. log.info("计算完毕:" + command);
  72. }
  73. //开始建模
  74. public static void build3dModel2(String folderName,String isModel) throws Exception{
  75. log.info("开始建模");
  76. String command = ConstantCmd.BUILD_MODEL_COMMAND2+folderName;
  77. callshell(command);
  78. log.info("计算完毕:" + command);
  79. }
  80. //开始建模
  81. public static void build3dModelOld(String folderName,String isModel) throws Exception{
  82. log.info("开始v2建模");
  83. String command = ConstantCmd.BUILD_MODEL_OLD_COMMAND+folderName;
  84. callshell(command);
  85. log.info("计算v2完毕:" + command);
  86. }
  87. public static void killMainLoader(){
  88. log.info("开始杀掉算法进程");
  89. String command = "ps -ef | grep 'MainLoader.exe' | grep -v grep | awk '{print $2}' | xargs kill -9";
  90. callshell(command);
  91. log.info("开始杀掉算法完毕");
  92. }
  93. //开始建模
  94. public static void translateHoustfloorJSONFile(String filePath,String outputPath) throws Exception{
  95. log.info("开始转换houst_floor.json");
  96. String command = ConstantCmd.TRANSLATE_HOUST_FLOOR + filePath + " " + outputPath;
  97. callshell(command);
  98. log.info("转换houst_floor.json 结束");
  99. }
  100. //激光相机复制资源
  101. public static void cpfile(String filepathOld,String filepathNew) throws Exception{
  102. log.info("开始复制");
  103. String command = ConstantCmd.CP_JG_EXTRA+ " " + filepathOld + " " + filepathNew;
  104. callshell(command);
  105. log.info("复制完毕:" + command);
  106. }
  107. //激光相机复制资源laser下的全部资源
  108. public static void cplaserfile(String filepathOld,String filepathNew) throws Exception{
  109. log.info("开始复制");
  110. String command = ConstantCmd.CP_JG_ALL+ " " + filepathOld + " " + filepathNew;
  111. callshell(command);
  112. log.info("复制完毕:" + command);
  113. }
  114. //开始建模
  115. public void build3dModelSFM(String folderName,String isModel) throws Exception{
  116. log.info("开始建模");
  117. String command = ConstantCmd.BUILD_MODEL_SFM_COMMAND+folderName+" "+isModel;
  118. callshell(command);
  119. log.info("计算完毕");
  120. }
  121. //obj文件转换问txt
  122. public static void objToTxt(String folderName,String isModel) throws Exception{
  123. log.info("obj2txt开始转换");
  124. String command = ConstantCmd.OBJ_TO_TXT+folderName;
  125. callshell(command);
  126. log.info("转换完毕:" + command);
  127. }
  128. public void rebuildModelFllor(String folderName, String isModel) {
  129. try{
  130. log.info("开始建模");
  131. String command = ConstantCmd.REBUILD_MODEL_FLLOR+folderName+" "+isModel;
  132. callshell(command);
  133. log.info("计算完毕");
  134. }
  135. catch(Exception e)
  136. {
  137. e.printStackTrace();
  138. }
  139. }
  140. //切图
  141. public void cutImgs(String[] imgNames ,String folderName)
  142. {
  143. try{
  144. log.info("开始切图");
  145. for(int i=0;i<imgNames.length;++i)
  146. {
  147. String imgName=imgNames[i].replace(".jpg", "");
  148. String command = ConstantCmd.CUT_IMG_COMMAND+folderName+" "+imgName;
  149. callshell(command);
  150. }
  151. log.info("切图完毕");
  152. }
  153. catch(Exception e)
  154. {
  155. e.printStackTrace();
  156. }
  157. }
  158. //调整切图
  159. public void adjustImgs(String folderName)
  160. {
  161. try{
  162. String command = ConstantCmd.ADJUST_IMG_COMMAND + folderName;
  163. log.info("开始调整图片");
  164. callshell(command);
  165. log.info("调整图片完毕");
  166. }
  167. catch(Exception e)
  168. {
  169. e.printStackTrace();
  170. }
  171. }
  172. //obj和camera转换成大场景要的格式
  173. public void convertobjTotxt(String folderName) throws Exception
  174. {
  175. //obj
  176. String command = "/home/ubuntu/photoscan-pro/main/mesh/mesh "+folderName;
  177. callshell(command);
  178. //camera
  179. command = "/home/ubuntu/photoscan-pro/main/read_camera/read_camera "+folderName;
  180. callshell(command);
  181. String prefix = ConstantFilePath.CREATE_BIG_SCENE_PATH+folderName+File.separator+"data"+File.separator;
  182. String srcpath = prefix +"mesh.txt";
  183. String despath = prefix +"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam";
  184. convertTxtToDam( srcpath, despath);
  185. //dam转换成lzma
  186. command = "lzma /home/ubuntu/photo_data/bigscene/"+folderName+"/data/dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam";
  187. callshell(command);
  188. srcpath = prefix +"vision.txt";
  189. despath = prefix +"vision.modeldata";
  190. convertTxtToVisionmodeldata( srcpath, despath);
  191. }
  192. public static void convertDamToLzma(String folderName)throws Exception
  193. {
  194. try
  195. {
  196. String command = "lzma "+ folderName+ ConstantFileName.modelUUID+"_50k.dam";
  197. log.info("开始转换lzma");
  198. callshell(command);
  199. log.info("转换lzma完毕");
  200. }
  201. catch(Exception e)
  202. {
  203. StringWriter trace=new StringWriter();
  204. e.printStackTrace(new PrintWriter(trace));
  205. log.error(trace.toString());
  206. }
  207. }
  208. public static void convertDamToLzmaByAbsolutePath(String path)throws Exception
  209. {
  210. try
  211. {
  212. String command = "lzma "+ path;
  213. log.info("开始转换lzma");
  214. callshell(command);
  215. log.info("转换lzma完毕");
  216. }
  217. catch(Exception e)
  218. {
  219. StringWriter trace=new StringWriter();
  220. e.printStackTrace(new PrintWriter(trace));
  221. log.error(trace.toString());
  222. }
  223. }
  224. public static void convertDamToLzma2(String folderName)throws Exception
  225. {
  226. try
  227. {
  228. String command = "lzma "+ folderName+File.separator+ ConstantFileName.modelUUID+"_50k2.dam";
  229. log.info("开始转换lzma");
  230. callshell(command);
  231. log.info("转换lzma完毕");
  232. }
  233. catch(Exception e)
  234. {
  235. StringWriter trace=new StringWriter();
  236. e.printStackTrace(new PrintWriter(trace));
  237. log.error(trace.toString());
  238. }
  239. }
  240. public static void convertTxtToDam(String srcpath,String despath)throws Exception{
  241. InputStream inputStream = null;
  242. InputStreamReader reader = null;
  243. ByteArrayInputStream stream = null;
  244. BufferedOutputStream bos = null;
  245. BufferedInputStream bis = null;
  246. try{
  247. BigSceneProto.binary_mesh.Builder builder = BigSceneProto.binary_mesh.newBuilder();
  248. inputStream = new FileInputStream(srcpath);
  249. reader = new InputStreamReader(inputStream, "ASCII");
  250. TextFormat.merge(reader, builder);
  251. byte[] buf = builder.build().toByteArray();
  252. //把序列化后的数据写入本地磁盘
  253. stream = new ByteArrayInputStream(buf);
  254. bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
  255. bis = new BufferedInputStream(stream);
  256. int b = -1;
  257. while ((b = bis.read()) != -1) {
  258. bos.write(b);
  259. }
  260. }catch (Exception e){
  261. log.error("txt转dam出错,srcpath:{}, despath:{}",srcpath, despath);
  262. throw e;
  263. }finally {
  264. if(inputStream != null){
  265. inputStream.close();
  266. }
  267. if(reader != null){
  268. reader.close();
  269. }
  270. if(stream != null){
  271. stream.close();
  272. }
  273. if(bos != null){
  274. bos.close();
  275. }
  276. if(bis != null){
  277. bis.close();
  278. }
  279. }
  280. }
  281. public static void convertDamToTxt(String srcpath,String despath) throws IOException {
  282. FileInputStream fis= null;
  283. ByteArrayInputStream stream = null;
  284. BufferedOutputStream bos = null;
  285. BufferedInputStream bis = null;
  286. try {
  287. fis=new FileInputStream(new File(srcpath));
  288. BigSceneProto.binary_mesh data_NavigationInfo = BigSceneProto.binary_mesh.parseFrom(fis);
  289. String jsonFormat1 = JsonFormat.printToString(data_NavigationInfo);
  290. stream = new ByteArrayInputStream(jsonFormat1.getBytes());
  291. bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
  292. bis = new BufferedInputStream(stream);
  293. int b = -1;
  294. while ((b = bis.read()) != -1) {
  295. bos.write(b);
  296. }
  297. }finally{
  298. try {
  299. if(bis != null){
  300. bis.close();
  301. }
  302. if(bos != null){
  303. bos.close();
  304. }
  305. if(fis != null){
  306. fis.close();
  307. }
  308. }catch (Exception e){
  309. log.error("关闭文件流报错", e);
  310. }
  311. }
  312. }
  313. public static void main(String[] args) throws Exception {
  314. // convertVisionmodeldataToTxt("D:\\test\\test\\vision.modeldata", "D:\\test\\test\\vision.txt");
  315. // FileUtil.del("D:\\test\\test");
  316. convertTxtToVisionmodeldata("D:\\test\\vision_100(1).txt", "D:\\test\\vision_100.modeldata");
  317. }
  318. public static void convertVisionmodeldataToTxt(String srcpath,String despath)throws Exception {
  319. try (FileInputStream fis = new FileInputStream(srcpath)){
  320. Visionmodeldata.NavigationInfo data_NavigationInfo = Visionmodeldata.NavigationInfo.parseFrom(fis);
  321. String jsonFormat1 = JsonFormat.printToString(data_NavigationInfo);
  322. try (
  323. ByteArrayInputStream stream = new ByteArrayInputStream(jsonFormat1.getBytes());
  324. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
  325. BufferedInputStream bis = new BufferedInputStream(stream)
  326. ){
  327. int b = -1;
  328. while ((b = bis.read()) != -1) {
  329. bos.write(b);
  330. }
  331. }
  332. }
  333. }
  334. public static void convertTxtToVisionmodeldata(String srcpath,String despath)throws Exception
  335. {
  336. try{
  337. Visionmodeldata.NavigationInfo.Builder builder = Visionmodeldata.NavigationInfo.newBuilder();
  338. String jsonFormat = readTxtFileToJson(srcpath);
  339. JsonFormat.merge(jsonFormat, builder);
  340. byte[] buf= builder.build().toByteArray();
  341. //把序列化后的数据写入本地磁盘
  342. ByteArrayInputStream stream = new ByteArrayInputStream(buf);
  343. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
  344. BufferedInputStream bis = new BufferedInputStream(stream);
  345. int b = -1;
  346. while ((b = bis.read()) != -1) {
  347. bos.write(b);
  348. }
  349. bis.close();
  350. bos.close();
  351. }
  352. catch(Exception e)
  353. {
  354. StringWriter trace=new StringWriter();
  355. e.printStackTrace(new PrintWriter(trace));
  356. log.error(trace.toString());
  357. }
  358. }
  359. public static void convertVisionmodeldataToTxtCommon(String srcpath,String despath)throws Exception
  360. {
  361. try
  362. {
  363. File file = new File(srcpath);
  364. FileInputStream fis=new FileInputStream(file);
  365. Common.NavigationInfo data_NavigationInfo = Common.NavigationInfo.parseFrom(fis);
  366. //PrintStream out = new PrintStream(despath);
  367. String jsonFormat1 = JsonFormat.printToString(data_NavigationInfo);
  368. ByteArrayInputStream stream = new ByteArrayInputStream(jsonFormat1.getBytes());
  369. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
  370. BufferedInputStream bis = new BufferedInputStream(stream);
  371. int b = -1;
  372. while ((b = bis.read()) != -1) {
  373. bos.write(b);
  374. }
  375. //out.close();
  376. bis.close();
  377. bos.close();
  378. }
  379. catch(Exception e)
  380. {
  381. StringWriter trace=new StringWriter();
  382. e.printStackTrace(new PrintWriter(trace));
  383. log.error(trace.toString());
  384. }
  385. }
  386. public static void convertTxtToVisionmodeldataCommon(String srcpath,String despath)throws Exception
  387. {
  388. try
  389. {
  390. Common.NavigationInfo.Builder builder = Common.NavigationInfo.newBuilder();
  391. String jsonFormat = readTxtFileToJson(srcpath);
  392. JsonFormat.merge(jsonFormat, builder);
  393. byte[] buf= builder.build().toByteArray();
  394. //把序列化后的数据写入本地磁盘
  395. ByteArrayInputStream stream = new ByteArrayInputStream(buf);
  396. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
  397. BufferedInputStream bis = new BufferedInputStream(stream);
  398. int b = -1;
  399. while ((b = bis.read()) != -1) {
  400. bos.write(b);
  401. }
  402. bis.close();
  403. bos.close();
  404. }
  405. catch(Exception e)
  406. {
  407. StringWriter trace=new StringWriter();
  408. e.printStackTrace(new PrintWriter(trace));
  409. log.error(trace.toString());
  410. }
  411. }
  412. public static void callshell(String command){
  413. try {
  414. Long start = System.currentTimeMillis();
  415. Process process = Runtime.getRuntime().exec(command);
  416. StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
  417. errorGobbler.start();
  418. StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
  419. outGobbler.start();
  420. process.waitFor();
  421. log.info("脚本{}执行完毕,用时:{}ms",command,System.currentTimeMillis()-start);
  422. } catch (Exception e) {
  423. e.printStackTrace();
  424. }
  425. }
  426. public static int doWaitFor(Process process) {
  427. InputStream in = null;
  428. InputStream err = null;
  429. int exitValue = -1; // returned to caller when p is finished
  430. try {
  431. in = process.getInputStream();
  432. err = process.getErrorStream();
  433. boolean finished = false; // Set to true when p is finished
  434. while (!finished) {
  435. try {
  436. while (in.available() > 0) {
  437. // Print the output of our system call
  438. Character c = new Character((char) in.read());
  439. System.out.print(c);
  440. }
  441. while (err.available() > 0) {
  442. // Print the output of our system call
  443. Character c = new Character((char) err.read());
  444. System.out.print(c);
  445. }
  446. // Ask the process for its exitValue. If the process
  447. // is not finished, an IllegalThreadStateException
  448. // is thrown. If it is finished, we fall through and
  449. // the variable finished is set to true.
  450. exitValue = process.exitValue();
  451. finished = true;
  452. } catch (IllegalThreadStateException e) {
  453. // Process is not finished yet;
  454. // Sleep a little to save on CPU cycles
  455. Thread.currentThread().sleep(500);
  456. }
  457. }
  458. } catch (Exception e) {
  459. e.printStackTrace();
  460. } finally {
  461. try {
  462. if (in != null) {
  463. in.close();
  464. }
  465. } catch (IOException e) {
  466. e.printStackTrace();
  467. }
  468. if (err != null) {
  469. try {
  470. err.close();
  471. } catch (IOException e) {
  472. e.printStackTrace();
  473. }
  474. }
  475. }
  476. return exitValue;
  477. }
  478. private boolean isModel(String sPath,String folderName)
  479. {
  480. boolean flag = false;
  481. File file = new File(sPath);
  482. if (file.isFile() && file.exists()) {
  483. flag = true;
  484. }
  485. log.info("等待...");
  486. return flag;
  487. }
  488. public static String readTxtFileToJson(String filePath){
  489. try {
  490. String encoding="UTF-8";
  491. File file=new File(filePath);
  492. if(file.isFile() && file.exists()){
  493. InputStreamReader read = new InputStreamReader(
  494. new FileInputStream(file),encoding);
  495. BufferedReader bufferedReader = new BufferedReader(read);
  496. String lineTxt = null;
  497. String result="";
  498. while((lineTxt = bufferedReader.readLine()) != null){
  499. result+=lineTxt;
  500. //log.info(lineTxt);
  501. }
  502. read.close();
  503. return result;
  504. }else{
  505. return null;
  506. }
  507. } catch (Exception e) {
  508. e.printStackTrace();
  509. return null;
  510. }
  511. }
  512. public Map<String,String> getAllFile(String dPath,String prefix)
  513. {
  514. File dirFile = new File(dPath);
  515. if (!dirFile.isDirectory()) {
  516. }
  517. Map<String,String> map = new HashMap<String,String>();
  518. File[] files = dirFile.listFiles();
  519. for (int i = 0; i < files.length; i++) {
  520. if (files[i].isFile()) {
  521. String path = files[i].getPath();
  522. map.put(path, prefix+path.substring(path.lastIndexOf("/")+1));
  523. }
  524. }
  525. return map;
  526. }
  527. public Map<String,String> getchildFile(String dPath,String prefix,String childname)
  528. {
  529. File dirFile = new File(dPath+File.separator+childname);
  530. if (!dirFile.isDirectory()) {
  531. return null;
  532. }
  533. Map<String,String> map = new HashMap<String,String>();
  534. File[] files = dirFile.listFiles();
  535. for (int i = 0; i < files.length; i++) {
  536. if (files[i].isFile()) {
  537. String path = files[i].getPath();
  538. map.put(path, prefix+childname+path.substring(path.lastIndexOf("/")));
  539. }
  540. }
  541. return map;
  542. }
  543. //转台拼图
  544. public void buildPanoramicImgs(String folderName)throws Exception
  545. {
  546. String command = ConstantCmd.BUILD_PANORAMA + folderName;
  547. log.info("开始拼全景图");
  548. callshell(command);
  549. log.info("全景图拼接完毕");
  550. }
  551. //六目拼图、切图,计算
  552. public void buildForSix(String folderName)throws Exception
  553. {
  554. String command = ConstantCmd.BUILD_FOR_SIX + folderName;
  555. log.info("开始处理数据(六目)");
  556. callshell(command);
  557. log.info("数据处理完毕(六目)");
  558. }
  559. public static void createSoftConnection(String source, String target) {
  560. String command = "ln -s " + source + " " + target;
  561. log.info("开始创建文件夹软连接");
  562. callshell(command);
  563. log.info("数据处理完毕(六目):" + command);
  564. }
  565. //合并音频
  566. public static void mergeVideo(String oldVideo , String newVideo, String targetVideo) throws Exception{
  567. String command = ConstantCmd.MERGE_VIDEO + " " + oldVideo + " " + newVideo + " " + targetVideo + " -y";
  568. log.info("开始合并视频");
  569. callshell(command);
  570. log.info("合并视频完毕:" + command);
  571. }
  572. //生成一段静音音频
  573. public static void createMuteViode(double time , String targetVideo) throws Exception{
  574. String command = ConstantCmd.CREATE_MUTE_VIDEO + " " + time + " " + targetVideo + " -y";
  575. log.info("开始生成一段静音音频");
  576. callshell(command);
  577. log.info("生成一段静音音频完毕:" + command);
  578. }
  579. //mp4文件转换成flv文件
  580. public static void mp4ToFlv(String oldVideo, String newVideo) throws Exception{
  581. String command = ConstantCmd.MP4_TO_FLV + " " + oldVideo + " " + newVideo;
  582. log.info("mp4文件转换成flv文件");
  583. callshell(command);
  584. log.info("mp4文件转换成flv文件完毕:" + command);
  585. }
  586. public static void formatMp4(String oldVideo, String newVideo) throws Exception{
  587. String command = ConstantCmd.FORMAT_MP4 + " " + oldVideo + " " + newVideo;
  588. log.info("mp4格式转换开始:{}", command);
  589. callshell(command);
  590. log.info("mp4格式转换完毕:{}", command);
  591. }
  592. //删除/mnt/data/下的数据
  593. public static void deleteFile(String filePath) throws Exception{
  594. String command = ConstantCmd.DELETE_FILE + " " + filePath;
  595. log.info("删除/mnt/data/下的数据");
  596. callshell(command);
  597. log.info("删除/mnt/data/下的数据完毕:" + command);
  598. }
  599. public static void ossUtilCp(String fileUrl , String path) throws Exception{
  600. String command = ConstantCmd.OSS_UTIL_CP + " " + fileUrl + " " + path;
  601. Long start = System.currentTimeMillis();
  602. log.info("开始oss下载文件:" + command);
  603. callshell(command);
  604. log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
  605. }
  606. /**
  607. * oss文件下载,支持目录或者单个文件下载
  608. * @param fyunType oss类型(oss, aws)
  609. * @param bucket oss桶名
  610. * @param remoteFilePath key
  611. * @param path 本地路径
  612. * @throws Exception
  613. */
  614. public static void ossDownload(String fyunType, String bucket, String remoteFilePath , String path) throws Exception{
  615. String optType = remoteFilePath.contains(".") ? "file" : "folder";
  616. String command = String.format(ConstantCmd.FYUN_DOWNLOAD, bucket, remoteFilePath, path, fyunType, optType);
  617. Long start = System.currentTimeMillis();
  618. log.info("开始oss下载文件:" + command);
  619. callshell(command);
  620. log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
  621. }
  622. /**
  623. * oss文件上传,支持目录或者单个文件上传
  624. * @param fyunType oss类型(oss, aws)
  625. * @param bucket oss桶名
  626. * @param remoteFilePath key
  627. * @param path 本地路径
  628. * @throws Exception
  629. */
  630. public static void ossUpload(String fyunType, String bucket, String remoteFilePath , String path) throws Exception{
  631. String optType = remoteFilePath.contains(".") ? "file" : "folder";
  632. String command = String.format(ConstantCmd.FYUN_UPLOAD, bucket, path, remoteFilePath, fyunType, optType);
  633. Long start = System.currentTimeMillis();
  634. log.info("开始oss上传文件:" + command);
  635. callshell(command);
  636. log.info("oss上传文件完成,时间为:" + (System.currentTimeMillis() - start));
  637. }
  638. public static void ossFileCp(String fileUrl , String path) throws Exception{
  639. String command = ConstantCmd.OSS_FILE_CP + " " + fileUrl + " " + path;
  640. Long start = System.currentTimeMillis();
  641. log.info("开始s3文件下载文件:" + command);
  642. callshell(command);
  643. log.info("s3文件下载文件完成,时间为:" + (System.currentTimeMillis() - start));
  644. }
  645. /**
  646. * matterpro场景获取阿里云的切图数据
  647. * @param path
  648. * @throws Exception
  649. */
  650. public static void matterproCutImg(String num , String path) throws Exception{
  651. String command = ConstantCmd.MATTERPRO_CUT_IMG + " -s " + num + " -d " + path;
  652. Long start = System.currentTimeMillis();
  653. log.info("开始matterpro获取阿里云图片方法:" + command);
  654. callshell(command);
  655. log.info("matterpro获取阿里云图片方法完成,时间为:" + (System.currentTimeMillis() - start));
  656. }
  657. }