Package com.xuggle.xuggler

Examples of com.xuggle.xuggler.IRational


 
  @Test
  public void testStreamGetters()
  {
    helperGetStream(0);
    IRational rational = null;
    long val=0;
   
    val = mStream.getIndex();
    log.debug("Index: {}", val);
   
    val = mStream.getId();
    log.debug("ID: {}", val);
   
    rational = mStream.getFrameRate();
    log.debug("Frame Rate: {}", rational.getDouble());
   
    rational = mStream.getTimeBase();
    log.debug("Time Base: {}", rational.getDouble());
   
    val = mStream.getStartTime();
    log.debug("Start Time: {}", val);
    val = mStream.getDuration();
    log.debug("Duration: {}", val);
View Full Code Here


  }

  public void testGetSampleAspectRatio()
  {
    helperGetStream(0);
    IRational sample = mStream.getSampleAspectRatio();
    assertNotNull(sample);
    assertEquals(0, sample.getNumerator());
    assertEquals(0, sample.getNumerator());
  }
View Full Code Here

 
  public void testSetSampleAspectRatio()
  {
    helperGetStream(0);
   
    IRational newVal = IRational.make(3,2);
    mStream.setSampleAspectRatio(newVal);
   
    IRational sample = mStream.getSampleAspectRatio();
    assertNotNull(sample);
    assertEquals(3, sample.getNumerator());
    assertEquals(2, sample.getDenominator());
  }
View Full Code Here

  public void testSetSampleAspectRatioNullIgnored()
  {
    helperGetStream(0);
   
    IRational newVal = IRational.make(3,2);
    mStream.setSampleAspectRatio(newVal);
   
    IRational sample = mStream.getSampleAspectRatio();
    assertNotNull(sample);
    assertEquals(3, sample.getNumerator());
    assertEquals(2, sample.getDenominator());

    // Now, set to null and make sure it doesn't actually work or crash the JVM
    newVal = null;
    mStream.setSampleAspectRatio(newVal);
   
    sample = mStream.getSampleAspectRatio();
    assertNotNull(sample);
    assertEquals(3, sample.getNumerator());
    assertEquals(2, sample.getDenominator());
  }
View Full Code Here

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

  public void testVideoGetters()
  {
    int bitRate = -1;
    int height = -1;
    int width = -1;
    IRational timebase = null;
    int gops = -1;
    IPixelFormat.Type pixFmt= IPixelFormat.Type.NONE;
    int sampleRate = -1;
    int channels = -1;
   
    // get the video stream
    mCoder = getStreamCoder(sampleFile, 0);
    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.getNumerator(),
        timebase.getDenominator());
    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(0, bitRate);
    assertEquals(176, height);
    assertEquals(424, width);
    assertEquals(1, timebase.getNumerator());
    assertEquals(1000, timebase.getDenominator());
    assertEquals(12, gops);
    assertEquals(IPixelFormat.Type.YUV420P, pixFmt);
    assertEquals(0, sampleRate);
    assertEquals(0, channels);   
  }
View Full Code Here

  public void testAudioGetters()
  {
    int bitRate = -1;
    int height = -1;
    int width = -1;
    IRational timebase = null;
    int gops = -1;
    IPixelFormat.Type pixFmt= IPixelFormat.Type.NONE;
    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();
View Full Code Here

         *
         * But take my word that time stamps are tricky, and this only touches
         * the envelope. The good news is, it's easier in Xuggler than some
         * other systems.
         */
        IRational num = null;
        num = ic.getFrameRate();
        oc.setFrameRate(num);
        oc.setTimeBase(IRational.make(num.getDenominator(), num
                .getNumerator()));
        num = null;

        /**
         * And allocate buffers for us to store decoded and resample video
View Full Code Here

      IStream stream = mIContainer.getStream(i);
      long tsOffset = 0;
      if (stream.getStartTime() != Global.NO_PTS && stream.getStartTime() > 0
          && stream.getTimeBase() != null)
      {
        IRational defTimeBase = IRational.make(1,
            (int) Global.DEFAULT_PTS_PER_SECOND);
        tsOffset = defTimeBase.rescale(stream.getStartTime(), stream
            .getTimeBase());
      }
      /**
       * And look up the appropriate objects that are working on that stream.
       */
 
View Full Code Here

   * @param oPacket the packet about to be written.
   */
  private void delayForRealTime(IPacket oPacket)
  {
    // convert packet timestamp to microseconds
    final IRational timeBase = oPacket.getTimeBase();
    if (timeBase == null || timeBase.getNumerator() == 0 ||
        timeBase.getDenominator() == 0)
      return;
    long dts = oPacket.getDts();
    if (dts == Global.NO_PTS)
      return;
   
    final long currStreamTime = IRational.rescale(dts,
        1,
        1000000,
        timeBase.getNumerator(),
        timeBase.getDenominator(),
        IRational.Rounding.ROUND_NEAR_INF);
    if (mStartStreamTime == null)
      mStartStreamTime = currStreamTime;

    // convert now to microseconds
View Full Code Here

TOP

Related Classes of com.xuggle.xuggler.IRational

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.