SequenceEncoder enc = new SequenceEncoder(new File(path)); int currShape = 0; int[] labels = new int[nFrames]; enc.encodeImage(bi); g2d.dispose(); labels[i] = shapeTypes[currShape]; enc.finish(); //write .mp4
String fileName = "path/to/my/file"; File file = new File(fileName); MediaInfo info = new MediaInfo(); info.open(file); String format = info.get(MediaInfo.StreamKind.Video, i, "Format", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); int bitRate = info.get(MediaInfo.StreamKind.Video, i, "BitRate", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); float frameRate = info.get(MediaInfo.StreamKind.Video, i, "FrameRate", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); short width = info.get(MediaInfo.StreamKind.Video, i, "Width", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); int audioBitrate = info.get(MediaInfo.StreamKind.Audio, i, "BitRate", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); int audioChannels = info.get(MediaInfo.StreamKind.Audio, i, "Channels", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
import org.jcodec.api.awt.SequenceEncoder; ... SequenceEncoder enc = new SequenceEncoder(new File("filename")); // GOP size will be supported in 0.2 // enc.getEncoder().setKeyInterval(25); for(...) { BufferedImage image = ... // Obtain an image to encode enc.encodeImage(image); } enc.finish();
/** * Get a specified frame by number from an already open demuxer track * * @param vt * @param decoder * @param frameNumber * @return * @throws IOException * @throws JCodecException */ public static Picture getNativeFrameAtFrame(SeekableDemuxerTrack vt, ContainerAdaptor decoder, int frameNumber) throws IOException, JCodecException { return new FrameGrab(vt, decoder).seekToFramePrecise(frameNumber).getNativeFrame(); }
/** * Get a specified frame by second from an already open demuxer track * * @param vt * @param decoder * @param frameNumber * @return * @throws IOException * @throws JCodecException */ public static Picture getNativeFrameAtSec(SeekableDemuxerTrack vt, ContainerAdaptor decoder, double second) throws IOException, JCodecException { return new FrameGrab(vt, decoder).seekToSecondPrecise(second).getNativeFrame(); }
/** * Get a specified frame by number from an already open demuxer track ( * sloppy mode, i.e. nearest keyframe ) * * @param vt * @param decoder * @param frameNumber * @return * @throws IOException * @throws JCodecException */ public static Picture getNativeFrameSloppy(SeekableDemuxerTrack vt, ContainerAdaptor decoder, int frameNumber) throws IOException, JCodecException { return new FrameGrab(vt, decoder).seekToFrameSloppy(frameNumber).getNativeFrame(); }
/** * Get a specified frame by second from an already open demuxer track ( * sloppy mode, i.e. nearest keyframe ) * * @param vt * @param decoder * @param frameNumber * @return * @throws IOException * @throws JCodecException */ public static Picture getNativeFrameAtSecSloppy(SeekableDemuxerTrack vt, ContainerAdaptor decoder, double second) throws IOException, JCodecException { return new FrameGrab(vt, decoder).seekToSecondSloppy(second).getNativeFrame(); }
/** * Get frame at a specified frame number as JCodec image * * @param file * @param second * @return * @throws IOException * @throws JCodecException */ public static Picture getFrameFromChannel(SeekableByteChannel file, int frameNumber) throws JCodecException, IOException { return createFrameGrab(file).seekToFramePrecise(frameNumber).getNativeFrame(); }
/** * Get frame at a specified second as JCodec image * * @param file * @param second * @return * @throws IOException * @throws JCodecException */ public static Picture getFrameFromChannelAtSec(SeekableByteChannel file, double second) throws JCodecException, IOException { return createFrameGrab(file).seekToSecondPrecise(second).getNativeFrame(); }
public static AWTFrameGrab createAWTFrameGrab(SeekableByteChannel _in) throws IOException, JCodecException { FrameGrab fg = FrameGrab.createFrameGrab(_in); return new AWTFrameGrab(fg.getVideoTrack(), fg.getDecoder()); }
public static SequenceEncoder createWithFps(SeekableByteChannel out, Rational fps) throws IOException { return new SequenceEncoder(out, fps, MOV, H264, null); }
@Override public MediaInfo getMediaInfo() { return new MediaInfo(size); } }
private SeekableDemuxerTrack sdt() throws JCodecException { if (!(videoTrack instanceof SeekableDemuxerTrack)) throw new JCodecException("Not a seekable track"); return (SeekableDemuxerTrack) videoTrack; }
private void goToPrevKeyframe() throws IOException, JCodecException { sdt().gotoFrame(detectKeyFrame((int) sdt().getCurFrame())); }
@Override public void seek(double second) { throw new NotSupportedException(); } }
public static void writeSliceTrailingBits() { throw new NotImplementedException("todo"); } }
@Override public MediaInfo getMediaInfo() { return new MediaInfo(new Size(0, 0)); }
@Override public void seek(double second) { throw new NotSupportedException(); }
public short[] encode(byte[] orig) { throw new NotSupportedException(); }
public static String lookupFourcc(AudioFormat format) { if (format.getSampleSizeInBits() == 16 && !format.isBigEndian()) return "sowt"; else if (format.getSampleSizeInBits() == 24) return "in24"; else throw new NotSupportedException("Audio format " + format + " is not supported."); }