本文整理汇总了Java中com.xuggle.xuggler.IPixelFormat.Type方法的典型用法代码示例。如果您正苦于以下问题:Java IPixelFormat.Type方法的具体用法?Java IPixelFormat.Type怎么用?Java IPixelFormat.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.xuggle.xuggler.IPixelFormat
的用法示例。
在下文中一共展示了IPixelFormat.Type方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例4: 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;
}
示例5: 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());
}
}
示例6: 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;
}
示例7: 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;
}
示例8: openStream
import com.xuggle.xuggler.IPixelFormat; //导入方法依赖的package包/类
/**
* Opens/initializes the output stream using a specified Xuggle format.
*
* @param format the format
* @param pixelType the pixel type
* @throws IOException
*/
private boolean openStream(IContainerFormat format, IPixelFormat.Type pixelType)
throws IOException {
outContainer = IContainer.make();
if (outContainer.open(scratchFile.getAbsolutePath(), IContainer.Type.WRITE, format)<0) {
OSPLog.finer("Xuggle could not open output file"); //$NON-NLS-1$
return false;
}
String typicalName = "typical."+videoType.getDefaultExtension(); //$NON-NLS-1$
ICodec codec = ICodec.guessEncodingCodec(format, null, typicalName, null, ICodec.Type.CODEC_TYPE_VIDEO);
outStream = outContainer.addNewStream(0);
outStreamCoder = outStream.getStreamCoder();
outStreamCoder.setNumPicturesInGroupOfPictures(10);
outStreamCoder.setCodec(codec);
outStreamCoder.setBitRate(250000);
// outStreamCoder.setBitRateTolerance(9000);
outStreamCoder.setPixelType(pixelType);
if(dim==null && frameImage!=null) {
dim = new Dimension(frameImage.getWidth(null), frameImage.getHeight(null));
}
if(dim!=null) {
outStreamCoder.setHeight(dim.height);
outStreamCoder.setWidth(dim.width);
}
// outStreamCoder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
// outStreamCoder.setGlobalQuality(0);
IRational frameRate = IRational.make(1000/frameDuration);
boolean hasTimeBaseLimit = typicalName.endsWith(".avi") || typicalName.endsWith(".mpg"); //$NON-NLS-1$ //$NON-NLS-2$
if (hasTimeBaseLimit && frameRate.getDenominator()>65535) { // maximum timebase = 2^16 - 1
double fps = 1000/frameDuration;
int denom = 63000; // 7 x 9000
int numer = Math.round(Math.round(fps*denom));
frameRate = IRational.make(numer, denom);
}
outStreamCoder.setFrameRate(frameRate);
// set time base to inverse of frame rate
outStreamCoder.setTimeBase(IRational.make(frameRate.getDenominator(),
frameRate.getNumerator()));
// // some codecs require experimental mode to be set? (and all accept it??)
// if (outStreamCoder.setStandardsCompliance(IStreamCoder.CodecStandardsCompliance.COMPLIANCE_EXPERIMENTAL) < 0) {
// OSPLog.finer("Xuggle could not set compliance mode to experimental"); //$NON-NLS-1$
// return false;
// }
if (outStreamCoder.open()<0) {
OSPLog.finer("Xuggle could not open stream encoder"); //$NON-NLS-1$
return false;
}
if (outContainer.writeHeader()<0) {
OSPLog.finer("Xuggle could not write file header"); //$NON-NLS-1$
return false;
}
return true;
}