Reputation: 41
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). Any help would be greatly appreciated.Thanks in advance.
Upvotes: 4
Views: 4041
Reputation: 301
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
Upvotes: 0
Reputation: 1066
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.
use the exec method to call ffmpeg.
Upvotes: 1
Reputation: 6499
You could use JMF (http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html) for it.
Upvotes: 0