本文整理汇总了Java中com.xuggle.xuggler.IPacket.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java IPacket.getSize方法的具体用法?Java IPacket.getSize怎么用?Java IPacket.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.xuggle.xuggler.IPacket
的用法示例。
在下文中一共展示了IPacket.getSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadPacket
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
/**
* Loads a video packet into the current Xuggle picture.
*
* @param packet the packet
* @return true if successfully loaded
*/
private boolean loadPacket(IPacket packet) {
int offset = 0;
int size = packet.getSize();
while(offset < size) {
// decode the packet into the picture
int bytesDecoded = videoCoder.decodeVideo(picture, packet, offset);
// check for errors
if (bytesDecoded < 0)
return false;
offset += bytesDecoded;
if (picture.isComplete()) {
return true;
}
}
return true;
}
示例2: loadFirstFrame
import com.xuggle.xuggler.IPacket; //导入方法依赖的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;
}
示例3: decodeVideoPacket
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
/**
* Decode a Video Packet. Taken from Xuggler Demo file for Video decoding.
* @param packet
* @return
*/
private IVideoPicture decodeVideoPacket(IPacket packet) {
int c = 0;
for (c = 0; c < coder.length; c++)
if (coder[c] != null
&& coder[c].getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO)
break;
if (c >= coder.length)
return null;
IStreamCoder videoCoder = coder[c];
/*
* We allocate a new picture to get the data out of Xuggler
*/
IVideoPicture picture = IVideoPicture.make(videoCoder.getPixelType(),
videoCoder.getWidth(), videoCoder.getHeight());
if (!videoCoder.isOpen()) {
int o = videoCoder.open();
if (o < 0)
LOG.debug("error on open VideoCoder = " + o);
//setResampler(videoCoder);
}
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 in: "
+ packet.getPosition());
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 decoder
*/
if (picture.isComplete()) {
IVideoPicture newPic = picture;
/*
* If the resampler is not null, that 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 from: "
+ packet.getPosition());
}
return newPic;
}
}
return null;
}