Package com.xuggle.xuggler

Examples of com.xuggle.xuggler.IPacket


    }

    public void run() {
        int errorNumber;
        container.open(videoInput, containerFormat, true, false);
        IPacket packet = IPacket.make();
        while (container.readNextPacket(packet) >= 0) {
            if (Thread.interrupted())
                return;

            statistic.dataRead(packet.getSize());

            if (coder == null) {
                int streamIndex = packet.getStreamIndex();
                IStreamCoder newCoder = container.getStream(streamIndex)
                    .getStreamCoder();
                if (newCoder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
                    videoStreamIndex = streamIndex;
                    coder = newCoder;
                    if ((errorNumber = coder.open()) < 0) {
                        videoSharingSession.reportError(new DecodingException(
                            IError.make(errorNumber).getDescription()));
                        return;
                    }
                }
                if (coder == null)
                    // coder not properly set up yet
                    continue;
            }

            if (packet.getStreamIndex() == videoStreamIndex) {
                // one of the pictures in this packet
                IVideoPicture picture = IVideoPicture.make(
                    coder.getPixelType(), coder.getWidth(), coder.getHeight());

                // offset for already processed data in package
                int offset = 0;
                // fetch every frame from the packet
                while (offset < packet.getSize()) {
                    int bytesDecoded = coder.decodeVideo(picture, packet,
                        offset);

                    if (bytesDecoded < 0) {
                        videoSharingSession.reportError(new DecodingException(
View Full Code Here


    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

                        throw new RuntimeException("could not find audio stream in container");
                }
                 
                audioCoder.setSampleFormat(IAudioSamples.Format.FMT_S16);
                audioCoder.open();
                IPacket packet = IPacket.make();
                
                long timer = 0;
                boolean stoper = false;
                
                while(stoper == false)
                {
                        container.readNextPacket(packet);
                    if (packet.getStreamIndex() == audioStreamId)
                    {
                        IAudioSamples samples = IAudioSamples.make(512, audioCoder.getChannels(),IAudioSamples.Format.FMT_S16 );
                        int offset = 0;
                        while(offset < packet.getSize())
                        {
                                int bytesDecoded = audioCoder.decodeAudio(samples, packet, offset);
                            if (bytesDecoded < 0)
                            {
                                  throw new RuntimeException("got error decoding audio in");
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

          "could not create color space resampler for: " + filename);
    }

    // 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 strea

      if (packet.getStreamIndex() == videoStreamId)
      {
        // We allocate a new picture to get the data out of Xuggle

        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.

          int bytesDecoded = videoCoder.decodeVideo(picture, packet, offset);
          if (bytesDecoded < 0)
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

   
   
    /*
     * Now, we start walking through the container looking at each packet.
     */
    IPacket packet = IPacket.make();
    mFirstVideoTimestampInStream = Global.NO_PTS;
    mSystemVideoClockStartTime = 0;
    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());
       
        /*
         * Now, we decode the video, checking for any errors.
         *
         */
        int bytesDecoded = videoCoder.decodeVideo(picture, packet, 0);
        if (bytesDecoded < 0)
          throw new RuntimeException("got error decoding audio in: " + filename);

        /*
         * Some decoders will consume data in a packet, but will not be able to construct
         * a full video picture yet.  Therefore you should always check if you
         * got a complete picture from the decoder
         */
        if (picture.isComplete())
        {
          IVideoPicture newPic = picture;
          /*
           * If the resampler is not null, that means we didn't get the video in BGR24 format and
           * need to convert it into BGR24 format.
           */
          if (resampler != null)
          {
            // we must resample
            newPic = IVideoPicture.make(resampler.getOutputPixelFormat(), picture.getWidth(), picture.getHeight());
            if (resampler.resample(newPic, picture) < 0)
              throw new RuntimeException("could not resample video from: " + filename);
          }
          if (newPic.getPixelType() != IPixelFormat.Type.BGR24)
            throw new RuntimeException("could not decode video as BGR 24 bit data in: " + filename);

          long delay = millisecondsUntilTimeToDisplay(newPic);
          // if there is no audio stream; go ahead and hold up the main thread.  We'll end
          // up caching fewer video pictures in memory that way.
          try
          {
            if (delay > 0)
              Thread.sleep(delay);
          }
          catch (InterruptedException e)
          {
            return;
          }

          // And finally, convert the picture to an image and display it

          mScreen.setImage(Utils.videoPictureToImage(newPic));
        }
      }
      else 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

    }
    // 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

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.