com.xuggle.xuggler.IVideoPicture Java Examples
The following examples show how to use
com.xuggle.xuggler.IVideoPicture.
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: RollingRecorder.java From ShootOFF with GNU General Public License v3.0 | 6 votes |
@Override public void onVideoPicture(IVideoPictureEvent event) { // < 0 means the file we are rolling off of has < RECORD_LENGTH // seconds of footage if (event.getTimeStamp() >= startingTimestamp || startingTimestamp < 0) { final IVideoPicture picture = event.getPicture(); if (startTimestamp == -1) { startTimestamp = picture.getTimeStamp(); } lastTimestamp = picture.getTimeStamp() - startTimestamp; picture.setTimeStamp(lastTimestamp); writer.encodeVideo(0, picture); } }
Example #2
Source File: StreamWriter.java From StormCV with Apache License 2.0 | 6 votes |
/** * Adds an image as a frame to the current video * @param image */ private void addImage(BufferedImage image){ IPacket packet = IPacket.make(); IConverter converter = ConverterFactory.createConverter(image, coder.getPixelType()); IVideoPicture frame = converter.toPicture(image, Math.round(frameTime)); if (coder.encodeVideo(packet, frame, 0) < 0) { throw new RuntimeException("Unable to encode video."); } if (packet.isComplete()) { if (writer.writePacket(packet) < 0) { throw new RuntimeException("Could not write packet to container."); } } this.frameTime += 1000000f/frameRate; frameCount++; }
Example #3
Source File: RollingRecorder.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
public void recordFrame(BufferedImage frame) { final BufferedImage image = ConverterFactory.convertToType(frame, BufferedImage.TYPE_3BYTE_BGR); final IConverter converter = ConverterFactory.createConverter(image, IPixelFormat.Type.YUV420P); timestamp = (System.currentTimeMillis() - startTime) + timeOffset; final IVideoPicture f = converter.toPicture(image, timestamp * 1000); f.setKeyFrame(isFirstShotFrame); f.setQuality(0); if (forking) { synchronized (bufferedFrames) { bufferedFrames.add(f); } } else { isFirstShotFrame = false; synchronized (videoWriterLock) { if (recording) videoWriter.encodeVideo(0, f); } if (timestamp >= ShotRecorder.RECORD_LENGTH * 3) { logger.debug("Rolling video file {}, timestamp = {} ms", relativeVideoFile.getPath(), timestamp); fork(false); } } }
Example #4
Source File: ShotRecorder.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
public void recordFrame(BufferedImage frame) { final BufferedImage image = ConverterFactory.convertToType(frame, BufferedImage.TYPE_3BYTE_BGR); final IConverter converter = ConverterFactory.createConverter(image, IPixelFormat.Type.YUV420P); final long timestamp = (System.currentTimeMillis() - startTime) + timeOffset; final IVideoPicture f = converter.toPicture(image, timestamp * 1000); f.setKeyFrame(isFirstShotFrame); f.setQuality(0); isFirstShotFrame = false; videoWriter.encodeVideo(0, f); }
Example #5
Source File: SegmentFacade.java From red5-hls-plugin with Apache License 2.0 | 5 votes |
QueuedVideoData(IVideoPicture pic, long timeStamp, TimeUnit timeUnit) { ByteBuffer buf = pic.getByteBuffer(); picture = new byte[buf.limit()]; buf.get(picture); buf.flip(); //this.type = pic.getPixelType(); this.width = pic.getWidth(); this.height = pic.getHeight(); this.timeStamp = timeStamp; this.timeUnit = timeUnit; }
Example #6
Source File: SegmentFacade.java From red5-hls-plugin with Apache License 2.0 | 5 votes |
/** * @return the picture */ public IVideoPicture getVideoPicture() { IVideoPicture pic = IVideoPicture.make(IPixelFormat.Type.YUV420P, width, height); pic.put(picture, 0, 0, picture.length); pic.setComplete(true, IPixelFormat.Type.YUV420P, width, height, timeStamp); return pic; }
Example #7
Source File: HLSStreamWriter.java From red5-hls-plugin with Apache License 2.0 | 5 votes |
public void encodeVideo(IVideoPicture picture, long timeStamp, TimeUnit timeUnit) { log.debug("encodeVideo {}", outputUrl); // establish the stream, return silently if no stream returned if (null != picture) { IPacket videoPacket = IPacket.make(); // encode video picture int result = videoCoder.encodeVideo(videoPacket, picture, 0); //System.out.printf("Flags v: %08x\n", videoCoder.getFlags()); if (result < 0) { log.error("{} Failed to encode video: {} picture: {}", new Object[] { result, getErrorMessage(result), picture }); videoPacket.delete(); return; } videoComplete = videoPacket.isComplete(); if (videoComplete) { final long timeStampMicro; if (timeUnit == null) { timeStampMicro = Global.NO_PTS; } else { timeStampMicro = MICROSECONDS.convert(timeStamp, timeUnit); } log.trace("Video timestamp {} us", timeStampMicro); // write packet writePacket(videoPacket); // add the duration of our video double dur = (timeStampMicro + videoPacket.getDuration() - prevVideoTime) / 1000000d; videoDuration += dur; log.trace("Duration - video: {}", dur); //double videoPts = (double) videoPacket.getDuration() * videoCoder.getTimeBase().getNumerator() / videoCoder.getTimeBase().getDenominator(); //log.trace("Video pts - calculated: {} reported: {}", videoPts, videoPacket.getPts()); prevVideoTime = timeStampMicro; videoPacket.delete(); } else { log.warn("Video packet was not complete"); } } else { throw new IllegalArgumentException("No picture"); } }
Example #8
Source File: VideoAdjustTool.java From red5-hls-plugin with Apache License 2.0 | 5 votes |
@Override public void onVideoPicture(IVideoPictureEvent event) { log.debug("Adjust onVideo"); IVideoPicture in = event.getPicture(); log.debug("Video ts: {}", in.getFormattedTimeStamp()); int inWidth = in.getWidth(); int inHeight = in.getHeight(); if (inHeight != height || inWidth != width) { log.debug("VideoAdjustTool onVideoPicture"); log.trace("Video timestamp: {} pixel type: {}", event.getTimeStamp(), in.getPixelType()); log.trace("Video in: {} x {} out: {} x {}", new Object[] { inWidth, inHeight, width, height }); if (resampler == null) { resampler = IVideoResampler.make(width, height, pixelType, inWidth, inHeight, in.getPixelType()); log.debug("Video resampler: {}", resampler); } if (resampler != null) { IVideoPicture out = IVideoPicture.make(pixelType, width, height); if (resampler.resample(out, in) >= 0) { //check complete if (out.isComplete()) { // queue video facade.queueVideo(out, event.getTimeStamp(), event.getTimeUnit()); in.delete(); } else { log.warn("Resampled picture was not marked as complete"); } } else { log.warn("Resample failed"); } out.delete(); } else { log.debug("Resampler was null"); } log.debug("VideoAdjustTool onVideoPicture - end"); } else { // queue video facade.queueVideo(in, event.getTimeStamp(), event.getTimeUnit()); } }
Example #9
Source File: CameraManager.java From ShootOFF with GNU General Public License v3.0 | 4 votes |
private boolean handleFrame(Frame currentFrame, boolean shouldDedistort) { boolean cameraError = false; if (currentFrame == null && !camera.isOpen()) { // Camera appears to have closed if (isStreaming.get() && cameraErrorView.isPresent()) cameraErrorView.get().showMissingCameraError(camera); cameraError = true; } else if (currentFrame == null && camera.isOpen()) { // Camera appears to be open but got a null frame logger.warn("Null frame from camera: {}", camera.getName()); cameraError = true; } else if (currentFrame != null && (currentFrame.size().height != feedHeight || currentFrame.size().width != feedWidth) && camera.isOpen()) { // Camera appears to be open but got an invalid size frame logger.warn("Invalid frame size from camera: {} gave {} expecting {},{}", camera.getName(), currentFrame.size(), feedWidth, feedHeight); cameraError = true; } if (cameraError) { consecutiveCameraErrors++; if (consecutiveCameraErrors > MAXIMUM_CONSECUTIVE_CAMERA_ERRORS) { if (isStreaming.get() && cameraErrorView.isPresent()) cameraErrorView.get().showMissingCameraError(camera); camera.close(); } return false; } else { consecutiveCameraErrors = 0; } BufferedImage currentImage = processFrame(currentFrame, shouldDedistort); Bounds b; synchronized (projectionBoundsLock) { if (projectionBounds.isPresent()) { b = projectionBounds.get(); } else { b = null; } } if (cropFeedToProjection && b != null) { currentImage = currentImage.getSubimage((int) b.getMinX(), (int) b.getMinY(), (int) b.getWidth(), (int) b.getHeight()); } if (recordingShots) { rollingRecorder.recordFrame(currentImage); final List<Shot> removeKeys = new ArrayList<>(); for (final Entry<Shot, ShotRecorder> r : shotRecorders.entrySet()) { if (r.getValue().isComplete()) { r.getValue().close(); removeKeys.add(r.getKey()); } else { r.getValue().recordFrame(currentImage); } } for (final Shot s : removeKeys) shotRecorders.remove(s); } if (recordingStream) { final BufferedImage image = ConverterFactory.convertToType(currentImage, BufferedImage.TYPE_3BYTE_BGR); final IConverter converter = ConverterFactory.createConverter(image, IPixelFormat.Type.YUV420P); final IVideoPicture frame = converter.toPicture(image, (System.currentTimeMillis() - recordingStartTime) * 1000); frame.setKeyFrame(isFirstStreamFrame); frame.setQuality(0); isFirstStreamFrame = false; videoWriterStream.encodeVideo(0, frame); } if (!config.isHeadless()) { if (cropFeedToProjection && projectionBounds.isPresent()) { cameraView.updateBackground(currentImage, projectionBounds); } else { cameraView.updateBackground(currentImage, Optional.empty()); } } return true; }
Example #10
Source File: HLSStreamWriter.java From red5-hls-plugin with Apache License 2.0 | 4 votes |
public void encodeVideo(IVideoPicture picture) { encodeVideo(picture, 0L, null); }
Example #11
Source File: SegmentFacade.java From red5-hls-plugin with Apache License 2.0 | 2 votes |
/** * Queue the video data from xuggler. * * @param pic video picture to queue * @param timeStamp * @param timeUnit */ public void queueVideo(IVideoPicture pic, long timeStamp, TimeUnit timeUnit) { log.trace("Queue video"); dataQueue.add(new QueuedVideoData(pic, timeStamp, timeUnit)); }
Example #12
Source File: IStreamWriter.java From red5-hls-plugin with Apache License 2.0 | votes |
public abstract void encodeVideo(IVideoPicture picture);