boofcv.io.video.CombineFilesTogether Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boofcv-io Show documentation
Show all versions of boofcv-io Show documentation
BoofCV is an open source Java library for real-time computer vision and robotics applications.
The newest version!
/*
* Copyright (c) 2021, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package boofcv.io.video;
import boofcv.io.UtilIO;
import boofcv.misc.BoofMiscOps;
import org.ddogleg.struct.DogArray_I8;
import java.io.*;
import java.util.Collections;
import java.util.List;
/**
* Combines a sequence of files together using a simple format. At the beginning of each segment/file [0xff,0xff,0xff]
* is written, followed by the 4-byte integer in big endian order specifying the file size. After that the file
* is written. This is repeated until all the files are done.
*
* @author Peter Abeles
*/
public class CombineFilesTogether {
public static void combine( List fileNames, String outputName ) throws IOException {
FileOutputStream fos = new FileOutputStream(outputName);
DogArray_I8 buffer = new DogArray_I8();
for (String s : fileNames) {
File f = new File(s);
FileInputStream fis = new FileInputStream(f);
long length = f.length();
buffer.resize((int)length);
// write out header
fos.write(255);
fos.write(255);
fos.write(255);
fos.write((byte)(length >> 24));
fos.write((byte)(length >> 16));
fos.write((byte)(length >> 8));
fos.write((byte)length);
int readLength = fis.read(buffer.data, 0, (int)length);
BoofMiscOps.checkEq(readLength, (int)length);
fos.write(buffer.data, 0, (int)length);
}
}
@SuppressWarnings({"IdentityBinaryExpression"})
public static boolean readNext( DataInputStream fis, DogArray_I8 output ) throws IOException {
int r;
if ((r = fis.read()) != 0xFF || (r = fis.read()) != 0xFF || (r = fis.read()) != 0xFF)
if (r == -1)
return false;
else
throw new IllegalArgumentException("Bad header byte: " + r);
int length = ((fis.read() & 0xFF) << 24) | ((fis.read() & 0xFF) << 16) |
((fis.read() & 0xFF) << 8) | (fis.read() & 0xFF);
output.resize(length);
int readLength = fis.read(output.data, 0, length);
BoofMiscOps.checkEq(readLength, length);
return true;
}
public static void main( String[] args ) throws IOException {
List fileNames = UtilIO.listByPrefix("log", "depth", null);
Collections.sort(fileNames);
CombineFilesTogether.combine(fileNames, "combined.mpng");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy