本文整理汇总了Java中com.xuggle.xuggler.IStreamCoder类的典型用法代码示例。如果您正苦于以下问题:Java IStreamCoder类的具体用法?Java IStreamCoder怎么用?Java IStreamCoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IStreamCoder类属于com.xuggle.xuggler包,在下文中一共展示了IStreamCoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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: openJavaSound
import com.xuggle.xuggler.IStreamCoder; //导入依赖的package包/类
private static void openJavaSound(IStreamCoder aAudioCoder) {
AudioFormat audioFormat = new AudioFormat(aAudioCoder.getSampleRate(),
(int)IAudioSamples.findSampleBitDepth(aAudioCoder.getSampleFormat()),
aAudioCoder.getChannels(),
true, /* xuggler defaults to signed 16 bit samples */
false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
try
{
mLine = (SourceDataLine) AudioSystem.getLine(info);
/**
* if that succeeded, try opening the line.
*/
mLine.open(audioFormat);
/**
* And if that succeed, start the line.
*/
mLine.start();
}
catch (LineUnavailableException e)
{
throw new RuntimeException("could not open audio line");
}
}
示例3: getMeanGOPLength
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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;
}
示例4: setResampler
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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);
}
}
示例5: getAvgGOPLength
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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;
}
示例6: setStreamEncodings
import com.xuggle.xuggler.IStreamCoder; //导入依赖的package包/类
/**
* Not working yet.
*
* @param b
* @param off
* @param len
* @throws IOException
*/
@Override
public void setStreamEncodings(byte[] b, long off, long len)
throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(b);
ObjectInputStream ois = null;
ois = new ObjectInputStream(bis);
try {
streamCoders = (IStreamCoder[]) ois.readObject();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例7: loadFirstFrame
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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;
}
示例8: initialize
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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());
}
}
示例9: onAddStream
import com.xuggle.xuggler.IStreamCoder; //导入依赖的package包/类
@Override
public void onAddStream(IAddStreamEvent event) {
int streamIndex = event.getStreamIndex();
IStreamCoder streamCoder = event.getSource().getContainer()
.getStream(streamIndex).getStreamCoder();
if (streamCoder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
//writer.addAudioStream(streamIndex, streamIndex, 1, 16000);
writer.addAudioStream(1, 0,ICodec.ID.CODEC_ID_PCM_S16LE, 1, 16000);
}
super.onAddStream(event);
}
示例10: getMeanVideoFrameSize
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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();
}
示例11: printStreamInfo
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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);
}
示例12: XugglerOutputStream
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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();
}
示例13: setEncodingParameters
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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()));
}
示例14: open
import com.xuggle.xuggler.IStreamCoder; //导入依赖的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();
}
示例15: initialize
import com.xuggle.xuggler.IStreamCoder; //导入依赖的package包/类
/**
* Initializes this audio player thread with the given audio coder information.
* <p>
* Returns an integer representing any conversions that must be performed on the audio data.
* @param audioCoder the audio coder
* @return int
*/
public int initialize(IStreamCoder audioCoder) {
if (this.line != null) {
this.line.close();
this.line = null;
}
// make sure the given audio coder is not null
// this can happen with videos that are just video
if (audioCoder != null) {
int result = XugglerAudioData.CONVERSION_NONE;
int sampleRate = audioCoder.getSampleRate();
int bitDepth = (int)IAudioSamples.findSampleBitDepth(audioCoder.getSampleFormat());
int channels = audioCoder.getChannels();
// attempt to use the media's audio format
AudioFormat format = new AudioFormat(sampleRate, bitDepth, channels, true, false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
// see if its supported
if (!AudioSystem.isLineSupported(info)) {
// if its not supported, this is typically due to the number of playback channels
// lets try the same format with just 2 channels (stereo)
if (channels > 2) {
format = new AudioFormat(sampleRate, bitDepth, 2, true, false);
info = new DataLine.Info(SourceDataLine.class, format);
// check if its supported
if (AudioSystem.isLineSupported(info)) {
// flag that downmixing must take place
result |= XugglerAudioData.CONVERSION_TO_STEREO;
}
}
// if its still not supported check the bit depth
if (!AudioSystem.isLineSupported(info)) {
// otherwise it could be due to the bit depth
// use either the audio format or the down mixed format
AudioFormat source = format;
// try to see if converting it to 16 bit will work
AudioFormat target = new AudioFormat(sampleRate, 16, format.getChannels(), true, false);
if (AudioSystem.isConversionSupported(target, source)) {
// setup the line
info = new DataLine.Info(SourceDataLine.class, target);
format = target;
// flag that a bit depth conversion must take place
result |= XugglerAudioData.CONVERSION_TO_BIT_DEPTH_16;
} else {
// if we still can't get it to be supported just give up and log a message
LOGGER.warn("The audio format is not supported by JavaSound and could not be converted: " + format);
this.line = null;
return -1;
}
}
}
try {
// create and open JavaSound
this.line = (SourceDataLine)AudioSystem.getLine(info);
this.line.open(format);
this.line.start();
return result;
} catch (LineUnavailableException e) {
// if a line isn't available then just dont play any sound
// and just continue normally
LOGGER.error("Line not available for audio playback: ", e);
this.line = null;
return -1;
}
}
return -1;
}