Java源码示例:org.jcodec.api.JCodecException

示例1
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();
}
 
示例2
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);
}
 
示例3
private SeekableDemuxerTrack sdt() throws JCodecException {
      if (!(videoTrack instanceof SeekableDemuxerTrack)) {
	throw new JCodecException("Not a seekable track");
}

      return (SeekableDemuxerTrack) videoTrack;
  }
 
示例4
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");
 }
 
示例5
public long getCurrentFrameNum(){
  	try {
	return sdt().getCurFrame();
} catch (JCodecException e) {
	LOGGER.warn(LogHelper.getStackTrace(e));
}
  	return -1;
  }
 
示例6
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;
}
 
示例7
private void goToPrevKeyframe() throws IOException, JCodecException {
    sdt().gotoFrame(detectKeyFrame((int) sdt().getCurFrame()));
}
 
示例8
/**
 * 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;
}
 
示例9
/**
 * 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;
}
 
示例10
/**
 * 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;
}
 
示例11
/**
 * 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;
}