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,37 @@
|
|||
package org.jcodec.codecs.raw;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.jcodec.common.VideoCodecMeta;
|
||||
import org.jcodec.common.VideoDecoder;
|
||||
import org.jcodec.common.model.ColorSpace;
|
||||
import org.jcodec.common.model.Picture;
|
||||
import org.jcodec.common.model.Size;
|
||||
|
||||
public class RAWVideoDecoder extends VideoDecoder {
|
||||
private int width;
|
||||
|
||||
private int height;
|
||||
|
||||
public RAWVideoDecoder(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Picture decodeFrame(ByteBuffer data, byte[][] buffer) {
|
||||
Picture create = Picture.createPicture(this.width, this.height, buffer, ColorSpace.YUV420);
|
||||
ByteBuffer pix = data.duplicate();
|
||||
copy(pix, create.getPlaneData(0), this.width * this.height);
|
||||
copy(pix, create.getPlaneData(1), this.width * this.height / 4);
|
||||
copy(pix, create.getPlaneData(2), this.width * this.height / 4);
|
||||
return create;
|
||||
}
|
||||
|
||||
void copy(ByteBuffer b, byte[] ii, int size) {
|
||||
for (int i = 0; b.hasRemaining() && i < size; i++)
|
||||
ii[i] = (byte)((b.get() & 0xFF) - 128);
|
||||
}
|
||||
|
||||
public VideoCodecMeta getCodecMeta(ByteBuffer data) {
|
||||
return VideoCodecMeta.createSimpleVideoCodecMeta(new Size(this.width, this.height), ColorSpace.YUV420);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package org.jcodec.codecs.raw;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.jcodec.common.VideoEncoder;
|
||||
import org.jcodec.common.model.ColorSpace;
|
||||
import org.jcodec.common.model.Picture;
|
||||
|
||||
public class RAWVideoEncoder extends VideoEncoder {
|
||||
public VideoEncoder.EncodedFrame encodeFrame(Picture pic, ByteBuffer _out) {
|
||||
ByteBuffer dup = _out.duplicate();
|
||||
ColorSpace color = pic.getColor();
|
||||
if (color.planar) {
|
||||
for (int plane = 0; plane < color.nComp; plane++) {
|
||||
int width = pic.getWidth() >> color.compWidth[plane];
|
||||
int startX = pic.getStartX();
|
||||
int startY = pic.getStartY();
|
||||
int cropW = pic.getCroppedWidth() >> color.compWidth[plane];
|
||||
int cropH = pic.getCroppedHeight() >> color.compHeight[plane];
|
||||
byte[] planeData = pic.getPlaneData(plane);
|
||||
int pos = width * startY + startX;
|
||||
for (int y = 0; y < cropH; y++) {
|
||||
for (int x = 0; x < cropW; x++)
|
||||
dup.put((byte)(planeData[pos + x] + 128));
|
||||
pos += width;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int bytesPerPixel = color.bitsPerPixel + 7 >> 3;
|
||||
int stride = pic.getWidth() * bytesPerPixel;
|
||||
int startX = pic.getStartX();
|
||||
int startY = pic.getStartY();
|
||||
int cropW = pic.getCroppedWidth();
|
||||
int cropH = pic.getCroppedHeight();
|
||||
byte[] planeData = pic.getPlaneData(0);
|
||||
int pos = stride * startY + startX * bytesPerPixel;
|
||||
for (int y = 0; y < cropH; y++) {
|
||||
for (int x = 0, off = 0; x < cropW; x++, off += bytesPerPixel) {
|
||||
for (int b = 0; b < bytesPerPixel; b++)
|
||||
dup.put((byte)(planeData[pos + off + b] + 128));
|
||||
}
|
||||
pos += stride;
|
||||
}
|
||||
}
|
||||
dup.flip();
|
||||
return new VideoEncoder.EncodedFrame(dup, true);
|
||||
}
|
||||
|
||||
public ColorSpace[] getSupportedColorSpaces() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int estimateBufferSize(Picture frame) {
|
||||
int fullPlaneSize = frame.getWidth() * frame.getCroppedHeight();
|
||||
ColorSpace color = frame.getColor();
|
||||
int totalSize = 0;
|
||||
for (int i = 0; i < color.nComp; i++)
|
||||
totalSize += fullPlaneSize >> color.compWidth[i] >> color.compHeight[i];
|
||||
return totalSize;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package org.jcodec.codecs.raw;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import org.jcodec.common.model.ColorSpace;
|
||||
import org.jcodec.common.model.Picture;
|
||||
|
||||
public class V210Decoder {
|
||||
private int width;
|
||||
|
||||
private int height;
|
||||
|
||||
public V210Decoder(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Picture decode(byte[] data) {
|
||||
ByteBuffer littleEndian = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
|
||||
IntBuffer dat = littleEndian.asIntBuffer();
|
||||
ByteBuffer y = ByteBuffer.wrap(new byte[this.width * this.height]);
|
||||
ByteBuffer cb = ByteBuffer.wrap(new byte[this.width * this.height / 2]);
|
||||
ByteBuffer cr = ByteBuffer.wrap(new byte[this.width * this.height / 2]);
|
||||
while (dat.hasRemaining()) {
|
||||
int i = dat.get();
|
||||
cr.put(to8Bit(i >> 20));
|
||||
y.put(to8Bit(i >> 10 & 0x3FF));
|
||||
cb.put(to8Bit(i & 0x3FF));
|
||||
i = dat.get();
|
||||
y.put(to8Bit(i & 0x3FF));
|
||||
y.put(to8Bit(i >> 20));
|
||||
cb.put(to8Bit(i >> 10 & 0x3FF));
|
||||
i = dat.get();
|
||||
cb.put(to8Bit(i >> 20));
|
||||
y.put(to8Bit(i >> 10 & 0x3FF));
|
||||
cr.put(to8Bit(i & 0x3FF));
|
||||
i = dat.get();
|
||||
y.put(to8Bit(i & 0x3FF));
|
||||
y.put(to8Bit(i >> 20));
|
||||
cr.put(to8Bit(i >> 10 & 0x3FF));
|
||||
}
|
||||
return Picture.createPicture(this.width, this.height, new byte[][] { (byte)y.array(), (byte)cb.array(), (byte)cr.array() }, ColorSpace.YUV422);
|
||||
}
|
||||
|
||||
private byte to8Bit(int i) {
|
||||
return (byte)((i + 2 >> 2) - 128);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package org.jcodec.codecs.raw;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import org.jcodec.common.model.Picture;
|
||||
import org.jcodec.common.tools.MathUtil;
|
||||
|
||||
public class V210Encoder {
|
||||
public ByteBuffer encodeFrame(ByteBuffer _out, Picture frame) throws IOException {
|
||||
ByteBuffer out = _out.duplicate();
|
||||
out.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int tgtStride = (frame.getPlaneWidth(0) + 47) / 48 * 48;
|
||||
byte[][] data = frame.getData();
|
||||
byte[] tmpY = new byte[tgtStride];
|
||||
byte[] tmpCb = new byte[tgtStride >> 1];
|
||||
byte[] tmpCr = new byte[tgtStride >> 1];
|
||||
int yOff = 0, cbOff = 0, crOff = 0;
|
||||
for (int yy = 0; yy < frame.getHeight(); yy++) {
|
||||
System.arraycopy(data[0], yOff, tmpY, 0, frame.getPlaneWidth(0));
|
||||
System.arraycopy(data[1], cbOff, tmpCb, 0, frame.getPlaneWidth(1));
|
||||
System.arraycopy(data[2], crOff, tmpCr, 0, frame.getPlaneWidth(2));
|
||||
for (int yi = 0, cbi = 0, cri = 0; yi < tgtStride; ) {
|
||||
int i = 0;
|
||||
i |= clip(tmpCr[cri++]) << 20;
|
||||
i |= clip(tmpY[yi++]) << 10;
|
||||
i |= clip(tmpCb[cbi++]);
|
||||
out.putInt(i);
|
||||
i = 0;
|
||||
i |= clip(tmpY[yi++]);
|
||||
i |= clip(tmpY[yi++]) << 20;
|
||||
i |= clip(tmpCb[cbi++]) << 10;
|
||||
out.putInt(i);
|
||||
i = 0;
|
||||
i |= clip(tmpCb[cbi++]) << 20;
|
||||
i |= clip(tmpY[yi++]) << 10;
|
||||
i |= clip(tmpCr[cri++]);
|
||||
out.putInt(i);
|
||||
i = 0;
|
||||
i |= clip(tmpY[yi++]);
|
||||
i |= clip(tmpY[yi++]) << 20;
|
||||
i |= clip(tmpCr[cri++]) << 10;
|
||||
out.putInt(i);
|
||||
}
|
||||
yOff += frame.getPlaneWidth(0);
|
||||
cbOff += frame.getPlaneWidth(1);
|
||||
crOff += frame.getPlaneWidth(2);
|
||||
}
|
||||
out.flip();
|
||||
return out;
|
||||
}
|
||||
|
||||
static final int clip(byte val) {
|
||||
return MathUtil.clip(val + 128 << 2, 8, 1019);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue