/** * 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 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(); }
FrameGrab fg; try{ fg = new FrameGrab(seekableByteChannel); if(startFrame != 0) fg.seekToFramePrecise(startFrame); } catch(JCodecException e){ throw new RuntimeException(e); BufferedImage grab = fg.getFrame(); if(ravel) record.add(RecordConverter.toRecord(imageLoader.toRaveledTensor(grab))); for(double i = 0; i < videoLength; i += framesPerSecond) { try { BufferedImage grab = FrameGrab.getFrame(seekableByteChannel, i); if(ravel) record.add(RecordConverter.toRecord(imageLoader.toRaveledTensor(grab)));
/** * 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(); }
@Override public void reset() { try { grabber = new FrameGrab(NIOUtils.readableFileChannel(new File(filename))); } catch (IOException | JCodecException e) { throw new RuntimeException(e); } try { frameCurrent = null; frameNext = grabber.getNativeFrame(); } catch (IOException e) { frameNext = null; } } }
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; }
int frameNumber = 10000; FileChannelWrapper ch = null; try { ch = NIOUtils.readableFileChannel(new File(path to mp4)); FrameGrab frameGrab = new FrameGrab(ch); frameGrab.seek(frameNumber); Picture frame; for (int i = 0; (frame = frameGrab.getNativeFrame()) != null && i < 200; i++) { // Do something } } finally { NIOUtils.closeQuietly(ch); }
@Override public T next() { frameCurrent = frameNext; try { frameNext = grabber.getNativeFrame(); } catch (IOException e) { frameNext = null; } image.reshape(frameCurrent.getWidth(), frameCurrent.getHeight()); UtilJCodec.convertToBoof(frameCurrent, image); frame++; return image; }
public static AWTFrameGrab createAWTFrameGrab(SeekableByteChannel _in) throws IOException, JCodecException { FrameGrab fg = FrameGrab.createFrameGrab(_in); return new AWTFrameGrab(fg.getVideoTrack(), fg.getDecoder()); }
/** * Position frame grabber to a specific frame in a movie. As a result the * next decoded frame will be precisely the requested frame number. * * WARNING: potentially very slow. Use only when you absolutely need precise * seek. Tries to seek to exactly the requested frame and for this it might * have to decode a sequence of frames from the closes key frame. Depending * on GOP structure this may be as many as 500 frames. * * @param frameNumber * @return * @throws IOException * @throws JCodecException */ public FrameGrab seekToFramePrecise(int frameNumber) throws IOException, JCodecException { sdt().gotoFrame(frameNumber); decodeLeadingFrames(); return this; }
FrameGrab fg; try { fg = new FrameGrab(seekableByteChannel); if (startFrame != 0) fg.seekToFramePrecise(startFrame); } catch (JCodecException e) { throw new RuntimeException(e); BufferedImage grab = fg.getFrame(); if (ravel) record.add(RecordConverter.toRecord(imageLoader.toRaveledTensor(grab))); for (double i = 0; i < videoLength; i += framesPerSecond) { try { BufferedImage grab = FrameGrab.getFrame(seekableByteChannel, i); if (ravel) record.add(RecordConverter.toRecord(imageLoader.toRaveledTensor(grab)));
@Override public void reset() { try { grabber = new FrameGrab(NIOUtils.readableFileChannel(new File(filename))); } catch (IOException | JCodecException e) { throw new RuntimeException(e); } try { frameCurrent = null; frameNext = grabber.getNativeFrame(); } catch (IOException e) { frameNext = null; } } }
/** * Get frame at a specified second as JCodec image * * @param file * @param second * @return * @throws IOException * @throws JCodecException */ public static Picture getFrameAtSec(File file, double second) throws IOException, JCodecException { FileChannelWrapper ch = null; try { ch = NIOUtils.readableChannel(file); return createFrameGrab(ch).seekToSecondPrecise(second).getNativeFrame(); } finally { NIOUtils.closeQuietly(ch); } }
@Override public T next() { frameCurrent = frameNext; try { frameNext = grabber.getNativeFrame(); } catch (IOException e) { frameNext = null; } image.reshape(frameCurrent.getWidth(), frameCurrent.getHeight()); UtilJCodec.convertToBoof(frameCurrent, image); frame++; return image; }
/** * Position frame grabber to a specific second in a movie. As a result the * next decoded frame will be precisely at the requested second. * * WARNING: potentially very slow. Use only when you absolutely need precise * seek. Tries to seek to exactly the requested second and for this it might * have to decode a sequence of frames from the closes key frame. Depending * on GOP structure this may be as many as 500 frames. * * @param second * @return * @throws IOException * @throws JCodecException */ public FrameGrab seekToSecondPrecise(double second) throws IOException, JCodecException { sdt().seek(second); decodeLeadingFrames(); return this; }
/** * Get frame at a specified frame number as JCodec image * * @param file * @param second * @return * @throws IOException * @throws JCodecException */ public static Picture getFrameFromFile(File file, int frameNumber) throws IOException, JCodecException { FileChannelWrapper ch = null; try { ch = NIOUtils.readableChannel(file); return createFrameGrab(ch).seekToFramePrecise(frameNumber).getNativeFrame(); } finally { NIOUtils.closeQuietly(ch); } }