public static FrameGrab createFrameGrab(SeekableByteChannel _in) throws IOException, JCodecException { ByteBuffer header = ByteBuffer.allocate(65536); _in.read(header); header.flip(); Format detectFormat = JCodecUtil.detectFormatBuffer(header); if (detectFormat == null) { throw new UnsupportedFormatException("Could not detect the format of the input video."); } SeekableDemuxerTrack videoTrack_; switch (detectFormat) { case MOV: MP4Demuxer d1 = MP4Demuxer.createMP4Demuxer(_in); videoTrack_ = (SeekableDemuxerTrack)d1.getVideoTrack(); break; case MPEG_PS: throw new UnsupportedFormatException("MPEG PS is temporarily unsupported."); case MPEG_TS: throw new UnsupportedFormatException("MPEG TS is temporarily unsupported."); default: throw new UnsupportedFormatException("Container format is not supported by JCodec"); } FrameGrab fg = new FrameGrab(videoTrack_, detectDecoder(videoTrack_)); fg.decodeLeadingFrames(); return fg; }
private static ContainerAdaptor detectDecoder(SeekableDemuxerTrack videoTrack) throws JCodecException { DemuxerTrackMeta meta = videoTrack.getMeta(); switch (meta.getCodec()) { case H264: return new AVCMP4Adaptor(meta); default: throw new UnsupportedFormatException("Codec is not supported"); } }