本文整理汇总了Java中com.xuggle.xuggler.IPacket.make方法的典型用法代码示例。如果您正苦于以下问题:Java IPacket.make方法的具体用法?Java IPacket.make怎么用?Java IPacket.make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.xuggle.xuggler.IPacket
的用法示例。
在下文中一共展示了IPacket.make方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addImage
import com.xuggle.xuggler.IPacket; //导入方法依赖的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++;
}
示例2: readPacket
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
public AVPacket readPacket() {
IPacket packet = IPacket.make();
XugglerPacket xpacket = null;
if (this.container.readNextPacket(packet) >= 0) {
printPacketInfo(packet);
xpacket = new XugglerPacket(packet,
streamTypes[packet.getStreamIndex()]);
} else
finished = true;
if (xpacket != null) {
// calc position of the packet relative to the whole video
long pos = xpacket.getPosition() - decompressor.getHeaderSize()
+ getAdjustedStart();
xpacket.setPosition(pos);
xpacket.setFrameNo(xpacket.getFrameNo() + getFrameOffset());
LOG.debug("readPacket, frame no " + xpacket.getFrameNo());
}
return xpacket;
}
示例3: encode
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
public void encode( AVPacket packet ) {
IPacket ipacket = (IPacket)packet.getPacket();
int streamNum = ipacket.getStreamIndex();
ipacket = IPacket.make();
printPacketInfo(ipacket);
IVideoPicture picture = (IVideoPicture)packet.getDecodedObject();
if( picture == null ) {
LOG.debug("Picture is null" );
return;
} else
{
printPictureInfo(picture);
}
if( streamNum < outStreams.length ) {
LOG.debug( "Coder Bitrate: " + outStreams[streamNum].getStreamCoder().getBitRate());
LOG.debug( "Coder Name: " + outStreams[streamNum].getStreamCoder().getCodec().getName());
int retVal = outStreams[streamNum].getStreamCoder().encodeVideo( ipacket, picture, -1);
LOG.debug("encoding, retval = " + retVal );
if( ipacket.isComplete() )
{
//packet = new XugglerPacket( ipacket, ICodec.Type.CODEC_TYPE_VIDEO );
packet.setPacket( ipacket );
}
}
}
示例4: encodeImage
import com.xuggle.xuggler.IPacket; //导入方法依赖的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: run
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
public void run() {
while (doStream) {
IVideoPicture frame = frames.poll();
if (frame != null) {
// mark as keyframe
//frame.setKeyFrame(i % keyFrameInterval == 0);
//frame.setQuality(0);
IPacket packet = IPacket.make();
try {
coder.encodeVideo(packet, frame, 0);
if (packet.isComplete()) {
container.writePacket(packet);
}
} finally {
frame.delete();
if (packet != null) {
packet.delete();
}
}
} else {
try {
Thread.sleep(16L);
} catch (InterruptedException e) {
}
}
}
System.out.println("Frame worker exit");
}
示例6: 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;
}
示例7: initialize
import com.xuggle.xuggler.IPacket; //导入方法依赖的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());
}
}
示例8: close
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
public void close(){
if(writer != null){
// write last packets
IPacket packet = IPacket.make();
do{
coder.encodeVideo(packet, null, 0);
if(packet.isComplete()){
writer.writePacket(packet);
}
}while(packet.isComplete());
writer.flushPackets();
writer.close();
writer = null;
coder = null;
fileCount++;
frameCount = 0;
// move video to final location (can be remote!)
if(location != null) try {
connector.moveTo(location+currentFile.getName());
logger.info("Moving video to final location: "+location+currentFile.getName());
connector.copyFile(currentFile, true);
} catch (IOException e) {
logger.error("Unable to move file to final destinaiton: location", e);
}
}
}
示例9: writeBufferedImage
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
public boolean writeBufferedImage( BufferedImage image ) {
BufferedImage worksWithXugglerBufferedImage = XugglerPacket.convertToType(
image, BufferedImage.TYPE_3BYTE_BGR);
IPacket packet = IPacket.make();
//IConverter converter = ConverterFactory.createConverter(
//worksWithXugglerBufferedImage, compressor.);
return false;
}
示例10: addImage
import com.xuggle.xuggler.IPacket; //导入方法依赖的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!");
}
}
}
示例11: encodeVideo
import com.xuggle.xuggler.IPacket; //导入方法依赖的package包/类
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");
}
}