[英]Split video into image frames in java
I would like to read a video(MPEG,AVI or any popular format) using Java code and split it into a no of frames(Jpeg),For instance splitting a 2sec video into 48 images(2X24 frames/sec).Is this possible in java.On hindsight i would also like to know if it is possible to create a video using an array of images(reconstruction of the video after editing the individual images).我想使用 Java 代码读取视频(MPEG、AVI 或任何流行格式)并将其拆分为多个帧(Jpeg),例如将 2 秒视频拆分为 48 个图像(2X24 帧/秒)。这可能吗?在java中。事后看来,我还想知道是否可以使用图像数组创建视频(在编辑单个图像后重建视频)。 Any help would be greatly appreciated.Thanks in advance.任何帮助将不胜感激。提前致谢。
You can use FFMPEG which is a open source C program build, and fastest video/audio processing library even used by most popular video sites.您可以使用 FFMPEG,它是一个开源 C 程序构建,也是最流行的视频网站使用的最快的视频/音频处理库。
use the exec method to call ffmpeg.使用exec方法调用ffmpeg。
Easy with velvet-video :轻松使用天鹅绒视频:
Getting frames as images from a video file:从视频文件中获取帧作为图像:
IVelvetVideoLib lib = VelvetVideoLib().getInstance();
try (IDemuxer demuxer = lib.demuxer(new File("/some/path/example.mp4"))) {
IDecoderVideoStream videoStream = demuxer.videoStream(0);
IFrame videoFrame;
while ((videoFrame = videoStream.nextFrame()) != null) {
BufferedImage image = videoFrame.image();
// Use image as needed...
}
}
Composing a video from image array从图像阵列合成视频
BufferedImage[] images = ...
IVelvetVideoLib lib = VelvetVideoLib().getInstance();
try (IMuxer muxer = lib.muxer("matroska") // specify you format
.video(lib.videoEncoder("libaom-av1").bitrate(800000)) // specify you codec
.build(new File("/some/path/output.mkv"))) {
IEncoderVideoStream videoStream = muxer.videoStream(0);
for (BufferedImage image : images) {
videoStream.encode(image);
}
}
Disclaimer: I'm the author of velvet-video免责声明:我是天鹅绒视频的作者
您可以使用 JMF (http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.