Package com.xuggle.xuggler

Examples of com.xuggle.xuggler.IStream


        coder = mCoders.get(i);
        if (coder == null)
        {
          // now get the coder for the given stream index
         
          IStream stream = getContainer().getStream(i);
          try
          {
            coder = stream.getStreamCoder();

            // put the coder into the coder map, event if it not a supported
            // type so that on further reads it will find the coder but choose
            // not decode unsupported types

            mCoders.put(i, coder);
            // and release our coder to the list
            coder = null;
            super.onAddStream(new AddStreamEvent(this, i));
          }
          finally
          {
            if (coder != null) coder.delete();
            if (stream != null)
              stream.delete();
          }
        }
      }
    }
    coder = mCoders.get(streamIndex);
    IStream stream = getContainer().getStream(streamIndex);
    try
    {
      ICodec.Type type = coder.getCodecType();

      // if the coder is not open, open it
      // NOTE: MediaReader currently supports audio & video streams

      if (!coder.isOpen()
          && (type == ICodec.Type.CODEC_TYPE_AUDIO || type == ICodec.Type.CODEC_TYPE_VIDEO))
      {
        if (coder.open() < 0)
          throw new RuntimeException("could not open coder for stream: "
              + streamIndex);
        mOpenedStreams.add(stream);
        super.onOpenCoder(new OpenCoderEvent(this, stream.getIndex()));
        stream = null;
      }
    } finally {
      if (stream != null)
        stream.delete();
    }
    // return back the reference we had
    return coder;
  }
View Full Code Here


    // add the audio stream

    ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_MP3);
    IContainer container = writer.getContainer();
    IStream stream = container.getStream(
        writer.addAudioStream(audioStreamIndex, audioStreamId,
            codec, channelCount, sampleRate));
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);
View Full Code Here

    ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_MP3);
    IContainer container = writer.getContainer();
    int streamIndex = writer.addAudioStream(
        audioStreamIndex, audioStreamId, codec, channelCount, sampleRate);
    IStream stream = container.getStream(streamIndex);
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);
View Full Code Here

    // add the audio stream

    ICodec audioCodec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_MP3);
    IContainer container = writer.getContainer();
    IStream stream = container.getStream(writer.addAudioStream(audioStreamIndex, audioStreamId,
      audioCodec, channelCount, sampleRate));
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples and video pictures

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);
    IVideoPicture picture = IVideoPicture.make(IPixelFormat.Type.YUV420P, w, h);
View Full Code Here

    // add the audio stream

    ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_MP3);
    IContainer container = writer.getContainer();
    IStream stream = container.getStream(
        writer.addAudioStream(audioStreamIndex, audioStreamId,
            codec, channelCount, sampleRate));
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);
View Full Code Here

    // add the audio stream

    ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_MP3);
    IContainer container = writer.getContainer();
    IStream stream = container.getStream(
        writer.addAudioStream(audioStreamIndex, audioStreamId,
            codec, channelCount, sampleRate));
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);
View Full Code Here

    int videoStreamId = -1;
    IStreamCoder videoCoder = null;
    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;
View Full Code Here

      throw new IllegalArgumentException(
        "invalid sample rate " + sampleRate);

    // add the new stream at the correct index

    IStream stream = establishStream(inputIndex, streamId, codec);
   
    // configre the stream coder

    IStreamCoder coder = stream.getStreamCoder();
    coder.setChannels(channelCount);
    coder.setSampleRate(sampleRate);
    coder.setSampleFormat(DEFAULT_SAMPLE_FORMAT);

    // add the stream to the media writer
   
    addStream(stream, inputIndex, stream.getIndex());

    // return the new audio stream

    return stream.getIndex();
  }
View Full Code Here

    int sampleRate = -1;
    int channels = -1;
   
    IContainer container = IContainer.make();
    container.open("fixtures/testfile.mp3", IContainer.Type.READ, null);
    IStream stream = container.getStream(0);
   
    // get the audio stream
    mCoder = stream.getStreamCoder();
    bitRate = mCoder.getBitRate();
    height = mCoder.getHeight();
    width = mCoder.getWidth();
    timebase = mCoder.getTimeBase();
    gops = mCoder.getNumPicturesInGroupOfPictures();
    pixFmt = mCoder.getPixelType();
    sampleRate = mCoder.getSampleRate();
    channels = mCoder.getChannels();
   
    // Log them all
    log.debug("Bitrate: {}", bitRate);
    log.debug("Height: {}", height);
    log.debug("Width: {}", width);
    log.debug("Timebase: {}", timebase);
    log.debug("Num Group of Pictures: {}", gops);
    log.debug("Pixel Format: {}", pixFmt);
    log.debug("Sample Rate: {}", sampleRate);
    log.debug("Channels: {}", channels);
   
    // now our assertions
    assertEquals(128000, bitRate, 1000);
    assertEquals(0, height);
    assertEquals(0, width);
    assertEquals(1, timebase.getNumerator());
    assertEquals(14112000, timebase.getDenominator());
    assertEquals(12, gops);
    assertEquals(IPixelFormat.Type.NONE, pixFmt);
    assertEquals(44100, sampleRate);
    assertEquals(2, channels);   
    stream.delete();
    container.close();
    container.delete();

  }
