Package com.xuggle.xuggler

Examples of com.xuggle.xuggler.IStreamCoder


 
  public void testGetStreamCoder()
  {
    helperGetStream(0);
   
    IStreamCoder coder = null;
    coder = mStream.getStreamCoder();
    assertTrue(coder != null);
  }
View Full Code Here


    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());
View Full Code Here

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

    IStreamCoder coder = stream.getStreamCoder();
    try
    {
      List<IRational> supportedFrameRates = codec.getSupportedVideoFrameRates();
      IRational timeBase = null;
      if (supportedFrameRates != null && supportedFrameRates.size() > 0)
      {
        IRational highestResolution = null;
        // If we have a list of supported frame rates, then
        // we must pick at least one of them.  and if the
        // user passed in a frameRate, it must match
        // this list.
        for(IRational supportedRate: supportedFrameRates)
        {
          if (!IRational.positive(supportedRate))
            continue;
          if (highestResolution == null)
            highestResolution = supportedRate.copyReference();

          if (IRational.positive(frameRate))
          {
            if (supportedRate.compareTo(frameRate) == 0)
              // use this
              highestResolution = frameRate.copyReference();
          }
          else if (highestResolution.getDouble() < supportedRate.getDouble())
          {
            highestResolution.delete();
            highestResolution = supportedRate.copyReference();
          }
          supportedRate.delete();
        }
        // if we had a frame rate suggested, but we
        // didn't find a match among the supported elements,
        // throw an error.
        if (IRational.positive(frameRate) &&
            (highestResolution == null ||
                highestResolution.compareTo(frameRate) != 0))
          throw new UnsupportedOperationException("container does not"+
              " support encoding at given frame rate: " + frameRate);
       
        // if we got through the supported list and found NO valid
        // resolution, fail.
        if (highestResolution == null)
          throw new UnsupportedOperationException(
              "could not find supported frame rate for container: " +
              getUrl());
        if (timeBase == null)
          timeBase = IRational.make(highestResolution.getDenominator(),
              highestResolution.getNumerator());
        highestResolution.delete();
        highestResolution = null;
      }
      // if a positive frame rate was passed in, we
      // should either use the inverse of it, or if
      // there is a supported frame rate, but not
      // this, then throw an error.
      if (IRational.positive(frameRate) && timeBase == null)
      {
        timeBase = IRational.make(
            frameRate.getDenominator(),
            frameRate.getNumerator());
      }
     
      if (timeBase == null)
      {
        timeBase = getDefaultTimebase();
       
        // Finally MPEG4 has some code failing if the time base
        // is too aggressive...
        if (codec.getID() == ICodec.ID.CODEC_ID_MPEG4 &&
            timeBase.getDenominator() > ((1<<16)-1))
        {
          // this codec can't support that high of a frame rate
          timeBase.delete();
          timeBase = IRational.make(1,(1<<16)-1);
        }
      }
      coder.setTimeBase(timeBase);
      timeBase.delete();
      timeBase= null;

      coder.setWidth(width);
      coder.setHeight(height);
      coder.setPixelType(DEFAULT_PIXEL_TYPE);

      // add the stream to the media writer

      addStream(stream, inputIndex, stream.getIndex());
    }
    finally
    {
      coder.delete();
    }

    // return the new video stream

    return stream.getIndex();
View Full Code Here

      throw new RuntimeException("Unable to create stream id " + streamId +
        ", index " + inputIndex + ", codec " + codec);
   
    // configure the stream coder

    IStreamCoder coder = stream.getStreamCoder();
    coder.setCodec(codec);
    coder.delete();
    coder = null;

    // if the stream count is 1, don't force interleave

    setForceInterleave(getContainer().getNumStreams() != 1);
View Full Code Here

    IStream stream = getStream(streamIndex);
    if (null == stream)
      return;

    IStreamCoder coder = stream.getStreamCoder();
    try
    {
      if (CODEC_TYPE_AUDIO != coder.getCodecType())
      {
        throw new IllegalArgumentException("stream[" + streamIndex +
        "] is not audio");
      }

      // encode the audio

      // convert the samples into a packet

      for (int consumed = 0; consumed < samples.getNumSamples(); /* in loop */)
      {
        // encode audio

        IPacket packet = IPacket.make();
        try {
          int result = coder.encodeAudio(packet, samples, consumed);
          if (result < 0)
            throw new RuntimeException("failed to encode audio");

          // update total consumed

          consumed += result;

          // if a complete packed was produced write it out

          if (packet.isComplete())
            writePacket(packet);
        } finally {
          if (packet != null)
            packet.delete();
        }
      }      // inform listeners

      super.onAudioSamples(new AudioSamplesEvent(this, samples,
          streamIndex));
    }
    finally
    {
      if (coder != null) coder.delete();
    }
  }
