下载地址(文章指定相关附件):https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:2249
这个项目使用JavaCV库处理视频文件
包含视频读取、处理和保存的基本功能
使用Maven构建可执行JAR文件
可以通过命令行参数指定输入输出文件
需要Java 11或更高版本运行
源码部分:
import org.bytedeco.javacv.;
import org.bytedeco.opencv.opencv_core.;
public class VideoProcessor {
private FFmpegFrameGrabber grabber;
private FFmpegFrameRecorder recorder;
private String inputPath;
private String outputPath;
public VideoProcessor(String input, String output) {
this.inputPath = input;
this.outputPath = output;
}
public void processVideo() throws Exception {
grabber = new FFmpegFrameGrabber(inputPath);
grabber.start();
recorder = new FFmpegFrameRecorder(outputPath,
grabber.getImageWidth(), grabber.getImageHeight());
recorder.setVideoCodec(grabber.getVideoCodec());
recorder.setFrameRate(grabber.getFrameRate());
recorder.start();
Frame frame;
while ((frame = grabber.grab()) != null) {
// 这里可以添加视频处理逻辑
recorder.record(frame);
}
recorder.stop();
grabber.stop();
}
}
class Main {
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: java -jar video-processor.jar ");
return;
}
VideoProcessor processor = new VideoProcessor(args[0], args[1]);
try {
processor.processVideo();
System.out.println("Video processing completed successfully!");
} catch (Exception e) {
System.err.println("Error processing video: " + e.getMessage());
}
}
}