View Full Code Here

    for (int i = 0; i < numStreams; i++)
    {
      /**
       * Get the IStream for this input stream.
       */
      IStream is = mIContainer.getStream(i);
      /**
       * And get the input stream coder. Xuggler will set up all sorts of
       * defaults on this StreamCoder for you (such as the audio sample rate)
       * when you open it.
       *
       * You can create IStreamCoders yourself using
       * IStreamCoder#make(IStreamCoder.Direction), but then you have to set all
       * parameters yourself.
       */
      IStreamCoder ic = is.getStreamCoder();

      /**
       * Find out what Codec Xuggler guessed the input stream was encoded with.
       */
      ICodec.Type cType = ic.getCodecType();

      mIStreams[i] = is;
      mICoders[i] = ic;
      mOStreams[i] = null;
      mOCoders[i] = null;
      mASamplers[i] = null;
      mVSamplers[i] = null;
      mIVideoPictures[i] = null;
      mOVideoPictures[i] = null;
      mISamples[i] = null;
      mOSamples[i] = null;

      if (cType == ICodec.Type.CODEC_TYPE_AUDIO && mHasAudio
          && (astream == -1 || astream == i))
      {
        /**
         * So it looks like this stream as an audio stream. Now we add an audio
         * stream to the output container that we will use to encode our
         * resampled audio.
         */
        IStream os = mOContainer.addNewStream(i);

        /**
         * And we ask the IStream for an appropriately configured IStreamCoder
         * for output.
         *
         * Unfortunately you still need to specify a lot of things for
         * outputting (because we can't really guess what you want to encode
         * as).
         */
        IStreamCoder oc = os.getStreamCoder();
        String apreset = cmdLine.getOptionValue("apreset");
        if (apreset != null)
          Configuration.configure(apreset, oc);

        mOStreams[i] = os;
        mOCoders[i] = oc;

        /**
         * First, did the user specify an audio codec?
         */
        if (acodec != null)
        {
          ICodec codec = null;
          /**
           * Looks like they did specify one; let's look it up by name.
           */
          codec = ICodec.findEncodingCodecByName(acodec);
          if (codec == null || codec.getType() != cType)
            throw new RuntimeException("could not find encoder: " + acodec);
          /**
           * Now, tell the output stream coder that it's to use that codec.
           */
          oc.setCodec(codec);
        }
        else
        {
          /**
           * Looks like the user didn't specify an output coder for audio.
           *
           * So we ask Xuggler to guess an appropriate output coded based on the
           * URL, container format, and that it's audio.
           */
          ICodec codec = ICodec.guessEncodingCodec(oFmt, null, outputURL, null,
              cType);
          if (codec == null)
            throw new RuntimeException("could not guess " + cType
                + " encoder for: " + outputURL);
          /**
           * Now let's use that.
           */
          oc.setCodec(codec);
        }

        /**
         * In general a IStreamCoder encoding audio needs to know: 1) A ICodec
         * to use. 2) The sample rate and number of channels of the audio. Most
         * everything else can be defaulted.
         */

        /**
         * If the user didn't specify a sample rate to encode as, then just use
         * the same sample rate as the input.
         */
        if (sampleRate == 0)
          sampleRate = ic.getSampleRate();
        oc.setSampleRate(sampleRate);
        /**
         * If the user didn't specify a bit rate to encode as, then just use the
         * same bit as the input.
         */
        if (abitrate == 0)
          abitrate = ic.getBitRate();
        if (abitrate == 0)
          // some containers don't give a bit-rate
          abitrate = 64000;
        oc.setBitRate(abitrate);
       
        /**
         * If the user didn't specify the number of channels to encode audio as,
         * just assume we're keeping the same number of channels.
         */
        if (channels == 0)
          channels = ic.getChannels();
        oc.setChannels(channels);

        /**
         * And set the quality (which defaults to 0, or highest, if the user
         * doesn't tell us one).
         */
        oc.setGlobalQuality(aquality);

        /**
         * Now check if our output channels or sample rate differ from our input
         * channels or sample rate.
         *
         * If they do, we're going to need to resample the input audio to be in
         * the right format to output.
         */
        if (oc.getChannels() != ic.getChannels()
            || oc.getSampleRate() != ic.getSampleRate())
        {
          /**
           * Create an audio resampler to do that job.
           */
          mASamplers[i] = IAudioResampler.make(oc.getChannels(), ic
              .getChannels(), oc.getSampleRate(), ic.getSampleRate());
          if (mASamplers[i] == null)
          {
            throw new RuntimeException(
                "could not open audio resampler for stream: " + i);
          }
        }
        else
        {
          mASamplers[i] = null;
        }
        /**
         * Finally, create some buffers for the input and output audio
         * themselves.
         *
         * We'll use these repeated during the #run(CommandLine) method.
         */
        mISamples[i] = IAudioSamples.make(1024, ic.getChannels());
        mOSamples[i] = IAudioSamples.make(1024, oc.getChannels());
      }
      else if (cType == ICodec.Type.CODEC_TYPE_VIDEO && mHasVideo
          && (vstream == -1 || vstream == i))
      {
        /**
         * If you're reading these commends, this does the same thing as the
         * above branch, only for video. I'm going to assume you read those
         * comments and will only document something substantially different
         * here.
         */
        IStream os = mOContainer.addNewStream(i);
        IStreamCoder oc = os.getStreamCoder();
        String vpreset = cmdLine.getOptionValue("vpreset");
        if (vpreset != null)
          Configuration.configure(vpreset, oc);

        mOStreams[i] = os;
View Full Code Here

TOP

Related Classes of com.xuggle.xuggler.IStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.