|
@@ -1,97 +1,179 @@
|
|
|
-package com.fdkk.fdkkmeta.test;
|
|
|
-
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.io.file.FileWriter;
|
|
|
-import cn.hutool.core.util.URLUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.fdkk.fdkkmeta.po.RoutePO;
|
|
|
-import com.fdkk.fdkkmeta.util.FileUtils;
|
|
|
-
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.nio.charset.Charset;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author Xiewj
|
|
|
- * @date 2022/3/29
|
|
|
- */
|
|
|
-public class test {
|
|
|
+//package com.fdkk.fdkkmeta.test;
|
|
|
+//
|
|
|
+//import cn.hutool.core.date.DateUtil;
|
|
|
+//import cn.hutool.core.io.BufferUtil;
|
|
|
+//import cn.hutool.core.io.FileUtil;
|
|
|
+//import cn.hutool.core.io.IORuntimeException;
|
|
|
+//import cn.hutool.core.io.IoUtil;
|
|
|
+//import cn.hutool.core.io.file.FileWriter;
|
|
|
+//import cn.hutool.core.lang.Console;
|
|
|
+//import cn.hutool.core.util.StrUtil;
|
|
|
+//import cn.hutool.core.util.URLUtil;
|
|
|
+//import cn.hutool.log.StaticLog;
|
|
|
+//import cn.hutool.socket.aio.AioServer;
|
|
|
+//import cn.hutool.socket.aio.AioSession;
|
|
|
+//import cn.hutool.socket.aio.SimpleIoAction;
|
|
|
+//import cn.hutool.socket.nio.NioServer;
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
+//import com.alibaba.fastjson.JSONArray;
|
|
|
+//import com.alibaba.fastjson.JSONObject;
|
|
|
+//import com.fdkk.fdkkmeta.po.RoutePO;
|
|
|
+//import com.fdkk.fdkkmeta.util.FileUtils;
|
|
|
+//import org.bytedeco.ffmpeg.global.avcodec;
|
|
|
+//import org.bytedeco.javacv.FFmpegFrameGrabber;
|
|
|
+//import org.bytedeco.javacv.FFmpegFrameRecorder;
|
|
|
+//import org.bytedeco.javacv.Frame;
|
|
|
+//
|
|
|
+//import java.io.*;
|
|
|
+//import java.nio.ByteBuffer;
|
|
|
+//import java.nio.charset.Charset;
|
|
|
+//import java.text.SimpleDateFormat;
|
|
|
+//import java.util.*;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @author Xiewj
|
|
|
+// * @date 2022/3/29
|
|
|
+// */
|
|
|
+//public class test {
|
|
|
+//// public static void main(String[] args) throws IOException {
|
|
|
+//// int d=6;
|
|
|
+//// int fps=2 % d;
|
|
|
+//// if (fps!=0){
|
|
|
+//// fps=2/d+1;
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// System.out.println(fps);
|
|
|
+////
|
|
|
+//// }
|
|
|
// public static void main(String[] args) throws IOException {
|
|
|
-// int d=6;
|
|
|
-// int fps=2 % d;
|
|
|
-// if (fps!=0){
|
|
|
-// fps=2/d+1;
|
|
|
+//
|
|
|
+// NioServer server = new NioServer(9099);
|
|
|
+// server.setChannelHandler((sc)->{
|
|
|
+// ByteBuffer readBuffer = ByteBuffer.allocate(1024);
|
|
|
+// try{
|
|
|
+// //从channel读数据到缓冲区
|
|
|
+// int readBytes = sc.read(readBuffer);
|
|
|
+// if (readBytes > 0) {
|
|
|
+// //Flips this buffer. The limit is set to the current position and then
|
|
|
+// // the position is set to zero,就是表示要从起始位置开始读取数据
|
|
|
+// readBuffer.flip();
|
|
|
+// //eturns the number of elements between the current position and the limit.
|
|
|
+// // 要读取的字节长度
|
|
|
+// byte[] bytes = new byte[readBuffer.remaining()];
|
|
|
+// //将缓冲区的数据读到bytes数组
|
|
|
+// readBuffer.get(bytes);
|
|
|
+// String body = StrUtil.utf8Str(bytes);
|
|
|
+// Console.log("[{}]: {}", sc.getRemoteAddress(), body);
|
|
|
+// String outputFile = "rtmp://demo-kms.4dage.com/live/test12";
|
|
|
+// try {
|
|
|
+// frameRecord(sc.socket().getInputStream(), outputFile, 1);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// } else if (readBytes < 0) {
|
|
|
+// IoUtil.close(sc);
|
|
|
+// }
|
|
|
+// } catch (IOException e){
|
|
|
+// throw new IORuntimeException(e);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// server.listen();
|
|
|
+// }
|
|
|
+// /**
|
|
|
+// * 按帧录制视频
|
|
|
+// *
|
|
|
+// * @param inputFile-该地址可以是网络直播/录播地址,也可以是远程/本地文件路径
|
|
|
+// * @param outputFile
|
|
|
+// * -该地址只能是文件地址,如果使用该方法推送流媒体服务器会报错,原因是没有设置编码格式
|
|
|
+// * @throws org.bytedeco.javacv.FrameRecorder.Exception
|
|
|
+// */
|
|
|
+// public static void frameRecord(InputStream inputFile, String outputFile, int audioChannel)
|
|
|
+// throws Exception, org.bytedeco.javacv.FrameRecorder.Exception {
|
|
|
+// boolean isStart=true;//该变量建议设置为全局控制变量,用于控制录制结束
|
|
|
+// // 获取视频源
|
|
|
+// FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
|
|
|
+// grabber.setOption("rtsp_transport", "tcp");
|
|
|
+// // 流媒体输出地址,分辨率(长,高),是否录制音频(0:不录制/1:录制)
|
|
|
+// FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile, 1280, 720, audioChannel);
|
|
|
+// recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
|
|
|
+// recorder.setFormat("flv");
|
|
|
+// // 开始取视频源
|
|
|
+// recordByFrame(grabber, recorder, isStart);
|
|
|
+// }
|
|
|
+// private static void recordByFrame(FFmpegFrameGrabber grabber, FFmpegFrameRecorder recorder, Boolean status)
|
|
|
+// throws Exception, org.bytedeco.javacv.FrameRecorder.Exception {
|
|
|
+// try {//建议在线程中使用该方法
|
|
|
+// grabber.start();
|
|
|
+// recorder.start();
|
|
|
+// Frame frame =null ;
|
|
|
+// while (status&& (frame = grabber.grabFrame()) != null) {
|
|
|
+// recorder.record(frame);
|
|
|
+// }
|
|
|
+// recorder.stop();
|
|
|
+// grabber.stop();
|
|
|
+// } finally {
|
|
|
+// if (grabber != null) {
|
|
|
+// grabber.stop();
|
|
|
+// }
|
|
|
// }
|
|
|
+// }
|
|
|
//
|
|
|
-// System.out.println(fps);
|
|
|
//
|
|
|
+// private static void createdPointsJson(String path) {
|
|
|
+// List<String> list = FileUtils.readFileByLines2(path);
|
|
|
+// JSONArray array=new JSONArray();
|
|
|
+// FileWriter writer=new FileWriter("D:\\video\\points.json");
|
|
|
+// for (int i = 0; i < list.size(); i++) {
|
|
|
+// JSONObject jsonObject=new JSONObject();
|
|
|
+// String[] s = list.get(i).split(" ");
|
|
|
+// jsonObject.put("id",i );
|
|
|
+// JSONObject position=new JSONObject();
|
|
|
+// position.put("x",Double.valueOf(s[0]));
|
|
|
+// position.put("y",Double.valueOf(s[1]));
|
|
|
+// position.put("z",Double.valueOf(s[2]));
|
|
|
+// jsonObject.put("position",position);
|
|
|
+// JSONObject rotation=new JSONObject();
|
|
|
+// rotation.put("x",0.0);
|
|
|
+// rotation.put("y",0.0);
|
|
|
+// rotation.put("z",0.0);
|
|
|
+// rotation.put("w",1.0);
|
|
|
+// jsonObject.put("rotation",rotation);
|
|
|
+// List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
|
|
|
+// List<Integer> contact = strings.stream().filter(a -> !a.equals("-1")).map(a->{
|
|
|
+// return Integer.parseInt(a)-1;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// jsonObject.put("contact",contact);
|
|
|
+// array.add(jsonObject);
|
|
|
+// }
|
|
|
+// writer.write(array.toJSONString());
|
|
|
+// }
|
|
|
+//
|
|
|
+// private static void creatTargetJson(String path) {
|
|
|
+// List<String> list = FileUtils.readFileByLines2(path);
|
|
|
+// List<String> collect = new ArrayList<>();
|
|
|
+// FileWriter writer=new FileWriter("D:\\video\\target_freespace.json");
|
|
|
+// for (int i = 0; i < list.size(); i++) {
|
|
|
+// RoutePO po = new RoutePO();
|
|
|
+// String[] s = list.get(i).split(" ");
|
|
|
+// po.setId(i );
|
|
|
+// if (s.length == 12) {
|
|
|
+// double[] oldPoint = {Double.valueOf(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2])};
|
|
|
+// po.setX(oldPoint[0]);
|
|
|
+// po.setY(oldPoint[1]);
|
|
|
+// po.setZ(oldPoint[2]);
|
|
|
+// po.setWeight(Double.parseDouble(s[3]));
|
|
|
+// List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
|
|
|
+// List<Integer> contact = strings.stream().map(a->{
|
|
|
+// if (Integer.parseInt(a)!=-1){
|
|
|
+// return Integer.parseInt(a)-1;
|
|
|
+// }
|
|
|
+// return Integer.parseInt(a);
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// po.setIds(contact);
|
|
|
+// }
|
|
|
+// collect.add(JSON.toJSONString(po));
|
|
|
+// }
|
|
|
+// writer.writeLines(collect);
|
|
|
// }
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
- String path="C:\\Users\\4DAGE\\Downloads\\final_freespace(1).csv";
|
|
|
- createdPointsJson(path);
|
|
|
- creatTargetJson(path);
|
|
|
- }
|
|
|
-
|
|
|
- private static void createdPointsJson(String path) {
|
|
|
- List<String> list = FileUtils.readFileByLines2(path);
|
|
|
- JSONArray array=new JSONArray();
|
|
|
- FileWriter writer=new FileWriter("D:\\video\\points.json");
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- JSONObject jsonObject=new JSONObject();
|
|
|
- String[] s = list.get(i).split(" ");
|
|
|
- jsonObject.put("id",i );
|
|
|
- JSONObject position=new JSONObject();
|
|
|
- position.put("x",Double.valueOf(s[0]));
|
|
|
- position.put("y",Double.valueOf(s[1]));
|
|
|
- position.put("z",Double.valueOf(s[2]));
|
|
|
- jsonObject.put("position",position);
|
|
|
- JSONObject rotation=new JSONObject();
|
|
|
- rotation.put("x",0.0);
|
|
|
- rotation.put("y",0.0);
|
|
|
- rotation.put("z",0.0);
|
|
|
- rotation.put("w",1.0);
|
|
|
- jsonObject.put("rotation",rotation);
|
|
|
- List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
|
|
|
- List<Integer> contact = strings.stream().filter(a -> !a.equals("-1")).map(a->{
|
|
|
- return Integer.parseInt(a)-1;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- jsonObject.put("contact",contact);
|
|
|
- array.add(jsonObject);
|
|
|
- }
|
|
|
- writer.write(array.toJSONString());
|
|
|
- }
|
|
|
-
|
|
|
- private static void creatTargetJson(String path) {
|
|
|
- List<String> list = FileUtils.readFileByLines2(path);
|
|
|
- List<String> collect = new ArrayList<>();
|
|
|
- FileWriter writer=new FileWriter("D:\\video\\target_freespace.json");
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- RoutePO po = new RoutePO();
|
|
|
- String[] s = list.get(i).split(" ");
|
|
|
- po.setId(i );
|
|
|
- if (s.length == 12) {
|
|
|
- double[] oldPoint = {Double.valueOf(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2])};
|
|
|
- po.setX(oldPoint[0]);
|
|
|
- po.setY(oldPoint[1]);
|
|
|
- po.setZ(oldPoint[2]);
|
|
|
- po.setWeight(Double.parseDouble(s[3]));
|
|
|
- List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
|
|
|
- List<Integer> contact = strings.stream().map(a->{
|
|
|
- if (Integer.parseInt(a)!=-1){
|
|
|
- return Integer.parseInt(a)-1;
|
|
|
- }
|
|
|
- return Integer.parseInt(a);
|
|
|
- }).collect(Collectors.toList());
|
|
|
- po.setIds(contact);
|
|
|
- }
|
|
|
- collect.add(JSON.toJSONString(po));
|
|
|
- }
|
|
|
- writer.writeLines(collect);
|
|
|
- }
|
|
|
-}
|
|
|
+//}
|