Java怎么提升视频质量,比如我有个视频,但清晰度很低。想用JavaCV或者其它库,怎么提升视频清晰度,降噪等等,谢谢。
用JavaCV试了,效果但效果不太好。
代码如下:
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameGrabber.Exception;
import org.bytedeco.javacv.FrameRecorder;
import org.bytedeco.javacv.OpenCVFrameConverter;
import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.Mat;
public void local(String videoFilePath) {
log.info("start...");
var videoFile = new File(videoFilePath);
if (!videoFile.exists()) {
log.info("{}: file no exists!", videoFilePath);
return;
}
var outputVideoFilePath = "./test.mp4";
try (FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(videoFilePath)) {
// 创建FrameGrabber对象并打开视频文件
grabber.start();
// 新视频文件路径及参数
int width = grabber.getImageWidth();
int height = grabber.getImageHeight();
var frameRate = grabber.getFrameRate();
// 创建FrameRecorder对象并设置视频文件参数
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputVideoFilePath, width, height);
recorder.setFrameRate(frameRate);
recorder.start();
// 逐帧读取视频文件
Frame frame;
while ((frame = grabber.grabFrame(false, true, true, false)) != null) {
// 将帧转换为OpenCV Mat
OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
Mat src = converter.convert(frame);
// 对每一帧图像进行处理
Mat frameMat = new Mat(src);
Mat denoisedMat = new Mat();
opencv_imgproc.medianBlur(frameMat, denoisedMat, 11);
Mat denoisedMat1 = new Mat();
OpenCVFrameConverter.ToMat converter1 = new OpenCVFrameConverter.ToMat();
// 将处理后的每一帧图像写入新的视频文件
recorder.record(converter1.convert(denoisedMat1));
}
// 关闭FrameGrabber
grabber.stop();
grabber.release();
// 关闭FrameRecorder
recorder.stop();
recorder.release();
log.info("If the execution is successful, the output file path: {}", outputVideoFilePath);
} catch (FrameRecorder.Exception | Exception e) {
throw new RuntimeException(e);
}
}
不可逆,视频质量只会越来越渣,绝无可能弄好,你放弃吧。你一开始就没有高质量的片源,就别指望后面还能处理的更好,这不符合基本原理