当前位置: 首页>>代码示例>>Java>>正文


Java ConverterFactory类代码示例

本文整理汇总了Java中com.xuggle.xuggler.video.ConverterFactory的典型用法代码示例。如果您正苦于以下问题:Java ConverterFactory类的具体用法?Java ConverterFactory怎么用?Java ConverterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConverterFactory类属于com.xuggle.xuggler.video包,在下文中一共展示了ConverterFactory类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: open

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
@Override
public void open(String path, int w, int h, int fps) throws Exception {
    int bitRate = (int) Math.max(w * h * fps * BPP, MIN_BITRATE);
    IRational frameRate = IRational.make(fps, 1);
    deltat = 1e6 / frameRate.getDouble();

    movieWriter = ToolFactory.makeWriter(path);
    movieWriter.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, w, h);

    IPixelFormat.Type pixFmt = IPixelFormat.Type.YUV420P;
    converter = ConverterFactory.createConverter(ConverterFactory.XUGGLER_BGR_24, pixFmt, w, h);

    IStreamCoder coder = movieWriter.getContainer().getStream(0).getStreamCoder();
    coder.setBitRate(bitRate);
    coder.setFrameRate(frameRate);
    coder.setTimeBase(IRational.make(frameRate.getDenominator(), frameRate.getNumerator()));
    coder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
    coder.setGlobalQuality(0);
    // coder.setNumPicturesInGroupOfPictures(fps);
    coder.setPixelType(pixFmt);

    frameNo = 0;
}
 
开发者ID:Helioviewer-Project,项目名称:JHelioviewer-SWHV,代码行数:24,代码来源:XuggleExporter.java

示例2: addImage

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
/**
 * 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++;
}
 
开发者ID:sensorstorm,项目名称:StormCV,代码行数:22,代码来源:StreamWriter.java

示例3: getConverter

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
/**
  * Gets the converter for converting images to pictures. 
  *
  * @param bgrImage the source image (must be type TYPE_3BYTE_BGR)
  * @param pixelType the desired pixel type
  */
private IConverter getConverter(BufferedImage bgrImage, IPixelFormat.Type pixelType){
	int w = bgrImage.getWidth();
	int h = bgrImage.getHeight();
	if (converterDim==null) {
		converterDim = new Dimension(w, h);
	}
	if (outConverter==null || w!=converterDim.width || h!=converterDim.height
			|| outConverter.getPictureType()!= pixelType) {
		try {
			outConverter = ConverterFactory.createConverter(bgrImage, pixelType);
			converterDim = new Dimension(w, h);
		} catch(UnsupportedOperationException e){
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
	}
	return outConverter;
}
 
开发者ID:OpenSourcePhysics,项目名称:video-engines,代码行数:25,代码来源:XuggleVideoRecorder.java

示例4: recordFrame

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
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);
		}
	}
}
 
开发者ID:phrack,项目名称:ShootOFF,代码行数:29,代码来源:RollingRecorder.java

示例5: recordFrame

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
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);
}
 
开发者ID:phrack,项目名称:ShootOFF,代码行数:14,代码来源:ShotRecorder.java

示例6: bufferedImageToMat

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
static Mat bufferedImageToMat(BufferedImage frame) {
	final BufferedImage transformedFrame = ConverterFactory.convertToType(frame, BufferedImage.TYPE_3BYTE_BGR);
	final byte[] pixels = ((DataBufferByte) transformedFrame.getRaster().getDataBuffer()).getData();
	final Mat mat = new Mat(frame.getHeight(), frame.getWidth(), CvType.CV_8UC3);
	mat.put(0, 0, pixels);

	return mat;
}
 
开发者ID:phrack,项目名称:ShootOFF,代码行数:9,代码来源:Camera.java

示例7: loadFirstFrame

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
/**
 * Loads the first frame of the given video and then seeks back to the beginning of the stream.
 * @param container the video container
 * @param videoCoder the video stream coder
 * @return BufferedImage
 * @throws MediaException thrown if an error occurs during decoding
 */