View Full Code Here

    IStream stream = getStream(streamIndex);
    if (null == stream)
      return;

    IStreamCoder coder = stream.getStreamCoder();
    try
    {
      if (IAudioSamples.Format.FMT_S16 != coder.getSampleFormat())
      {
        throw new IllegalArgumentException("stream[" + streamIndex
            + "] is not 16 bit audio");
      }

      // establish the number of samples

      long sampleCount = samples.length / coder.getChannels();

      // create the audio samples object and extract the internal buffer
      // as an array

      IAudioSamples audioFrame = IAudioSamples.make(sampleCount, coder
          .getChannels());

      /**
       * We allow people to pass in a null timeUnit for audio as
       * a signal that time stamps are unknown.  This is a common
       * case for audio data, and Xuggler should handle it if
       * we set a invalid time stamp on the audio.
       */
      final long timeStampMicro;
      if (timeUnit == null)
        timeStampMicro = Global.NO_PTS;
      else
        timeStampMicro = MICROSECONDS.convert(timeStamp, timeUnit);

      audioFrame.setComplete(true, sampleCount, coder.getSampleRate(), coder
          .getChannels(), coder.getSampleFormat(), timeStampMicro);

      audioFrame.put(samples, 0, 0, samples.length);
      encodeAudio(streamIndex, audioFrame);
    }
    finally
    {
      if (coder != null)
        coder.delete();
    }
  }
View Full Code Here

    // if not found create one

    if (videoConverter == null)
    {
      IStream stream = mStreams.get(streamIndex);
      IStreamCoder coder = stream.getStreamCoder();
      videoConverter = ConverterFactory.createConverter(
        ConverterFactory.findDescriptor(image),
        coder.getPixelType(),
        coder.getWidth(), coder.getHeight(),
        image.getWidth(), image.getHeight());
      mVideoConverters.put(streamIndex, videoConverter);
    }

    // return the converter
View Full Code Here

    IStream stream = mStreams.get(getOutputStreamIndex(inputStreamIndex));
    if (null == stream)
      throw new RuntimeException("invalid input stream index (no stream): "
         + inputStreamIndex);
    IStreamCoder coder = stream.getStreamCoder();
    if (null == coder)
      throw new RuntimeException("invalid input stream index (no coder): "
        + inputStreamIndex);
   
    // return the coder
View Full Code Here

  private boolean addStreamFromContainer(int inputStreamIndex)
  {
    // get the input stream

    IStream inputStream = mInputContainer.getStream(inputStreamIndex);
    IStreamCoder inputCoder = inputStream.getStreamCoder();
    ICodec.Type inputType = inputCoder.getCodecType();
    ICodec.ID inputID = inputCoder.getCodecID();
   
    // if this stream is not a supported type, indicate failure

    if (!isSupportedCodecType(inputType))
      return false;

    IContainerFormat format = getContainer().getContainerFormat();
   
    switch(inputType)
    {
      case CODEC_TYPE_AUDIO:
        addAudioStream(inputStream.getIndex(),
            inputStream.getId(),
            format.establishOutputCodecId(inputID),
            inputCoder.getChannels(),
            inputCoder.getSampleRate());
        break;
      case CODEC_TYPE_VIDEO:
        addVideoStream(inputStream.getIndex(),
            inputStream.getId(),
            format.establishOutputCodecId(inputID),
            inputCoder.getFrameRate(),
            inputCoder.getWidth(),
            inputCoder.getHeight());
        break;
      default:
        break;
    }
    return true;
View Full Code Here

    mStreams.put(outputStreamIndex, stream);

    // if this is a video coder, set the quality

    IStreamCoder coder = stream.getStreamCoder();
    if (CODEC_TYPE_VIDEO == coder.getCodecType())
      coder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
   
    // inform listeners

    super.onAddStream(new AddStreamEvent(this, outputStreamIndex));
  }
View Full Code Here

TOP

Related Classes of com.xuggle.xuggler.IStreamCoder

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.