www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,44 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
import org.jcodec.common.StringUtils;
|
||||
|
||||
public class DPXMetadata {
|
||||
public static final String V2 = "V2.0";
|
||||
|
||||
public static final String V1 = "V1.0";
|
||||
|
||||
public FileHeader file;
|
||||
|
||||
public ImageHeader image;
|
||||
|
||||
public ImageSourceHeader imageSource;
|
||||
|
||||
public FilmHeader film;
|
||||
|
||||
public TelevisionHeader television;
|
||||
|
||||
public String userId;
|
||||
|
||||
private static String smpteTC(int tcsmpte, boolean prevent_dropframe) {
|
||||
int ff = bcd2uint(tcsmpte & 0x3F);
|
||||
int ss = bcd2uint(tcsmpte >> 8 & 0x7F);
|
||||
int mm = bcd2uint(tcsmpte >> 16 & 0x7F);
|
||||
int hh = bcd2uint(tcsmpte >> 24 & 0x3F);
|
||||
boolean drop = ((long)(tcsmpte & 0x40000000) > 0L && !prevent_dropframe);
|
||||
return StringUtils.zeroPad2(hh) + ":" + StringUtils.zeroPad2(hh) + ":" +
|
||||
StringUtils.zeroPad2(mm) +
|
||||
StringUtils.zeroPad2(ss) + (drop ? ";" : ":");
|
||||
}
|
||||
|
||||
private static int bcd2uint(int bcd) {
|
||||
int low = bcd & 0xF;
|
||||
int high = bcd >> 4;
|
||||
if (low > 9 || high > 9)
|
||||
return 0;
|
||||
return low + 10 * high;
|
||||
}
|
||||
|
||||
public String getTimecodeString() {
|
||||
return smpteTC(this.television.timecode, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import org.jcodec.common.StringUtils;
|
||||
import org.jcodec.common.io.IOUtils;
|
||||
import org.jcodec.common.io.NIOUtils;
|
||||
import org.jcodec.common.io.SeekableByteChannel;
|
||||
|
||||
public class DPXReader {
|
||||
private static final int READ_BUFFER_SIZE = 3072;
|
||||
|
||||
static final int IMAGEINFO_OFFSET = 768;
|
||||
|
||||
static final int IMAGESOURCE_OFFSET = 1408;
|
||||
|
||||
static final int FILM_OFFSET = 1664;
|
||||
|
||||
static final int TVINFO_OFFSET = 1920;
|
||||
|
||||
public static final int SDPX = 1396985944;
|
||||
|
||||
private final ByteBuffer readBuf;
|
||||
|
||||
private final int magic;
|
||||
|
||||
private boolean eof;
|
||||
|
||||
public DPXReader(SeekableByteChannel ch) throws IOException {
|
||||
this.readBuf = ByteBuffer.allocate(3072);
|
||||
initialRead(ch);
|
||||
this.magic = this.readBuf.getInt();
|
||||
if (this.magic == 1396985944) {
|
||||
this.readBuf.order(ByteOrder.BIG_ENDIAN);
|
||||
} else {
|
||||
this.readBuf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
}
|
||||
|
||||
public DPXMetadata parseMetadata() {
|
||||
DPXMetadata dpx = new DPXMetadata();
|
||||
dpx.file = readFileInfo(this.readBuf);
|
||||
dpx.file.magic = this.magic;
|
||||
this.readBuf.position(768);
|
||||
dpx.image = readImageInfoHeader(this.readBuf);
|
||||
this.readBuf.position(1408);
|
||||
dpx.imageSource = readImageSourceHeader(this.readBuf);
|
||||
this.readBuf.position(1664);
|
||||
dpx.film = readFilmInformationHeader(this.readBuf);
|
||||
this.readBuf.position(1920);
|
||||
dpx.television = readTelevisionInfoHeader(this.readBuf);
|
||||
dpx.userId = readNullTermString(this.readBuf, 32);
|
||||
return dpx;
|
||||
}
|
||||
|
||||
private void initialRead(ReadableByteChannel ch) throws IOException {
|
||||
this.readBuf.clear();
|
||||
if (ch.read(this.readBuf) == -1)
|
||||
this.eof = true;
|
||||
this.readBuf.flip();
|
||||
}
|
||||
|
||||
private static FileHeader readFileInfo(ByteBuffer bb) {
|
||||
FileHeader h = new FileHeader();
|
||||
h.imageOffset = bb.getInt();
|
||||
h.version = readNullTermString(bb, 8);
|
||||
h.filesize = bb.getInt();
|
||||
h.ditto = bb.getInt();
|
||||
h.genericHeaderLength = bb.getInt();
|
||||
h.industryHeaderLength = bb.getInt();
|
||||
h.userHeaderLength = bb.getInt();
|
||||
h.filename = readNullTermString(bb, 100);
|
||||
h.created = tryParseISO8601Date(readNullTermString(bb, 24));
|
||||
h.creator = readNullTermString(bb, 100);
|
||||
h.projectName = readNullTermString(bb, 200);
|
||||
h.copyright = readNullTermString(bb, 200);
|
||||
h.encKey = bb.getInt();
|
||||
return h;
|
||||
}
|
||||
|
||||
static Date tryParseISO8601Date(String dateString) {
|
||||
if (StringUtils.isEmpty(dateString))
|
||||
return null;
|
||||
String noTZ = "yyyy:MM:dd:HH:mm:ss";
|
||||
if (dateString.length() == noTZ.length())
|
||||
return date(dateString, noTZ);
|
||||
if (dateString.length() == noTZ.length() + 4)
|
||||
dateString = dateString + "00";
|
||||
return date(dateString, "yyyy:MM:dd:HH:mm:ss:Z");
|
||||
}
|
||||
|
||||
private static Date date(String dateString, String dateFormat) {
|
||||
SimpleDateFormat format = new SimpleDateFormat(dateFormat, Locale.US);
|
||||
try {
|
||||
return format.parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String readNullTermString(ByteBuffer bb, int length) {
|
||||
ByteBuffer b = ByteBuffer.allocate(length);
|
||||
bb.get(b.array(), 0, length);
|
||||
return NIOUtils.readNullTermString(b);
|
||||
}
|
||||
|
||||
public static DPXReader readFile(File file) throws IOException {
|
||||
SeekableByteChannel _in = NIOUtils.readableChannel(file);
|
||||
try {
|
||||
return new DPXReader(_in);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(_in);
|
||||
}
|
||||
}
|
||||
|
||||
private static TelevisionHeader readTelevisionInfoHeader(ByteBuffer r) {
|
||||
TelevisionHeader h = new TelevisionHeader();
|
||||
h.timecode = r.getInt();
|
||||
h.userBits = r.getInt();
|
||||
h.interlace = r.get();
|
||||
h.filedNumber = r.get();
|
||||
h.videoSignalStarted = r.get();
|
||||
h.zero = r.get();
|
||||
h.horSamplingRateHz = r.getInt();
|
||||
h.vertSampleRateHz = r.getInt();
|
||||
h.frameRate = r.getInt();
|
||||
h.timeOffset = r.getInt();
|
||||
h.gamma = r.getInt();
|
||||
h.blackLevel = r.getInt();
|
||||
h.blackGain = r.getInt();
|
||||
h.breakpoint = r.getInt();
|
||||
h.referenceWhiteLevel = r.getInt();
|
||||
h.integrationTime = r.getInt();
|
||||
return h;
|
||||
}
|
||||
|
||||
private static FilmHeader readFilmInformationHeader(ByteBuffer r) {
|
||||
FilmHeader h = new FilmHeader();
|
||||
h.idCode = readNullTermString(r, 2);
|
||||
h.type = readNullTermString(r, 2);
|
||||
h.offset = readNullTermString(r, 2);
|
||||
h.prefix = readNullTermString(r, 6);
|
||||
h.count = readNullTermString(r, 4);
|
||||
h.format = readNullTermString(r, 32);
|
||||
return h;
|
||||
}
|
||||
|
||||
private static ImageSourceHeader readImageSourceHeader(ByteBuffer r) {
|
||||
ImageSourceHeader h = new ImageSourceHeader();
|
||||
h.xOffset = r.getInt();
|
||||
h.yOffset = r.getInt();
|
||||
h.xCenter = r.getFloat();
|
||||
h.yCenter = r.getFloat();
|
||||
h.xOriginal = r.getInt();
|
||||
h.yOriginal = r.getInt();
|
||||
h.sourceImageFilename = readNullTermString(r, 100);
|
||||
h.sourceImageDate = tryParseISO8601Date(readNullTermString(r, 24));
|
||||
h.deviceName = readNullTermString(r, 32);
|
||||
h.deviceSerial = readNullTermString(r, 32);
|
||||
h.borderValidity = new short[] { r.getShort(), r.getShort(), r.getShort(), r.getShort() };
|
||||
h.aspectRatio = new int[] { r.getInt(), r.getInt() };
|
||||
return h;
|
||||
}
|
||||
|
||||
private static ImageHeader readImageInfoHeader(ByteBuffer r) {
|
||||
ImageHeader h = new ImageHeader();
|
||||
h.orientation = r.getShort();
|
||||
h.numberOfImageElements = r.getShort();
|
||||
h.pixelsPerLine = r.getInt();
|
||||
h.linesPerImageElement = r.getInt();
|
||||
h.imageElement1 = new ImageElement();
|
||||
h.imageElement1.dataSign = r.getInt();
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class FileHeader {
|
||||
public int magic;
|
||||
|
||||
public int imageOffset;
|
||||
|
||||
public String version;
|
||||
|
||||
public int ditto;
|
||||
|
||||
public String filename;
|
||||
|
||||
public Date created;
|
||||
|
||||
public int filesize;
|
||||
|
||||
public String creator;
|
||||
|
||||
public String projectName;
|
||||
|
||||
public String copyright;
|
||||
|
||||
public int encKey;
|
||||
|
||||
public int genericHeaderLength;
|
||||
|
||||
public int industryHeaderLength;
|
||||
|
||||
public int userHeaderLength;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
public class FilmHeader {
|
||||
public String idCode;
|
||||
|
||||
public String type;
|
||||
|
||||
public String offset;
|
||||
|
||||
public String prefix;
|
||||
|
||||
public String count;
|
||||
|
||||
public String format;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
public class ImageElement {
|
||||
public int dataSign;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
public class ImageHeader {
|
||||
public short orientation;
|
||||
|
||||
public short numberOfImageElements;
|
||||
|
||||
public int linesPerImageElement;
|
||||
|
||||
public int pixelsPerLine;
|
||||
|
||||
public ImageElement imageElement1;
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ImageSourceHeader {
|
||||
public int xOffset;
|
||||
|
||||
public int yOffset;
|
||||
|
||||
public float xCenter;
|
||||
|
||||
public float yCenter;
|
||||
|
||||
public int xOriginal;
|
||||
|
||||
public int yOriginal;
|
||||
|
||||
public String sourceImageFilename;
|
||||
|
||||
public Date sourceImageDate;
|
||||
|
||||
public String deviceName;
|
||||
|
||||
public String deviceSerial;
|
||||
|
||||
public short[] borderValidity;
|
||||
|
||||
public int[] aspectRatio;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.jcodec.containers.dpx;
|
||||
|
||||
public class TelevisionHeader {
|
||||
public int timecode;
|
||||
|
||||
public int userBits;
|
||||
|
||||
public byte interlace;
|
||||
|
||||
public byte filedNumber;
|
||||
|
||||
public byte videoSignalStarted;
|
||||
|
||||
public byte zero;
|
||||
|
||||
public int horSamplingRateHz;
|
||||
|
||||
public int vertSampleRateHz;
|
||||
|
||||
public int frameRate;
|
||||
|
||||
public int timeOffset;
|
||||
|
||||
public int gamma;
|
||||
|
||||
public int blackLevel;
|
||||
|
||||
public int blackGain;
|
||||
|
||||
public int breakpoint;
|
||||
|
||||
public int referenceWhiteLevel;
|
||||
|
||||
public int integrationTime;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue