Package com.xuggle.xuggler

Examples of com.xuggle.xuggler.IContainer


    assertEquals("test value", 0xEF, tag[0]);
  }
 
  public void testSetCodecTagArray()
  {
    IContainer container = IContainer.make();
    assertTrue("should be able to open",
        container.open("fixtures/subtitled_video.mkv", IContainer.Type.READ, null) >= 0);
    IStreamCoder coder = container.getStream(0).getStreamCoder();
  
    char[] tag = new char[4];
    tag[3] = 0xDE;
    tag[2] = 0xAD;
    tag[1] = 0xBE;
View Full Code Here


  public DisplayWebcamVideo(String driverName, String deviceName)
  {
    // create a Xuggler container object

    IContainer container = IContainer.make();

    // devices, unlike most files, need to have parameters set in order
    // for Xuggler to know how to configure them, for a webcam, these
    // parameters make sense

    IContainerParameters params = IContainerParameters.make();
   
    // the timebase is used as the camera frame rate

    params.setTimeBase(IRational.make(30,1));
   
    // tell the driver what video with and height to use

    params.setVideoWidth(320);
    params.setVideoHeight(240);
   
    // set these parameters on the container before
    // opening

    container.setParameters(params);
   
    // tell Xuggler about the device format

    IContainerFormat format = IContainerFormat.make();
    if (format.setInputFormat(driverName) < 0)
      throw new IllegalArgumentException(
        "couldn't open webcam device: " + driverName);
   
    // open the container

    int retval = container.open(deviceName, IContainer.Type.READ, format);
    if (retval < 0)
    {
      // this little trick converts the non friendly integer return
      // value into a slightly more friendly object to get a
      // human-readable error name
View Full Code Here

    if (getMode() == Mode.DISABLED)
      return;

    // get the coder, and stream index

    IContainer container = event.getSource().getContainer();
    IStream stream = container.getStream(event.getStreamIndex());
    IStreamCoder coder = stream.getStreamCoder();
    int streamIndex = event.getStreamIndex();

    // if video stream and showing video, configure video stream
View Full Code Here

      throw new IllegalArgumentException("must pass in a filename as the first argument");
   
    String filename = args[0];
   
    // Create a Xuggler container object
    IContainer container = IContainer.make();
   
    // Open up the container
    if (container.open(filename, IContainer.Type.READ, null) < 0)
      throw new IllegalArgumentException("could not open file: " + filename);
   
    // query how many streams the call to open found
    int numStreams = container.getNumStreams();
   
    // and iterate through the streams to find the first audio stream
    int audioStreamId = -1;
    IStreamCoder audioCoder = null;
    for(int i = 0; i < numStreams; i++)
    {
      // Find the stream object
      IStream stream = container.getStream(i);
      // Get the pre-configured decoder that can decode this stream;
      IStreamCoder coder = stream.getStreamCoder();
     
      if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO)
      {
        audioStreamId = i;
        audioCoder = coder;
        break;
      }
    }
    if (audioStreamId == -1)
      throw new RuntimeException("could not find audio stream in container: "+filename);
   
    /*
     * Now we have found the audio stream in this file.  Let's open up our decoder so it can
     * do work.
     */
    if (audioCoder.open() < 0)
      throw new RuntimeException("could not open audio decoder for container: "+filename);
   
    /*
     * And once we have that, we ask the Java Sound System to get itself ready.
     */
    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;
          /*
           * Some decoder will consume data in a packet, but will not be able to construct
           * a full set of samples yet.  Therefore you should always check if you
           * got a complete set of samples from the decoder
           */
          if (samples.isComplete())
          {
            playJavaSound(samples);
          }
        }
      }
      else
      {
        /*
         * This packet isn't part of our audio stream, so we just silently drop it.
         */
        do {} while(false);
      }
     
    }
    /*
     * Technically since we're exiting anyway, these will be cleaned up by
     * the garbage collector... but because we're nice people and want
     * to be invited places for Christmas, we're going to show how to clean up.
     */
    closeJavaSound();
   
    if (audioCoder != null)
    {
      audioCoder.close();
      audioCoder = null;
    }
    if (container !=null)
    {
      container.close();
      container = null;
    }
  }
View Full Code Here

  {
    // maximize FFmpeg logging
    log.debug("About to change logging level");
    Global.setFFmpegLoggingLevel(50);
    // Try getting a new Container
    IContainer container = null;
    IContainerFormat fmt = null;   
    int retval = -1;

    container = IContainer.make();
    fmt = IContainerFormat.make();
   
    // try opening a container format
   
    retval = fmt.setInputFormat("flv");
    assertTrue("could not set input format", retval >= 0);
   
    retval = fmt.setOutputFormat("flv", null, null);
    assertTrue("could not set output format", retval >= 0);
   
    // force collection of native resources.
    container.delete();
    container = null;
   
    // get a new container; which will deref the old one.
    container = IContainer.make();
   
    // now, try opening a container.
    retval = container.open("file:"+this.getClass().getName()+"_"+this.getName()+".flv",
        IContainer.Type.WRITE, fmt);
    assertTrue("could not open file for writing", retval >= 0);

    retval = container.close();
    assertTrue("could not close file", retval >= 0);
   
    retval = container.open("file:"+this.getClass().getName()+"_"+this.getName()+".flv",
        IContainer.Type.WRITE, null);
    assertTrue("could not open file for writing", retval >= 0);

    retval = container.close();
    assertTrue("could not close file", retval >= 0);
   
    retval = container.open("file:"+mSampleFile,
        IContainer.Type.READ, fmt);
    assertTrue("could not open file for writing", retval >= 0);

    retval = container.close();
    assertTrue("could not close file", retval >= 0);
   
    retval = container.open("file:"+mSampleFile,
        IContainer.Type.READ, null);
    assertTrue("could not open file for writing", retval >= 0);

    retval = container.close();
    assertTrue("could not close file", retval >= 0);
   
  }
View Full Code Here

  }
 
  @Test
  public void testCorrectNumberOfStreams()
  {
    IContainer container = IContainer.make();
    int retval = -1;
   
    retval = container.open(mSampleFile, IContainer.Type.READ, null);
    assertTrue("could not open file", retval >= 0);
   
    int numStreams = container.getNumStreams();
    assertTrue("incorrect number of streams: " + numStreams, numStreams == 2);
   
    retval = container.close();
    assertTrue("could not close the file", retval >= 0);
  }
View Full Code Here

  }
 
  @Test
  public void testWriteHeaderAndTrailer()
  {
    IContainer container = IContainer.make();
    int retval = -1;
   
    retval = container.open(this.getClass().getName()+"_"+this.getName()+".flv",
        IContainer.Type.WRITE, null);
    assertTrue("could not open file", retval >= 0);
   
    IStream stream = container.addNewStream(0);
    IStreamCoder coder = stream.getStreamCoder();
    coder.setCodec(ICodec.ID.CODEC_ID_MP3);
    coder.setSampleRate(22050);
    coder.setChannels(1);
    retval = coder.open();
    assertTrue("could not open coder", retval >= 0);
   
    retval = container.writeHeader();
    assertTrue("could not write header", retval >= 0);
   
    retval = container.writeTrailer();
    assertTrue("could not write header", retval >= 0);
  
    retval = coder.close();
    assertTrue("could not close coder", retval >= 0);
   
    retval = container.close();
    assertTrue("could not close the file", retval >= 0);
   
  }
View Full Code Here

  }

  @Test
  public void testWriteTrailerWithNoWriteHeaderDoesNotCrashJVM()
  {
    IContainer container = IContainer.make();
    int retval = -1;
   
    retval = container.open(this.getClass().getName()+"_"+this.getName()+".flv",
        IContainer.Type.WRITE, null);
    assertTrue("could not open file", retval >= 0);

    // Should give a warning and fail, but should NOT crash the JVM like it used to.
    retval = container.writeTrailer();
    assertTrue("could not write header", retval < 0);
   
    retval = container.close();
    assertTrue("could not close the file", retval >= 0);
   
  }
View Full Code Here

  }
 
  @Test
  public void testOpenFileSetsInputContainer()
  {
    IContainer container = null;
    IContainerFormat fmt = null;   
    int retval = -1;

    container = IContainer.make();
   
    // now, try opening a container.
    retval = container.open("file:"+this.getClass().getName()+"_"+this.getName()+".flv",
        IContainer.Type.WRITE, null);
    assertTrue("could not open file for writing", retval >= 0);
   
    fmt = container.getContainerFormat();
    assertNotNull(fmt);
    assertEquals("flv", fmt.getOutputFormatShortName());

    retval = container.close();
    assertTrue("could not close file", retval >= 0);
   
    retval = container.open("file:"+mSampleFile,
        IContainer.Type.READ, fmt);
    assertTrue("could not open file for writing", retval >= 0);

    fmt = container.getContainerFormat();
    assertNotNull(fmt);
    assertEquals("flv", fmt.getInputFormatShortName());


    retval = container.close();
    assertTrue("could not close file", retval >= 0);
   
  }
View Full Code Here

  }
 
  @Test
  public void testQueryStreamMetaData()
  {
    IContainer container = IContainer.make();
   
    int retval = -1;
   
    retval = container.open(mSampleFile, IContainer.Type.READ, null);
    assertTrue("could not open file", retval >= 0);
   
    retval = container.queryStreamMetaData();
    assertTrue("could not query stream meta data", retval >= 0);
   
  }
View Full Code Here

TOP

Related Classes of com.xuggle.xuggler.IContainer

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.