本文整理汇总了Java中com.xuggle.xuggler.IStream类的典型用法代码示例。如果您正苦于以下问题:Java IStream类的具体用法?Java IStream怎么用?Java IStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IStream类属于com.xuggle.xuggler包,在下文中一共展示了IStream类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMeanGOPLength
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
public static int getMeanGOPLength(IContainer container) throws CannotProceedException, IOException {
int numStreams = container.getNumStreams();
if( numStreams <= 0 )
throw new IOException( "No streams found in container." );
List<IIndexEntry> index_list = null;
for( int j = 0; j < container.getNumStreams(); j++ ) {
IStream stream = container.getStream(j);
IStreamCoder coder = stream.getStreamCoder();
if( coder.getCodecType() != ICodec.Type.CODEC_TYPE_VIDEO)
continue;
index_list = stream.getIndexEntries();
}
if( index_list == null || index_list.size() == 0)
throw new CannotProceedException( "No index entries found!" );
int k = 0;
for( int i = 0; i < index_list.size(); i++ )
if ( index_list.get(i).isKeyFrame() ) k++;
return index_list.size() / k;
}
示例2: getAvgGOPLength
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
public long getAvgGOPLength(){
List<IIndexEntry> index_list = null;
IStream videostream = null;
for( int j = 0; j < container.getNumStreams(); j++ ) {
IStream stream = container.getStream(j);
IStreamCoder coder = stream.getStreamCoder();
if( coder.getCodecType() != ICodec.Type.CODEC_TYPE_VIDEO)
continue;
index_list = stream.getIndexEntries();
videostream = stream;
}
// TODO: generalize MediaFramework interface to deal with audio too (where not videostream is contained)
if( index_list == null || index_list.isEmpty() )
return videostream.getNumFrames();
int k = 0;
for( int i = 0; i < index_list.size(); i++ )
if ( index_list.get(i).isKeyFrame() ) k++;
return index_list.size() / k;
}
示例3: setupReader
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
private void setupReader(IContainer container) {
// Set up a new reader using the container that reads the images.
this.reader = ToolFactory.makeReader(container);
this.reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
this.reader.addListener(new FrameGetter());
// Find the video stream.
IStream s = null;
int i = 0;
while (i < container.getNumStreams()) {
s = container.getStream(i);
if (s != null && s.getStreamCoder().getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
// Save the stream index so that we only get frames from
// this stream in the FrameGetter
this.streamIndex = i;
break;
}
i++;
}
if (container.getDuration() == Global.NO_PTS)
this.totalFrames = -1;
else
this.totalFrames = (long) (s.getDuration() *
s.getTimeBase().getDouble() * s.getFrameRate().getDouble());
// If we found the video stream, set the FPS
if (s != null)
this.fps = s.getFrameRate().getDouble();
// If we found a video stream, setup the MBFImage buffer.
if (s != null) {
final int w = s.getStreamCoder().getWidth();
final int h = s.getStreamCoder().getHeight();
this.width = w;
this.height = h;
}
}
示例4: makeWriter
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
/**
* Make a video writer for the given path and dimensions
* @param path
* @param width
* @param height
*/
private void makeWriter(String path, int width, int height){
writer = IContainer.make();
writer.open(path, IContainer.Type.WRITE, null);
ICodec videoCodec = ICodec.findEncodingCodec(codec);
IStream videoStream = writer.addNewStream(videoCodec);
coder = videoStream.getStreamCoder();
IRational fr = IRational.make(frameRate, 1);
coder.setWidth(width);
coder.setHeight(height);
coder.setFrameRate(fr);
coder.setTimeBase(IRational.make(fr.getDenominator(), fr.getNumerator()));
coder.setNumPicturesInGroupOfPictures(frameRate);
if(bitrate > 0) coder.setBitRate(bitrate);
//coder.setBitRateTolerance(100000);
coder.setPixelType(Type.YUV420P);
//coder.setFlag(IStreamCoder.Flags.FLAG2_FAST, true);
//coder.setGlobalQuality(0);
if(ffmpegParams != null){
IMetaData options = IMetaData.make();
for(int i=0; i<ffmpegParams.length; i+=2){
options.setValue(ffmpegParams[i], ffmpegParams[i+1]);
}
coder.open(options, null);
}else{
coder.open(null, null);
}
writer.writeHeader();
this.frameTime = 0;
}
示例5: getMeanVideoFrameSize
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
/**
* Calculates average frame size in bytes of the video stream of the given container.
* @param container
* @return
* @throws IOException
* @throws CannotProceedException
*/
public static int getMeanVideoFrameSize( IContainer container ) throws IOException, CannotProceedException {
int numStreams = container.getNumStreams();
if( numStreams <= 0 )
throw new IOException( "No streams found in container." );
List<IIndexEntry> index_list = null;
for( int j = 0; j < container.getNumStreams(); j++ ) {
IStream stream = container.getStream(j);
IStreamCoder coder = stream.getStreamCoder();
if( coder.getCodecType() != ICodec.Type.CODEC_TYPE_VIDEO)
continue;
index_list = stream.getIndexEntries();
}
if( index_list == null || index_list.size() == 0)
throw new CannotProceedException( "No index entries found!" );
BigInteger avg_size = new BigInteger("0");
for( int i = 0; i < index_list.size(); i++ )
avg_size = avg_size.add( new BigInteger( index_list.get(i).getSize() + "") );
avg_size = avg_size.divide( new BigInteger( index_list.size() + "" ));
return avg_size.intValue();
}
示例6: printStreamInfo
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
private void printStreamInfo(IStream stream) {
IStreamCoder coder = stream.getStreamCoder();
IContainer container = stream.getContainer();
String info = "";
info += (String.format("type: %s; ", coder.getCodecType()));
info += (String.format("codec: %s; ", coder.getCodecID()));
info += String.format(
"duration: %s; ",
stream.getDuration() == Global.NO_PTS ? "unknown" : ""
+ stream.getDuration());
info += String.format("start time: %s; ",
container.getStartTime() == Global.NO_PTS ? "unknown" : ""
+ stream.getStartTime());
info += String
.format("language: %s; ",
stream.getLanguage() == null ? "unknown" : stream
.getLanguage());
info += String.format("timebase: %d/%d; ", stream.getTimeBase()
.getNumerator(), stream.getTimeBase().getDenominator());
info += String.format("coder tb: %d/%d; ", coder.getTimeBase()
.getNumerator(), coder.getTimeBase().getDenominator());
if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
info += String.format("sample rate: %d; ", coder.getSampleRate());
info += String.format("channels: %d; ", coder.getChannels());
info += String.format("format: %s", coder.getSampleFormat());
} else if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
info += String.format("width: %d; ", coder.getWidth());
info += String.format("height: %d; ", coder.getHeight());
info += String.format("format: %s; ", coder.getPixelType());
info += String.format("frame-rate: %5.2f; ", coder.getFrameRate()
.getDouble());
}
LOG.debug(info);
}
示例7: XugglerOutputStream
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
public XugglerOutputStream( OutputStream out, XugglerCompressor compressor ) {
super(out);
outContainer = IContainer.make();
this.compressor = compressor;
int retval = outContainer.open(out, compressor.getContainerFormat() );
if (retval <0)
throw new RuntimeException("could not open output stream");
IStreamCoder[] streamCoders = compressor.getStreamCoders();
outStreams = new IStream[ streamCoders.length ];
for( int i = 0; i < streamCoders.length; i++ ) {
outStreams[i] = outContainer.addNewStream(i);
outStreams[i].setStreamCoder( streamCoders[i] );
streamCoders[i].open();
}
outContainer.writeHeader();
}
示例8: open
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private void open(URLVideoSource src) throws IOException {
try {
if("file".equals(src.getURL().getProtocol())) {
File f = new File(src.getURL().toURI());
if (container.open(f.getAbsolutePath(), IContainer.Type.READ, null) < 0)
throw new IOException("could not open " + f.getAbsolutePath());
} else {
String urlStr = TextUtilities.toString(src.getURL());
if (container.open(urlStr, IContainer.Type.READ, null) < 0)
throw new IOException("could not open " + urlStr);
}
} catch(URISyntaxException e) {
throw new IOException(e);
}
// query how many streams the call to open found
int numStreams = container.getNumStreams();
// and iterate through the streams to find the first audio stream
int videoStreamId = -1;
int audioStreamId = -1;
for(int i = 0; i < numStreams; i++) {
// Find the stream object
IStream stream = container.getStream(i);
// Get the pre-configured decoder that can decode this stream;
IStreamCoder coder = stream.getStreamCoder();
if (videoStreamId == -1 && coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
videoStreamId = i;
videoStream = stream;
videoCoder = coder;
}
else if (audioStreamId == -1 && coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
audioStreamId = i;
audioStream = stream;
audioCoder = coder;
audioFormat = new AudioFormat(
audioCoder.getSampleRate(),
(int)IAudioSamples.findSampleBitDepth(audioCoder.getSampleFormat()),
audioCoder.getChannels(),
true, /* xuggler defaults to signed 16 bit samples */
false);
}
}
if (videoStreamId == -1 && audioStreamId == -1)
throw new IOException("could not find audio or video stream in container in " + src);
/*
* Check if we have a video stream in this file. If so let's open up our decoder so it can
* do work.
*/
if (videoCoder != null) {
if(videoCoder.open() < 0)
throw new IOException("could not open audio decoder for container " + src);
if (videoCoder.getPixelType() != IPixelFormat.Type.RGB24) {
resampler = IVideoResampler.make(
videoCoder.getWidth(), videoCoder.getHeight(),
IPixelFormat.Type.RGB24,
videoCoder.getWidth(), videoCoder.getHeight(),
videoCoder.getPixelType());
if (resampler == null)
throw new IOException("could not create color space resampler for " + src);
}
}
if (audioCoder != null) {
if (audioCoder.open() < 0)
throw new IOException("could not open audio decoder for container: " + src);
}
decoderThread = new Thread(this, src.getURL().toString());
decoderThread.setPriority(Thread.MIN_PRIORITY);
decoderThread.setDaemon(true);
doDecode.set(true);
decoderThread.start();
}
示例9: load
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
@Override
public XugglerAudioMedia load(String basePath, String filePath) throws MediaException {
// create the video container object
IContainer container = IContainer.make();
// open the container format
if (container.open(filePath, IContainer.Type.READ, null) < 0) {
LOGGER.error("Could not open container: [" + filePath + "].");
throw new UnsupportedMediaException(filePath);
}
// convert to seconds
long length = container.getDuration() / 1000 / 1000;
String format = container.getContainerFormat().getInputFormatLongName() + " [";
LOGGER.debug("Audio file opened. Container format: " + container.getContainerFormat().getInputFormatLongName());
// query how many streams the call to open found
int numStreams = container.getNumStreams();
LOGGER.debug("Stream count: " + numStreams);
// loop over the streams to find the first audio stream
IStreamCoder audioCoder = null;
for (int i = 0; i < numStreams; i++) {
IStream stream = container.getStream(i);
// get the coder for the stream
IStreamCoder coder = stream.getStreamCoder();
// check for an audio stream
if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
audioCoder = coder;
}
}
// make sure we have a video stream
if (audioCoder == null) {
LOGGER.error("No audio coder found in container: [" + filePath + "].");
throw new UnsupportedMediaException(filePath);
}
// check audio
if (audioCoder != null) {
format += " " + audioCoder.getCodec().getLongName();
}
format += "]";
AudioMediaFile file = new AudioMediaFile(
basePath,
filePath,
format,
length);
// create the media object
XugglerAudioMedia media = new XugglerAudioMedia(file);
// clean up
if (container != null) {
container.close();
}
// return the media
return media;
}
示例10: testBasicInfo
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
@Test
public void testBasicInfo() {
// first we create a Xuggler container object
IContainer container = IContainer.make();
// we attempt to open up the container
int result = container.open(filename, IContainer.Type.READ, null);
// check if the operation was successful
if (result < 0)
throw new RuntimeException("Failed to open media file");
// query how many streams the call to open found
int numStreams = container.getNumStreams();
// query for the total duration
long duration = container.getDuration();
// query for the file size
long fileSize = container.getFileSize();
// query for the bit rate
long bitRate = container.getBitRate();
System.out.println("Number of streams: " + numStreams);
System.out.println("Duration (ms): " + duration);
System.out.println("File Size (bytes): " + fileSize);
System.out.println("Bit Rate: " + bitRate);
// iterate through the streams to print their meta data
for (int i = 0; i < numStreams; i++) {
// find the stream object
IStream stream = container.getStream(i);
// get the pre-configured decoder that can decode this stream;
IStreamCoder coder = stream.getStreamCoder();
System.out.println("*** Start of Stream Info ***");
System.out.printf("stream %d: ", i);
System.out.printf("type: %s; ", coder.getCodecType());
System.out.printf("codec: %s; ", coder.getCodecID());
System.out.printf("duration: %s; ", stream.getDuration());
System.out.printf("start time: %s; ", container.getStartTime());
System.out.printf("timebase: %d/%d; ", stream.getTimeBase()
.getNumerator(), stream.getTimeBase().getDenominator());
System.out.printf("coder tb: %d/%d; ", coder.getTimeBase()
.getNumerator(), coder.getTimeBase().getDenominator());
System.out.println();
if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
System.out.printf("sample rate: %d; ", coder.getSampleRate());
System.out.printf("channels: %d; ", coder.getChannels());
System.out.printf("format: %s", coder.getSampleFormat());
} else if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
System.out.printf("width: %d; ", coder.getWidth());
System.out.printf("height: %d; ", coder.getHeight());
System.out.printf("format: %s; ", coder.getPixelType());
System.out.printf("frame-rate: %5.2f; ", coder.getFrameRate()
.getDouble());
}
System.out.println();
System.out.println("*** End of Stream Info ***");
}
}
示例11: XugglerInputStream
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
public XugglerInputStream(InputStream in, long start, long end, long frame_offset, XugglerDecompressor dec)
throws IOException {
super(in, start, end);
this.frame_offset = frame_offset;
decompressor = dec;
FSDataInputStream fIn = (FSDataInputStream) in;
int header_size = (int) dec.getHeaderSize();
byte[] header = new byte[header_size];
// read header
fIn.seek(0);
int b = fIn.read(header, 0, header_size);
LOG.debug( "header read, count bytes: " + b );
LOG.debug( "after header reading, fIn.pos = " + fIn.getPos() );
xfsdis = new XugglerFSDataInputStream(in, start, end);
xfsdis.setHeader( header );
this.container = IContainer.make();
// IMetaData metadata = container.getMetaData();
// format.setInputFlag(IContainerFormat.Flags.FLAG_GLOBALHEADER, true);
// this.container.setParameters(parameters);
int r = this.container.open( xfsdis, null);
LOG.debug("container.open = " + r);
if (r < 0) {
IError error = IError.make(r);
LOG.debug("error: " + error.getDescription());
throw new IOException( "Could not create Container from given InputStream");
}
// store container info: streams, coders ... whatever is needed later for decoding
int numStreams = this.container.getNumStreams();
this.streams = new IStream[numStreams];
this.coder = new IStreamCoder[numStreams];
this.streamTypes = new Type[numStreams];
for (int s = 0; s < this.streams.length; s++) {
this.streams[s] = this.container.getStream(s);
printStreamInfo(streams[s]);
this.coder[s] = this.streams[s] != null ? this.streams[s].getStreamCoder() : null;
this.streamTypes[s] = this.coder[s] != null ? this.coder[s].getCodecType() : null;
}
//testDecoding();
}
示例12: VideoFileWriter
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
/**
* Create new object for write video into the file.
*
* @param filePath
* Path to file for output.
* @param sizeOfVideo
* Size of video for saving.
* @param FPS
* <a href="http://en.wikipedia.org/wiki/Frame_rate">Frame rate per second</a> in Hz.
* @param numPicturesInGroupOfPictures
* Determines the number of interframes between each keyframe.
* @param bitRate
* Bit rate of video in Kbit per second (kbps). You can use 32 kbps, 64 kbps, 128 kbps, 256 kbps and so
* on. The relationship between the bit rate and the size of your video is also not quite linear. I've
* found that setting the bit rate too low actually increases the size of the video. Why this is I don't
* know, but just as a precaution you might want to play with the bit rate a little bit.
*/
public VideoFileWriter(final String filePath, final Size sizeOfVideo, final int FPS,
final int numPicturesInGroupOfPictures, final int bitRate) throws IOException {
this.outContainer = IContainer.make();
JCV.verifyIsNotNull(filePath);
int retval = this.outContainer.open(filePath, IContainer.Type.WRITE, null);
if (retval < 0) {
throw new IOException("Could not open output file!");
}
final ICodec codec = ICodec.guessEncodingCodec(null, null, filePath, null, ICodec.Type.CODEC_TYPE_VIDEO);
if (codec == null) {
throw new IOException("Could not guess a codec!");
}
final IStream outStream = this.outContainer.addNewStream(codec);
this.outStreamCoder = outStream.getStreamCoder();
this.outStreamCoder.setNumPicturesInGroupOfPictures(numPicturesInGroupOfPictures);
this.outStreamCoder.setBitRate(1000 * bitRate);
this.outStreamCoder.setPixelType(IPixelFormat.Type.YUV420P);
JCV.verifyIsNotNull(sizeOfVideo);
this.outStreamCoder.setWidth(sizeOfVideo.getWidth());
this.outStreamCoder.setHeight(sizeOfVideo.getHeight());
this.outStreamCoder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
this.outStreamCoder.setGlobalQuality(0); // Sets the video encoding to the highest quality.
if (FPS < 0) {
throw new IllegalArgumentException("Parameter 'FPS' must be more than 0!");
}
final IRational frameRate = IRational.make(FPS, 1); // Number of images per second of your end result video.
this.incrementTimeStamp = Math.round(1000000.0 / FPS);
this.outStreamCoder.setFrameRate(frameRate);
this.outStreamCoder.setTimeBase(IRational.make(frameRate.getDenominator(), frameRate.getNumerator()));
retval = this.outStreamCoder.open(null, null);
if (retval < 0) {
throw new IOException("Could not open input decoder!");
}
retval = this.outContainer.writeHeader();
if (retval < 0) {
throw new IOException("Could not write file header!");
}
this.isOpen = false;
}
示例13: play
import com.xuggle.xuggler.IStream; //导入依赖的package包/类
/**
* Plays the video stream, or resumes it if it was paused
*/
public void play() {
if(container == null) {
// Create a Xuggler container object
container = IContainer.make();
}
if(!container.isOpened()) {
// Open up the container
if (container.open(inputStream, null) < 0) {
throw new RuntimeException("Could not open video file: " + videoPath);
}
// Query how many streams the call to open found
int numStreams = container.getNumStreams();
// Iterate through the streams to find the first video stream
for (int i = 0; i < numStreams; i++) {
// Find the stream object
IStream stream = container.getStream(i);
// Get the pre-configured decoder that can decode this stream;
IStreamCoder coder = stream.getStreamCoder();
if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
videoStreamId = i;
videoCoder = coder;
break;
}
}
if (videoStreamId == -1) {
throw new RuntimeException("Could not find video stream in container: " + videoPath);
}
/* Now we have found the video stream in this file. Let's open up our
* decoder so it can do work
*/
if (videoCoder.open() < 0) {
throw new RuntimeException("Could not open video decoder for container: " + videoPath);
}
if (videoCoder.getPixelType() != IPixelFormat.Type.BGR24) {
// If this stream is not in BGR24, we're going to need to convert it
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");
}
}
/* Query the first timestamp in the stream
* Timestamps are in microseconds - convert to milli
*/
firstTimestampMilliseconds = container.getStartTime() / 1000;
}
playState = PlayState.PLAYING;
}