com.coremedia.iso.BoxReplacer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of isoparser Show documentation
Show all versions of isoparser Show documentation
A generic parser and writer for all ISO 14496 based files (MP4, Quicktime, DCF, PDCF, ...)
package com.coremedia.iso;
import com.coremedia.iso.boxes.Box;
import com.googlecode.mp4parser.FileDataSourceImpl;
import com.googlecode.mp4parser.util.Path;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class BoxReplacer {
public static void replace(Map replacements, File file) throws IOException {
IsoFile isoFile = new IsoFile( new FileDataSourceImpl(new RandomAccessFile(file, "r").getChannel()));
Map replacementSanitised = new HashMap();
Map positions = new HashMap();
for (Map.Entry e : replacements.entrySet()) {
Box b = Path.getPath(isoFile, e.getKey());
replacementSanitised.put(Path.createPath( b ), e.getValue());
positions.put(Path.createPath( b ), b.getOffset());
assert b.getSize() == e.getValue().getSize();
}
isoFile.close();
FileChannel fileChannel = new RandomAccessFile(file, "rw").getChannel();
for (String path : replacementSanitised.keySet()) {
Box b = replacementSanitised.get(path);
long pos = positions.get(path);
fileChannel.position(pos);
b.getBox(fileChannel);
}
fileChannel.close();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy