Reputation: 81
For my video steganography project (in java) , I need to encode sequential PNGs into a movie file. I tried xuggler but I was getting compression.(due to which data hidden in the lsb's of the png image is getting lost the next time I extract the frames from the video)
Because I need need to retreive the hidden data later, I need to find a process to encode png images to video(preferred format: avi) in a lossless manner. The size of the new video is not a matter to me.
Hoping if someone could guide me or recommend a useful different java library to do this.
I can post my java code if required.
Upvotes: 0
Views: 3133
Reputation: 2377
You can mux a sequence of PNGs into an MP4 file without transcoding ( preserving the exact original images ). To do this in pure Java use JCodec ( http://jcodec.org ):
public class SequenceMuxer {
private SeekableByteChannel ch;
private CompressedTrack outTrack;
private int frameNo;
private MP4Muxer muxer;
private Size size;
public SequenceMuxer(File out) throws IOException {
this.ch = NIOUtils.writableFileChannel(out);
// Muxer that will store the encoded frames
muxer = new MP4Muxer(ch, Brand.MP4);
// Add video track to muxer
outTrack = muxer.addTrackForCompressed(TrackType.VIDEO, 25);
}
public void encodeImage(File png) throws IOException {
if (size == null) {
BufferedImage read = ImageIO.read(png);
size = new Size(read.getWidth(), read.getHeight());
}
// Add packet to video track
outTrack.addFrame(new MP4Packet(NIOUtils.fetchFrom(png), frameNo, 25, 1, frameNo, true, null, frameNo, 0));
frameNo++;
}
public void finish() throws IOException {
// Push saved SPS/PPS to a special storage in MP4
outTrack.addSampleEntry(MP4Muxer.videoSampleEntry("png ", size, "JCodec"));
// Write MP4 header and finalize recording
muxer.writeHeader();
NIOUtils.closeQuietly(ch);
}
}
To use it go like this:
public static void main(String[] args) throws IOException {
SequenceMuxer encoder = new SequenceMuxer(new File("video_png.mp4"));
for (int i = 1; i < 100; i++) {
encoder.encodeImage(new File(String.format("img%08d.png", i)));
}
encoder.finish();
}
Upvotes: 3
Reputation: 21
If you download the processing framework, from www.processing.org, you can write a very simple java program to read in your images and write them out to a mov file, if you use the ANIMATION codec and specify lossless, it will be totally lossless.
Upvotes: 2