private BufferedImage loadFirstFrame(IContainer container, IStreamCoder videoCoder) throws MediaException {
	// walk through each packet of the container format
	IPacket packet = IPacket.make();
	while (container.readNextPacket(packet) >= 0) {
		// make sure the packet belongs to the stream we care about
		if (packet.getStreamIndex() == videoCoder.getStream().getIndex()) {
			// create a new picture for the video data to be stored in
			IVideoPicture picture = IVideoPicture.make(videoCoder.getPixelType(), videoCoder.getWidth(), videoCoder.getHeight());
			int offset = 0;
			// decode the video
			while (offset < packet.getSize()) {
				int bytesDecoded = videoCoder.decodeVideo(picture, packet, offset);
				if (bytesDecoded < 0) {
					LOGGER.error("No bytes found in container.");
					throw new MediaException();
				}
				offset += bytesDecoded;

				// make sure that we have a full picture from the video first
				if (picture.isComplete()) {
					// convert the picture to an Java buffered image
					BufferedImage target = new BufferedImage(picture.getWidth(), picture.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
					IConverter converter = ConverterFactory.createConverter(target, picture.getPixelType());
					return converter.toImage(picture);
				}
			}
		}
	}
	
	return null;
}
 
开发者ID:wnbittle,项目名称:praisenter,代码行数:39,代码来源:XugglerVideoMediaLoader.java

示例8: initialize

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
/**
 * Initializes the reader thread with the given media.
 * @param container the media container
 * @param videoCoder the media video decoder
 * @param audioCoder the media audio decoder
 * @param audioConversions the flag(s) for any audio conversions to must take place
 */
public void initialize(IContainer container, IStreamCoder videoCoder, IStreamCoder audioCoder, int audioConversions) {
	// assign the local variables
	this.outputWidth = 0;
	this.outputHeight = 0;
	this.videoConversionEnabled = false;
	this.scale = false;
	this.container = container;
	this.videoCoder = videoCoder;
	this.audioCoder = audioCoder;
	this.audioConversions = audioConversions;
	
	// create a packet for reading
	this.packet = IPacket.make();
	
	// create the image converter for the video
	if (videoCoder != null) {
		this.width = this.videoCoder.getWidth();
		this.height = this.videoCoder.getHeight();
		IPixelFormat.Type type = this.videoCoder.getPixelType();
		this.picture = IVideoPicture.make(type, this.width, this.height);
		BufferedImage target = new BufferedImage(this.width, this.height, BufferedImage.TYPE_3BYTE_BGR);
		this.videoConverter = ConverterFactory.createConverter(target, type);
	}
	
	// create a resuable container for the samples
	if (audioCoder != null) {
		this.samples = IAudioSamples.make(1024, this.audioCoder.getChannels());
	}
}
 
开发者ID:wnbittle,项目名称:praisenter,代码行数:37,代码来源:XugglerMediaReaderThread.java

示例9: addImage

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
/**
 * Add new image into video stream.
 */
@Override
public void addImage(final Image image) throws IOException {
    if (!isOpen()) {
        throw new IOException("Current object does not opened yet! Please call #open() method!");
    }

    final BufferedImage worksWithXugglerBufferedImage = convertToType(TypeConvert.toBufferedImage(image),
            BufferedImage.TYPE_3BYTE_BGR);
    final IPacket packet = IPacket.make();

    IConverter converter = null;
    try {
        converter = ConverterFactory.createConverter(worksWithXugglerBufferedImage, IPixelFormat.Type.YUV420P);
    } catch (final UnsupportedOperationException e) {
        throw new IOException(e.getMessage());
    }

    this.totalTimeStamp += this.incrementTimeStamp;
    final IVideoPicture outFrame = converter.toPicture(worksWithXugglerBufferedImage, this.totalTimeStamp);
    outFrame.setQuality(0);
    int retval = this.outStreamCoder.encodeVideo(packet, outFrame, 0);
    if (retval < 0) {
        throw new IOException("Could not encode video!");
    }

    if (packet.isComplete()) {
        retval = this.outContainer.writePacket(packet);
        if (retval < 0) {
            throw new IOException("Could not save packet to container!");
        }
    }
}
 
开发者ID:dzavodnikov,项目名称:JcvLib,代码行数:36,代码来源:VideoFileWriter.java

示例10: getBufferedImage

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
/**
  * Gets the BufferedImage for a specified Xuggle picture.
  *
  * @param picture the picture
  * @return the image, or null if unable to resample
  */
private BufferedImage getBufferedImage(IVideoPicture picture) {
   // if needed, convert picture into BGR24 format
	if (picture.getPixelType() != IPixelFormat.Type.BGR24) {
		if (resampler == null) {
      resampler = IVideoResampler.make(
      		picture.getWidth(), picture.getHeight(), IPixelFormat.Type.BGR24,
      		picture.getWidth(), picture.getHeight(), picture.getPixelType());
      if (resampler == null) {
      	OSPLog.warning("Could not create color space resampler"); //$NON-NLS-1$
      	return null;
      }
		}
     IVideoPicture newPic = IVideoPicture.make(resampler.getOutputPixelFormat(),
         picture.getWidth(), picture.getHeight());
     if (resampler.resample(newPic, picture) < 0
     		|| newPic.getPixelType() != IPixelFormat.Type.BGR24) {
     	OSPLog.warning("Could not encode video as BGR24"); //$NON-NLS-1$
     	return null;
     }
     picture = newPic;
	}

	// use IConverter to convert picture to buffered image
	if (converter==null) {
		ConverterFactory.Type type = ConverterFactory.findRegisteredConverter(
				ConverterFactory.XUGGLER_BGR_24);	  	
		converter = ConverterFactory.createConverter(type.getDescriptor(), picture);			
	}
	BufferedImage image = converter.toImage(picture);
	// garbage collect to play smoothly--but slows down playback speed significantly!
	if (playSmoothly)
		System.gc();
 	return image;		
}
 
开发者ID:OpenSourcePhysics,项目名称:video-engines,代码行数:41,代码来源:XuggleVideo.java

示例11: initDecoder

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
/**
 * See: https://github.com/MahatmaX/YADrone/blob/master/YADrone/src/de/yadrone/base/video/xuggler/XugglerDecoder.java
 */
private void initDecoder() throws XugglerException {
    if (!IVideoResampler.isSupported(IVideoResampler.Feature.FEATURE_COLORSPACECONVERSION)) {
        throw new XugglerException("You must install the GPL version of Xuggler (with IVideoResampler support) for this to work");
    }

    container = IContainer.make();
    if (container.open(is, null) < 0) {
        throw new XugglerException("could not open inputstream");
    }

    int numStreams = container.getNumStreams();

    videoStreamId = -1;
    videoCoder = null;
    for (int i = 0; i < numStreams; i++) {
        IStream stream = container.getStream(i);
        IStreamCoder coder = stream.getStreamCoder();

        if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
            videoStreamId = i;
            videoCoder = coder;
            break;
        }
    }
    if (videoStreamId == -1) {
        throw new XugglerException("could not find video stream");
    }

    if (videoCoder.open(null, null) < 0) {
        throw new XugglerException("could not open video decoder for container");
    }

    resampler = null;
    if (videoCoder.getPixelType() != IPixelFormat.Type.BGR24) {
        resampler = IVideoResampler.make(videoCoder.getWidth(), videoCoder.getHeight(), IPixelFormat.Type.BGR24, videoCoder.getWidth(), videoCoder.getHeight(), videoCoder.getPixelType());
        if (resampler == null) {
            throw new XugglerException("could not create color space resampler.");
        }
    }

    packet = IPacket.make();

    IVideoPicture picture = IVideoPicture.make(videoCoder.getPixelType(), videoCoder.getWidth(), videoCoder.getHeight());
    converter = ConverterFactory.createConverter(ConverterFactory.XUGGLER_BGR_24, picture);
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:49,代码来源:H264Decoder.java

示例12: hasNext

import com.xuggle.xuggler.video.ConverterFactory; //导入依赖的package包/类
@Override
public boolean hasNext() {
	while (container.readNextPacket(packet) >= 0) {
		frameID++;

		// Now we have a packet, let's see if it belongs to our video stream

		if (packet.getStreamIndex() == videoStreamId) {
			// We allocate a new picture to get the data out of Xuggle

			IVideoPicture picture = IVideoPicture.make(videoCoder.getPixelType(),
					videoCoder.getWidth(), videoCoder.getHeight());

			int offset = 0;
			while (offset < packet.getSize()) {
				// Now, we decode the video, checking for any errors.

				int bytesDecoded = videoCoder.decodeVideo(picture, packet, offset);
				if (bytesDecoded < 0)
					throw new RuntimeException("got error decoding video");
				offset += bytesDecoded;

				// Some decoders will consume data in a packet, but will not
				// be able to construct a full video picture yet.  Therefore
				// you should always check if you got a complete picture from
				// the decode.

				if (picture.isComplete()) {
					IVideoPicture newPic = picture;

					// If the resampler is not null, it means we didn't get the
					// video in BGR24 format and need to convert it into BGR24
					// format.

					if (resampler != null) {
						// we must resample
						newPic = IVideoPicture.make(
								resampler.getOutputPixelFormat(), picture.getWidth(),
								picture.getHeight());
						if (resampler.resample(newPic, picture) < 0)
							throw new RuntimeException(
									"could not resample video.");
					}

					if (newPic.getPixelType() != IPixelFormat.Type.BGR24)
						throw new RuntimeException(
								"could not decode video as BGR 24 bit data.");

					// convert the BGR24 to an Java buffered image
					if (converter == null) {
						converter = ConverterFactory.createConverter(bufferedImage, newPic.getPixelType());
					}

					bufferedImage = converter.toImage(newPic);
					return true;
				}
			}
		} else {
			// This packet isn't part of our video stream, so we just
			// silently drop it.
			do {
			} while (false);
		}
	}

	return false;
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:68,代码来源:XugglerSimplified.java


注:本文中的com.xuggle.xuggler.video.ConverterFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。