Package com.xuggle.xuggler

Examples of com.xuggle.xuggler.IPacket


    openJavaSound(audioCoder);
   
    /*
     * Now, we start walking through the container looking at each packet.
     */
    IPacket packet = IPacket.make();
    while(container.readNextPacket(packet) >= 0)
    {
      /*
       * Now we have a packet, let's see if it belongs to our audio stream
       */
      if (packet.getStreamIndex() == audioStreamId)
      {
        /*
         * We allocate a set of samples with the same number of channels as the
         * coder tells us is in this buffer.
         *
         * We also pass in a buffer size (1024 in our example), although Xuggler
         * will probably allocate more space than just the 1024 (it's not important why).
         */
        IAudioSamples samples = IAudioSamples.make(1024, audioCoder.getChannels());
       
        /*
         * A packet can actually contain multiple sets of samples (or frames of samples
         * in audio-decoding speak).  So, we may need to call decode audio multiple
         * times at different offsets in the packet's data.  We capture that here.
         */
        int offset = 0;
       
        /*
         * Keep going until we've processed all data
         */
        while(offset < packet.getSize())
        {
          int bytesDecoded = audioCoder.decodeAudio(samples, packet, offset);
          if (bytesDecoded < 0)
            throw new RuntimeException("got error decoding audio in: " + filename);
          offset += bytesDecoded;
View Full Code Here


      open();

    // if there is an off-nominal result from read packet, return the
    // correct error

    IPacket packet = IPacket.make();
    try
    {
      int rv = getContainer().readNextPacket(packet);
      if (rv < 0)
      {
        IError error = IError.make(rv);

        // if this is an end of file, or unknow, call close

        if (!mCloseOnEofOnly || IError.Type.ERROR_EOF == error.getType())
          close();

        return error;
      }

      // inform listeners that a packet was read

      super.onReadPacket(new ReadPacketEvent(this,packet));

      // get the coder for this packet

      IStreamCoder coder = getStreamCoder(packet.getStreamIndex());
      // decode based on type

      switch (coder.getCodecType())
      {
        // decode audio

        case CODEC_TYPE_AUDIO:
          decodeAudio(coder, packet);
          break;

          // decode video

        case CODEC_TYPE_VIDEO:
          decodeVideo(coder, packet);
          break;

          // all other stream types are currently ignored

        default:
      }

     
    }
    finally
    {
      if (packet != null)
        packet.delete();
    }

    // return true more packets to be read

    return null;
View Full Code Here

    openJavaWindow();

    /*
     * Now, we start walking through the container looking at each packet.
     */
    IPacket packet = IPacket.make();
    while(container.readNextPacket(packet) >= 0)
    {
      /*
       * Now we have a packet, let's see if it belongs to our video stream
       */
      if (packet.getStreamIndex() == videoStreamId)
      {
        /*
         * We allocate a new picture to get the data out of Xuggler
         */
        IVideoPicture picture = IVideoPicture.make(videoCoder.getPixelType(),
            videoCoder.getWidth(), videoCoder.getHeight());

        int offset = 0;
        while(offset < packet.getSize())
        {
          /*
           * Now, we decode the video, checking for any errors.
           *
           */
 
View Full Code Here

    }
    // encode video picture

    // encode the video packet
   
    IPacket packet = IPacket.make();
    try {
      if (stream.getStreamCoder().encodeVideo(packet, picture, 0) < 0)
        throw new RuntimeException("failed to encode video");
 
      if (packet.isComplete())
        writePacket(packet);
    } finally {
      if (packet != null)
        packet.delete();
    }
 
    // inform listeners

    super.onVideoPicture(new VideoPictureEvent(this, picture, image,
View Full Code Here

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

      // if it's audio coder flush that

      if (CODEC_TYPE_AUDIO == coder.getCodecType())
      {
        IPacket packet = IPacket.make();
        while (coder.encodeAudio(packet, null, 0) >= 0 && packet.isComplete())
        {
          writePacket(packet);
          packet.delete();
          packet = IPacket.make();
        }
        packet.delete();
      }
     
      // else flush video coder

      else if (CODEC_TYPE_VIDEO == coder.getCodecType())
      {
        IPacket packet = IPacket.make();
        while (coder.encodeVideo(packet, null, 0) >= 0 && packet.isComplete())
        {
          writePacket(packet);
          packet.delete();
          packet = IPacket.make();
        }
        packet.delete();
      }
    }

    // flush the container
View Full Code Here

  public void encodeImage(BufferedImage originalImage)
  {
    BufferedImage worksWithXugglerBufferedImage = convertToType(originalImage,
        BufferedImage.TYPE_3BYTE_BGR);
    IPacket packet = IPacket.make();

    long now = System.currentTimeMillis();
    if (firstTimeStamp == -1)
      firstTimeStamp = now;
   
    IConverter converter = null;
    try
    {
      converter = ConverterFactory.createConverter(
          worksWithXugglerBufferedImage, IPixelFormat.Type.YUV420P);
    }
    catch (UnsupportedOperationException e)
    {
      System.out.println(e.getMessage());
      e.printStackTrace(System.out);
    }

    long timeStamp = (now - firstTimeStamp)*1000; // convert to microseconds
    IVideoPicture outFrame = converter.toPicture(worksWithXugglerBufferedImage,
        timeStamp);

    outFrame.setQuality(0);
    int retval = outStreamCoder.encodeVideo(packet, outFrame, 0);
    if (retval < 0)
      throw new RuntimeException("could not encode video");
    if (packet.isComplete())
    {
      retval = outContainer.writePacket(packet);
      if (retval < 0)
        throw new RuntimeException("could not save packet to container");
    }
View Full Code Here

     */
    for (i = 0; i < numStreams; i++)
    {
      if (mOCoders[i] != null)
      {
        IPacket oPacket = IPacket.make();
        do {
          if (mOCoders[i].getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO)
            mOCoders[i].encodeAudio(oPacket, null, 0);
          else
            mOCoders[i].encodeVideo(oPacket, null, 0);
          if (oPacket.isComplete())
            mOContainer.writePacket(oPacket, mForceInterleave);
        } while (oPacket.isComplete());
      }
    }
    /**
     * Some container formats require a trailer to be written to avoid a corrupt
     * files.
 
View Full Code Here

    /**
     * Create packet buffers for reading data from and writing data to the
     * conatiners.
     */
    IPacket iPacket = IPacket.make();
    IPacket oPacket = IPacket.make();

    /**
     * Keep some "pointers' we'll use for the audio we're working with.
     */
    IAudioSamples inSamples = null;
View Full Code Here

    protected synchronized void encodeImage(BufferedImage image) {
        if (!isEncoding)
            return;

        int errorNumber;
        IPacket packet = IPacket.make();

        long now = System.currentTimeMillis();
        if (firstTimestamp == -1)
            firstTimestamp = now;

        if (converter == null || lastRenderedPictureSize == null
            || image.getWidth() != lastRenderedPictureSize.width
            || image.getHeight() != lastRenderedPictureSize.height) {
            lastRenderedPictureSize = new Dimension(image.getWidth(), image
                .getHeight());
            // close old converter if necessary
            if (converter != null)
                converter.delete();
            try {
                // converter =
                // ConverterFactory.createConverter("XUGGLER-BGR-24",
                // PIXELFORMAT, width, height, bgrImage.getWidth(), bgrImage
                // .getHeight());
                converter = ConverterFactory.createConverter("XUGGLER-BGR-24",
                    pixelformat, width, height, width, height);
            } catch (UnsupportedOperationException e) {
                videoSharingSession.reportError(new EncodingException(e));
                return;
            }
        }

        image = Decoder.resample(image, new Dimension(width, height));

        long timeStamp = (now - firstTimestamp) * 1000; // convert to
        // microseconds
        com.xuggle.xuggler.IVideoPicture outFrame = converter.toPicture(
            convertToType(image, BufferedImage.TYPE_3BYTE_BGR), timeStamp);

        if ((errorNumber = coder.encodeVideo(packet, outFrame, 0)) < 0) {
            videoSharingSession.reportError(new EncodingException(IError.make(
                errorNumber).getDescription()));
            return;
        }

        if (packet.isComplete()) {
            if ((errorNumber = container.writePacket(packet)) < 0) {
                videoSharingSession.reportError(new EncodingException(IError
                    .make(errorNumber).getDescription()));
                return;
            }
View Full Code Here

TOP

Related Classes of com.xuggle.xuggler.IPacket

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.