Modify Websocket GET BASE64 mechanism to get concise FPS between HQ and LQ.
Support multiple quality between users.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package Other;
|
||||
|
||||
import org.bytedeco.javacpp.Loader;
|
||||
import org.bytedeco.javacv.Frame;
|
||||
import org.bytedeco.javacv.Java2DFrameConverter;
|
||||
import org.bytedeco.javacv.OpenCVFrameConverter;
|
||||
@@ -8,10 +9,12 @@ import org.bytedeco.opencv.global.opencv_imgproc;
|
||||
import org.bytedeco.opencv.opencv_core.Mat;
|
||||
import org.bytedeco.opencv.opencv_core.Size;
|
||||
import org.bytedeco.opencv.opencv_core.UMat;
|
||||
import org.bytedeco.opencv.opencv_java;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.opencv.core.MatOfByte;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
@@ -19,19 +22,26 @@ import java.net.InetAddress;
|
||||
import java.nio.file.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
import java.util.Properties;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SomeCodes {
|
||||
static{
|
||||
Loader.load(opencv_java.class);
|
||||
}
|
||||
|
||||
public final static String currentDirectory = System.getProperty("user.dir");
|
||||
public final static Path audioPath = Path.of(currentDirectory, "audiofiles");
|
||||
private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
public static final OpenCVFrameConverter.ToMat matConverter = new OpenCVFrameConverter.ToMat();
|
||||
public static final OpenCVFrameConverter.ToOrgOpenCvCoreMat CoreMatConverter = new OpenCVFrameConverter.ToOrgOpenCvCoreMat();
|
||||
|
||||
public static final Java2DFrameConverter frameConverter = new Java2DFrameConverter();
|
||||
public static final Path logsPath = Path.of(currentDirectory, "logs");
|
||||
public static final boolean haveOpenCL = opencv_core.haveOpenCL();
|
||||
public static boolean useOpenCL;
|
||||
|
||||
private static final Base64.Encoder base64encoder = java.util.Base64.getEncoder();
|
||||
|
||||
public static String[] GetAudioFiles(){
|
||||
try{
|
||||
@@ -168,31 +178,28 @@ public class SomeCodes {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static BufferedImage FrameToBufferedImage(Frame frame){
|
||||
return frameConverter.getBufferedImage(frame);
|
||||
}
|
||||
|
||||
public static BufferedImage MatToBufferedImage(Mat mat){
|
||||
return frameConverter.getBufferedImage(matConverter.convert(mat));
|
||||
}
|
||||
|
||||
public static String BufferedImageToBase64(BufferedImage image){
|
||||
if (image!=null){
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try{
|
||||
javax.imageio.ImageIO.write(image, "jpg", baos);
|
||||
baos.flush();
|
||||
byte[] imageInByte = baos.toByteArray();
|
||||
baos.close();
|
||||
return java.util.Base64.getEncoder().encodeToString(imageInByte);
|
||||
} catch (Exception e){
|
||||
Logger.error("Error converting BufferedImage to Base64: "+e.getMessage());
|
||||
// Function ini pakai opencv, bukan javacv, jadi perlu Loader.load(opencv_java.class) di awal
|
||||
// lebih optimal untuk konversi frame ke base64
|
||||
public static String FrameToBase64(Frame frame){
|
||||
if (frame!=null){
|
||||
org.opencv.core.Mat converted = CoreMatConverter.convert(frame);
|
||||
if (converted!=null){
|
||||
if (!converted.empty()){
|
||||
MatOfByte mob = new MatOfByte();
|
||||
Imgcodecs.imencode(".jpg", converted, mob);
|
||||
byte[] jpgdata = mob.toArray();
|
||||
mob.release();
|
||||
converted.release();
|
||||
return base64encoder.encodeToString(jpgdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static @NotNull Properties LoadProperties(String filename){
|
||||
try{
|
||||
InputStream is = new FileInputStream(filename);
|
||||
|
||||
Reference in New Issue
Block a user