Examples of IAudioSamples


Examples of com.xuggle.xuggler.IAudioSamples

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

Examples of com.xuggle.xuggler.IAudioSamples

    {
      // allocate a set of samples with the correct number of channels
      // and a stock size of 1024 (currently the buffer size will be
      // expanded to 32k to conform to ffmpeg requirements)
         
      IAudioSamples samples = IAudioSamples.make(1024, audioCoder.getChannels());

      // decode audio

      int bytesDecoded = audioCoder.decodeAudio(samples, packet, offset);
      if (bytesDecoded < 0)
        throw new RuntimeException("error " + bytesDecoded + " decoding audio");
      offset += bytesDecoded;

      // if samples are a compelete audio frame, dispatch that frame
      try {
        if (samples.isComplete())
          dispatchAudioSamples(packet.getStreamIndex(), samples);
      } finally {
        if (samples != null)
          samples.delete();
      }
    }
  }
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

            codec, channelCount, sampleRate));
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);

    // create the tone generator

    TestAudioSamplesGenerator generator = new TestAudioSamplesGenerator();
    generator.prepare(channelCount, sampleRate);

    // let's make some noise!

    int totalSamples = 0;
    while (totalSamples < sampleRate * totalSeconds)
    {
      generator.fillNextSamples(samples, sampleCount);
      writer.encodeAudio(audioStreamIndex, samples);
      totalSamples += samples.getNumSamples();
    }

    // close the writer

    writer.close();
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

    IStream stream = container.getStream(streamIndex);
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);

    // create the tone generator

    TestAudioSamplesGenerator generator = new TestAudioSamplesGenerator();
    generator.prepare(channelCount, sampleRate);

    // let's make some noise!

    int totalSamples = 0;
    short[] javaSamples = new short[sampleCount*channelCount];
    while (totalSamples < sampleRate * totalSeconds)
    {
      generator.fillNextSamples(samples, sampleCount);
      samples.get(0, javaSamples, 0, javaSamples.length);
      writer.encodeAudio(streamIndex, javaSamples);
      totalSamples += samples.getNumSamples();
    }

    // close the writer

    writer.close();
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

      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);

    // create the tone generator

    TestAudioSamplesGenerator generator = new TestAudioSamplesGenerator();
    generator.prepare(channelCount, sampleRate);

    // make some media

    long videoTime = 0;
    long audioTime = 0;
    long totalSamples = 0;
    long totalSeconds = 6;

    // the goal is to get 6 seconds of audio and video, in this case
    // driven by audio, but kicking out a video frame at about the right
    // time

    while (totalSamples < sampleRate * totalSeconds)
    {
      // comput the time based on the number of samples

      audioTime = (totalSamples * 1000 * 1000) / sampleRate;

      // if the audioTime i>= videoTime then it's time for a video frame

      if (audioTime >= videoTime)
      {
        BufferedImage image = new BufferedImage(w, h,
          BufferedImage.TYPE_3BYTE_BGR);
     
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(
          RenderingHints.KEY_ANTIALIASING,
          RenderingHints.VALUE_ANTIALIAS_ON);

        double theta = videoTime / 1000000d;
        g.setColor(Color.RED);
        g.rotate(theta, w / 2, h / 2);
       
        g.fillRect(50, 50, 100, 100);
       
        picture.setPts(videoTime);
        writer.encodeVideo(videoStreamIndex, image, videoTime,
            Global.DEFAULT_TIME_UNIT);
     
        videoTime += deltaTime;
      }

      // generate audio
     
      generator.fillNextSamples(samples, sampleCount);
      writer.encodeAudio(audioStreamIndex, samples);
      totalSamples += samples.getNumSamples();
    }

    // close the writer

    writer.close();
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

            codec, channelCount, sampleRate));
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);

    // create the tone generator

    TestAudioSamplesGenerator generator = new TestAudioSamplesGenerator();
    generator.prepare(channelCount, sampleRate);
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

            codec, channelCount, sampleRate));
    int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

    // create a place for audio samples

    IAudioSamples samples = IAudioSamples.make(sampleCount, channelCount);

    // create the tone generator

    TestAudioSamplesGenerator generator = new TestAudioSamplesGenerator();
    generator.prepare(channelCount, sampleRate);
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

        break;
      }
    }
    assertTrue("Could not find audio stream", audioStream >= 0);
   
    IAudioSamples samples = IAudioSamples.make(buffer,
        h.mCoders[audioStream].getChannels(),
        h.mCoders[audioStream].getSampleFormat());
    assertNotNull(samples);
    while (h.mContainer.readNextPacket(h.mPacket) == 0)
    {
      if (h.mPacket.getStreamIndex() == audioStream)
      {
        int offset = 0;
        while (offset < h.mPacket.getSize())
        {
          retval = h.mCoders[audioStream].decodeAudio(
              samples,
              h.mPacket,
              offset);
          assertTrue("could not decode any audio", retval >0);
          offset += retval;
          assertTrue("did not write any samples",
              samples.getNumSamples() > 0);
          log.debug("Decoded {} samples",
              samples.getNumSamples());
          totalSamples += samples.getNumSamples();
        }
      } else {
        log.debug("skipping video packet");
      }
    }
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

  public void testGetNextPts()
  {
    int sampleRate = 440;
    int channels=1;
   
    IAudioSamples samples = IAudioSamples.make(sampleRate, 1);
    assertNotNull(samples);

    samples.setComplete(true, sampleRate, sampleRate, channels, IAudioSamples.Format.FMT_S16, 0);
    assertTrue(samples.isComplete());
    assertEquals(0, samples.getPts());
    assertEquals(Global.DEFAULT_PTS_PER_SECOND, samples.getNextPts());
  }
View Full Code Here

Examples of com.xuggle.xuggler.IAudioSamples

  public void testSetPts()
  {
    int sampleRate = 440;
    int channels=1;
   
    IAudioSamples samples = IAudioSamples.make(sampleRate, 1);
    assertNotNull(samples);

    samples.setComplete(true, sampleRate, sampleRate, channels, IAudioSamples.Format.FMT_S16, 0);
    assertTrue(samples.isComplete());
    assertEquals(0, samples.getPts());
    assertEquals(Global.DEFAULT_PTS_PER_SECOND, samples.getNextPts());
   
    samples.setPts(Global.DEFAULT_PTS_PER_SECOND);
    assertEquals(Global.DEFAULT_PTS_PER_SECOND, samples.getPts());
    assertEquals(2*Global.DEFAULT_PTS_PER_SECOND, samples.getNextPts());
   
   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.