test.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //package com.fdkk.fdkkmeta.test;
  2. //
  3. //import cn.hutool.core.date.DateUtil;
  4. //import cn.hutool.core.io.BufferUtil;
  5. //import cn.hutool.core.io.FileUtil;
  6. //import cn.hutool.core.io.IORuntimeException;
  7. //import cn.hutool.core.io.IoUtil;
  8. //import cn.hutool.core.io.file.FileWriter;
  9. //import cn.hutool.core.lang.Console;
  10. //import cn.hutool.core.util.StrUtil;
  11. //import cn.hutool.core.util.URLUtil;
  12. //import cn.hutool.log.StaticLog;
  13. //import cn.hutool.socket.aio.AioServer;
  14. //import cn.hutool.socket.aio.AioSession;
  15. //import cn.hutool.socket.aio.SimpleIoAction;
  16. //import cn.hutool.socket.nio.NioServer;
  17. //import com.alibaba.fastjson.JSON;
  18. //import com.alibaba.fastjson.JSONArray;
  19. //import com.alibaba.fastjson.JSONObject;
  20. //import com.fdkk.fdkkmeta.po.RoutePO;
  21. //import com.fdkk.fdkkmeta.util.FileUtils;
  22. //import org.bytedeco.ffmpeg.global.avcodec;
  23. //import org.bytedeco.javacv.FFmpegFrameGrabber;
  24. //import org.bytedeco.javacv.FFmpegFrameRecorder;
  25. //import org.bytedeco.javacv.Frame;
  26. //
  27. //import java.io.*;
  28. //import java.nio.ByteBuffer;
  29. //import java.nio.charset.Charset;
  30. //import java.text.SimpleDateFormat;
  31. //import java.util.*;
  32. //import java.util.stream.Collectors;
  33. //
  34. ///**
  35. // * @author Xiewj
  36. // * @date 2022/3/29
  37. // */
  38. //public class test {
  39. //// public static void main(String[] args) throws IOException {
  40. //// int d=6;
  41. //// int fps=2 % d;
  42. //// if (fps!=0){
  43. //// fps=2/d+1;
  44. //// }
  45. ////
  46. //// System.out.println(fps);
  47. ////
  48. //// }
  49. // public static void main(String[] args) throws IOException {
  50. //
  51. // NioServer server = new NioServer(9099);
  52. // server.setChannelHandler((sc)->{
  53. // ByteBuffer readBuffer = ByteBuffer.allocate(1024);
  54. // try{
  55. // //从channel读数据到缓冲区
  56. // int readBytes = sc.read(readBuffer);
  57. // if (readBytes > 0) {
  58. // //Flips this buffer. The limit is set to the current position and then
  59. // // the position is set to zero,就是表示要从起始位置开始读取数据
  60. // readBuffer.flip();
  61. // //eturns the number of elements between the current position and the limit.
  62. // // 要读取的字节长度
  63. // byte[] bytes = new byte[readBuffer.remaining()];
  64. // //将缓冲区的数据读到bytes数组
  65. // readBuffer.get(bytes);
  66. // String body = StrUtil.utf8Str(bytes);
  67. // Console.log("[{}]: {}", sc.getRemoteAddress(), body);
  68. // String outputFile = "rtmp://demo-kms.4dage.com/live/test12";
  69. // try {
  70. // frameRecord(sc.socket().getInputStream(), outputFile, 1);
  71. // } catch (Exception e) {
  72. // e.printStackTrace();
  73. // }
  74. // } else if (readBytes < 0) {
  75. // IoUtil.close(sc);
  76. // }
  77. // } catch (IOException e){
  78. // throw new IORuntimeException(e);
  79. // }
  80. // });
  81. // server.listen();
  82. // }
  83. // /**
  84. // * 按帧录制视频
  85. // *
  86. // * @param inputFile-该地址可以是网络直播/录播地址,也可以是远程/本地文件路径
  87. // * @param outputFile
  88. // * -该地址只能是文件地址,如果使用该方法推送流媒体服务器会报错,原因是没有设置编码格式
  89. // * @throws org.bytedeco.javacv.FrameRecorder.Exception
  90. // */
  91. // public static void frameRecord(InputStream inputFile, String outputFile, int audioChannel)
  92. // throws Exception, org.bytedeco.javacv.FrameRecorder.Exception {
  93. // boolean isStart=true;//该变量建议设置为全局控制变量,用于控制录制结束
  94. // // 获取视频源
  95. // FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
  96. // grabber.setOption("rtsp_transport", "tcp");
  97. // // 流媒体输出地址,分辨率(长,高),是否录制音频(0:不录制/1:录制)
  98. // FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile, 1280, 720, audioChannel);
  99. // recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
  100. // recorder.setFormat("flv");
  101. // // 开始取视频源
  102. // recordByFrame(grabber, recorder, isStart);
  103. // }
  104. // private static void recordByFrame(FFmpegFrameGrabber grabber, FFmpegFrameRecorder recorder, Boolean status)
  105. // throws Exception, org.bytedeco.javacv.FrameRecorder.Exception {
  106. // try {//建议在线程中使用该方法
  107. // grabber.start();
  108. // recorder.start();
  109. // Frame frame =null ;
  110. // while (status&& (frame = grabber.grabFrame()) != null) {
  111. // recorder.record(frame);
  112. // }
  113. // recorder.stop();
  114. // grabber.stop();
  115. // } finally {
  116. // if (grabber != null) {
  117. // grabber.stop();
  118. // }
  119. // }
  120. // }
  121. //
  122. //
  123. // private static void createdPointsJson(String path) {
  124. // List<String> list = FileUtils.readFileByLines2(path);
  125. // JSONArray array=new JSONArray();
  126. // FileWriter writer=new FileWriter("D:\\video\\points.json");
  127. // for (int i = 0; i < list.size(); i++) {
  128. // JSONObject jsonObject=new JSONObject();
  129. // String[] s = list.get(i).split(" ");
  130. // jsonObject.put("id",i );
  131. // JSONObject position=new JSONObject();
  132. // position.put("x",Double.valueOf(s[0]));
  133. // position.put("y",Double.valueOf(s[1]));
  134. // position.put("z",Double.valueOf(s[2]));
  135. // jsonObject.put("position",position);
  136. // JSONObject rotation=new JSONObject();
  137. // rotation.put("x",0.0);
  138. // rotation.put("y",0.0);
  139. // rotation.put("z",0.0);
  140. // rotation.put("w",1.0);
  141. // jsonObject.put("rotation",rotation);
  142. // List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
  143. // List<Integer> contact = strings.stream().filter(a -> !a.equals("-1")).map(a->{
  144. // return Integer.parseInt(a)-1;
  145. // }).collect(Collectors.toList());
  146. // jsonObject.put("contact",contact);
  147. // array.add(jsonObject);
  148. // }
  149. // writer.write(array.toJSONString());
  150. // }
  151. //
  152. // private static void creatTargetJson(String path) {
  153. // List<String> list = FileUtils.readFileByLines2(path);
  154. // List<String> collect = new ArrayList<>();
  155. // FileWriter writer=new FileWriter("D:\\video\\target_freespace.json");
  156. // for (int i = 0; i < list.size(); i++) {
  157. // RoutePO po = new RoutePO();
  158. // String[] s = list.get(i).split(" ");
  159. // po.setId(i );
  160. // if (s.length == 12) {
  161. // double[] oldPoint = {Double.valueOf(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2])};
  162. // po.setX(oldPoint[0]);
  163. // po.setY(oldPoint[1]);
  164. // po.setZ(oldPoint[2]);
  165. // po.setWeight(Double.parseDouble(s[3]));
  166. // List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
  167. // List<Integer> contact = strings.stream().map(a->{
  168. // if (Integer.parseInt(a)!=-1){
  169. // return Integer.parseInt(a)-1;
  170. // }
  171. // return Integer.parseInt(a);
  172. // }).collect(Collectors.toList());
  173. // po.setIds(contact);
  174. // }
  175. // collect.add(JSON.toJSONString(po));
  176. // }
  177. // writer.writeLines(collect);
  178. // }
  179. //}