本文整理汇总了Java中com.xuggle.xuggler.IPixelFormat类的典型用法代码示例。如果您正苦于以下问题:Java IPixelFormat类的具体用法?Java IPixelFormat怎么用?Java IPixelFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IPixelFormat类属于com.xuggle.xuggler包,在下文中一共展示了IPixelFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import com.xuggle.xuggler.IPixelFormat; //导入依赖的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;
}
示例2: MBFImageConverter
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
public MBFImageConverter(
final IPixelFormat.Type pictureType, final int pictureWidth,
final int pictureHeight, final int imageWidth, final int imageHeight)
{
super(pictureType, pictureWidth, pictureHeight, imageWidth, imageHeight);
this.bimg.img = new MBFImage(imageWidth, imageHeight, ColourSpace.RGB);
this.buffer = new byte[imageWidth * imageHeight * 3];
}
示例3: setResampler
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
private void setResampler(IStreamCoder videoCoder) {
if (videoCoder.getCodecType() != ICodec.Type.CODEC_TYPE_VIDEO)
return;
resampler = null;
if (videoCoder.getPixelType() != IPixelFormat.Type.BGR24) {
// if this stream is not in BGR24, we're going to need to
// convert it. The VideoResampler does that for us.
resampler = IVideoResampler.make(videoCoder.getWidth(),
videoCoder.getHeight(), IPixelFormat.Type.BGR24,
videoCoder.getWidth(), videoCoder.getHeight(),
videoCoder.getPixelType());
if (resampler == null)
throw new RuntimeException("could not create color space "
+ "resampler for: " + videoCoder);
}
}
示例4: encodeImage
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
/**
* Encodes an image and writes it to the output stream.
*
* @param image the image to encode (must be BufferedImage.TYPE_3BYTE_BGR)
* @param pixelType the pixel type
* @param timeStamp the time stamp in microseconds
* @throws IOException
*/
private boolean encodeImage(BufferedImage image, IPixelFormat.Type pixelType, long timeStamp)
throws IOException {
// convert image to xuggle picture
IVideoPicture picture = getPicture(image, pixelType, timeStamp);
if (picture==null)
throw new RuntimeException("could not convert to picture"); //$NON-NLS-1$
// make a packet
IPacket packet = IPacket.make();
if (outStreamCoder.encodeVideo(packet, picture, 0) < 0) {
throw new RuntimeException("could not encode video"); //$NON-NLS-1$
}
if (packet.isComplete()) {
boolean forceInterleave = true;
if (outContainer.writePacket(packet, forceInterleave) < 0) {
throw new RuntimeException("could not save packet to container"); //$NON-NLS-1$
}
return true;
}
return false;
}
示例5: getConverter
import com.xuggle.xuggler.IPixelFormat; //导入依赖的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;
}
示例6: getHostImage
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
@Override
public IHostImage getHostImage(BlockingQueue<float[]> audioData) {
IHostImage result = null;
try {
final int w = getWidth();
final int h = getHeight();
IVideoPicture newPic = currentPicture.get();
if (resampler != null) {
if(tmpPicture == null)
tmpPicture = IVideoPicture.make(resampler.getOutputPixelFormat(), w, h);
newPic = tmpPicture;
if (resampler.resample(newPic, currentPicture.get()) < 0) {
log.warning("could not resample video");
return null;
}
}
if (newPic.getPixelType() != IPixelFormat.Type.RGB24) {
log.warning("could not decode video as RGB24 bit data");
return null;
}
ByteBuffer dstBuffer = BufferUtils.createByteBuffer(w * h * 3);
flip(newPic.getByteBuffer(), dstBuffer, w, h);
result = IHostImage.create(w, h, ComponentType.BYTE, ComponentFormat.RGB, dstBuffer);
if(!(this.audioData.isEmpty())) {
while(audioData.size() > (2 * this.audioData.size()) + 128)
audioData.take();
while(!(this.audioData.isEmpty()))
audioData.add(this.audioData.take());
}
} catch(Throwable t) {
log.warning(t);
}
return result;
}
示例7: recordFrame
import com.xuggle.xuggler.IPixelFormat; //导入依赖的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);
}
}
}
示例8: recordFrame
import com.xuggle.xuggler.IPixelFormat; //导入依赖的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);
}
示例9: initialize
import com.xuggle.xuggler.IPixelFormat; //导入依赖的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());
}
}
示例10: setEncodingParameters
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
/**
* A quick hack. Encoding paramaters are hard-coded here.
*
* @throws IOException
*/
@Override
public void setEncodingParameters() throws IOException {
containerFormat = IContainerFormat.make();
containerFormat.setOutputFormat("avi", null, null);
// ObjectOutputStream oos = new ObjectOutputStream();
// oos.writeObject(containerFormat);
streamCoders = new IStreamCoder[] { IStreamCoder
.make(IStreamCoder.Direction.ENCODING) };
ICodec codec = ICodec.guessEncodingCodec(containerFormat, null, null,
null, ICodec.Type.CODEC_TYPE_VIDEO);
streamCoders[0].setNumPicturesInGroupOfPictures(1);
streamCoders[0].setCodec(codec);
streamCoders[0].setBitRate(25000);
streamCoders[0].setBitRateTolerance(9000);
streamCoders[0].setPixelType(IPixelFormat.Type.YUV420P);
streamCoders[0].setWidth(352);
streamCoders[0].setHeight(288);
streamCoders[0].setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
streamCoders[0].setGlobalQuality(0);
IRational frameRate = IRational.make(25, 1);
streamCoders[0].setFrameRate(frameRate);
streamCoders[0].setTimeBase(IRational.make(frameRate.getDenominator(),
frameRate.getNumerator()));
}
示例11: addImage
import com.xuggle.xuggler.IPixelFormat; //导入依赖的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!");
}
}
}
示例12: saveScratch
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
/**
* Saves the video to the current scratchFile.
*
* @throws IOException
*/
@Override
protected void saveScratch() throws IOException {
FileFilter fileFilter = videoType.getDefaultFileFilter();
if (!hasContent || !(fileFilter instanceof VideoFileFilter))
return;
// set container format
IContainerFormat format = IContainerFormat.make();
VideoFileFilter xuggleFilter = (VideoFileFilter)fileFilter;
format.setOutputFormat(xuggleFilter.getContainerType(), null, null);
// set the pixel type--may depend on selected fileFilter?
IPixelFormat.Type pixelType = IPixelFormat.Type.YUV420P;
// open the output stream, write the images, close the stream
openStream(format, pixelType);
// open temp images and encode
long timeStamp = 0;
int n=0;
synchronized (tempFiles) {
for (File imageFile: tempFiles) {
if (!imageFile.exists())
throw new IOException("temp image file not found"); //$NON-NLS-1$
BufferedImage image = ResourceLoader.getBufferedImage(imageFile.getAbsolutePath(), BufferedImage.TYPE_3BYTE_BGR);
if (image==null || image.getType()!=BufferedImage.TYPE_3BYTE_BGR) {
throw new IOException("unable to load temp image file"); //$NON-NLS-1$
}
encodeImage(image, pixelType, timeStamp);
n++;
timeStamp = Math.round(n*frameDuration*1000); // frameDuration in ms, timestamp in microsec
}
}
closeStream();
deleteTempFiles();
hasContent = false;
canRecord = false;
}
示例13: getPicture
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
/**
* Converts a bgr source image to a xuggle picture.
*
* @param bgrImage the source image (must be type TYPE_3BYTE_BGR)
* @param pixelType the pixel type
* @param timeStamp the timestamp in microseconds
* @return the xuggle picture
*/
private IVideoPicture getPicture(BufferedImage bgrImage, IPixelFormat.Type pixelType, long timeStamp) {
IVideoPicture picture = null;
try {
IConverter converter = getConverter(bgrImage, pixelType);
picture = converter.toPicture(bgrImage, timeStamp);
picture.setQuality(0);
} catch (Exception ex) {
ex.printStackTrace();
} catch (Error err) {
err.printStackTrace();
}
return picture;
}
示例14: getBufferedImage
import com.xuggle.xuggler.IPixelFormat; //导入依赖的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;
}
示例15: getVideoPicture
import com.xuggle.xuggler.IPixelFormat; //导入依赖的package包/类
/**
* @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;
}