org.jcodec.api.JCodecException Java Examples
The following examples show how to use
org.jcodec.api.JCodecException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JcodecFrameGrab.java From cineast with MIT License | 6 votes |
public JcodecFrameGrab(SeekableByteChannel in) throws IOException, JCodecException { ByteBuffer header = ByteBuffer.allocate(65536); in.read(header); header.flip(); Format detectFormat = JCodecUtil.detectFormat(header); switch (detectFormat) { case MOV: MP4Demuxer d1 = new MP4Demuxer(in); videoTrack = 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"); } decodeLeadingFrames(); }
Example #2
Source File: JcodecFrameGrab.java From cineast with MIT License | 6 votes |
private void decodeLeadingFrames() throws IOException, JCodecException { SeekableDemuxerTrack sdt = sdt(); int curFrame = (int) sdt.getCurFrame(); int keyFrame = detectKeyFrame(curFrame); sdt.gotoFrame(keyFrame); Packet frame = sdt.nextFrame(); decoder = detectDecoder(sdt, frame); while (frame.getFrameNo() < curFrame) { decoder.decodeFrame(frame, getBuffer()); frame = sdt.nextFrame(); } sdt.gotoFrame(curFrame); }
Example #3
Source File: JcodecFrameGrab.java From cineast with MIT License | 5 votes |
private SeekableDemuxerTrack sdt() throws JCodecException { if (!(videoTrack instanceof SeekableDemuxerTrack)) { throw new JCodecException("Not a seekable track"); } return (SeekableDemuxerTrack) videoTrack; }
Example #4
Source File: JcodecFrameGrab.java From cineast with MIT License | 5 votes |
private ContainerAdaptor detectDecoder(SeekableDemuxerTrack videoTrack, Packet frame) throws JCodecException { if (videoTrack instanceof AbstractMP4DemuxerTrack) { SampleEntry se = ((AbstractMP4DemuxerTrack) videoTrack).getSampleEntries()[((MP4Packet) frame).getEntryNo()]; VideoDecoder byFourcc = byFourcc(se.getHeader().getFourcc()); if (byFourcc instanceof H264Decoder) { return new AVCMP4Adaptor(((AbstractMP4DemuxerTrack) videoTrack).getSampleEntries()); } } throw new UnsupportedFormatException("Codec is not supported"); }
Example #5
Source File: JcodecFrameGrab.java From cineast with MIT License | 5 votes |
public long getCurrentFrameNum(){ try { return sdt().getCurFrame(); } catch (JCodecException e) { LOGGER.warn(LogHelper.getStackTrace(e)); } return -1; }
Example #6
Source File: OpenViduTestAppE2eTest.java From openvidu with Apache License 2.0 | 5 votes |
private boolean recordedFileFine(File file, Recording recording) throws IOException { this.checkMultimediaFile(file, recording.hasAudio(), recording.hasVideo(), recording.getDuration(), recording.getResolution(), "aac", "h264", true); boolean isFine = false; Picture frame; try { // Get a frame at 75% duration and check that it has the expected color frame = FrameGrab.getFrameAtSec(file, (double) (recording.getDuration() * 0.75)); BufferedImage image = AWTUtil.toBufferedImage(frame); Map<String, Long> colorMap = this.averageColor(image); String realResolution = image.getWidth() + "x" + image.getHeight(); Assert.assertEquals( "Resolution (" + recording.getResolution() + ") of recording entity is not equal to real video resolution (" + realResolution + ")", recording.getResolution(), realResolution); log.info("Recording map color: {}", colorMap.toString()); log.info("Recording frame below"); System.out.println(bufferedImageToBase64PngString(image)); isFine = this.checkVideoAverageRgbGreen(colorMap); } catch (IOException | JCodecException e) { log.warn("Error getting frame from video recording: {}", e.getMessage()); isFine = false; } return isFine; }
Example #7
Source File: JcodecFrameGrab.java From cineast with MIT License | 4 votes |
private void goToPrevKeyframe() throws IOException, JCodecException { sdt().gotoFrame(detectKeyFrame((int) sdt().getCurFrame())); }
Example #8
Source File: JcodecFrameGrab.java From cineast with MIT License | 2 votes |
/** * 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 JcodecFrameGrab seekToSecondPrecise(double second) throws IOException, JCodecException { sdt().seek(second); decodeLeadingFrames(); return this; }
Example #9
Source File: JcodecFrameGrab.java From cineast with MIT License | 2 votes |
/** * 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 JcodecFrameGrab seekToFramePrecise(int frameNumber) throws IOException, JCodecException { sdt().gotoFrame(frameNumber); decodeLeadingFrames(); return this; }
Example #10
Source File: JcodecFrameGrab.java From cineast with MIT License | 2 votes |
/** * Position frame grabber to a specific second in a movie. * * Performs a sloppy seek, meaning that it may actually not seek to exact * second requested, instead it will seek to the closest key frame * * NOTE: fast, as it just seeks to the closest previous key frame and * doesn't try to decode frames in the middle * * @param second * @return * @throws IOException * @throws JCodecException */ public JcodecFrameGrab seekToSecondSloppy(double second) throws IOException, JCodecException { sdt().seek(second); goToPrevKeyframe(); return this; }
Example #11
Source File: JcodecFrameGrab.java From cineast with MIT License | 2 votes |
/** * Position frame grabber to a specific frame in a movie * * Performs a sloppy seek, meaning that it may actually not seek to exact * frame requested, instead it will seek to the closest key frame * * NOTE: fast, as it just seeks to the closest previous key frame and * doesn't try to decode frames in the middle * * @param frameNumber * @return * @throws IOException * @throws JCodecException */ public JcodecFrameGrab seekToFrameSloppy(int frameNumber) throws IOException, JCodecException { sdt().gotoFrame(frameNumber); goToPrevKeyframe(); return this; }