Examples of IMediaWriter


Examples of com.xuggle.mediatool.IMediaWriter

        thread = new Thread(new Runnable() {
            @Override
            public void run() {

                final IMediaWriter writer = ToolFactory.makeWriter(recordedVideo.getAbsolutePath());
                writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, screenBounds.width / 2, screenBounds.height / 2);

                long startTime = System.nanoTime();

                timer = new Timer();
                timer.schedule(new TestTimeoutTask(), TimeUnit.SECONDS.toMillis(configuration.getTestTimeout()));

                while (running) {
                    BufferedImage bgrScreen = convertToType(getDesktopScreenshot(), BufferedImage.TYPE_3BYTE_BGR);
                    writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);

                    try {
                        Thread.sleep(500 / frameRate);
                    } catch (InterruptedException ex) {
                        logger.error("Exception occured during video recording", ex);
                    }
                    if (!running) {
                        writer.close();
                    }
                }
            }
        });
        thread.start();
View Full Code Here

Examples of com.xuggle.mediatool.IMediaWriter

                    output.deleteOnExit();
                    output.createNewFile();
                } catch (IOException e) {
                    throw new IllegalStateException("Can't create a temporary file for recording.", e);
                }
                IMediaWriter writer = ToolFactory.makeWriter(output.getAbsolutePath());
                writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,
                    screenBounds.width / 2, screenBounds.height / 2);
                long startTime = System.nanoTime();
                while (running) {
                    BufferedImage screen = getDesktopScreenshot();

                    BufferedImage bgrScreen = convertToType(screen,
                            BufferedImage.TYPE_3BYTE_BGR);

                    writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime,
                            TimeUnit.NANOSECONDS);
                    try {
                        Thread.sleep((long) (1000 / FRAME_RATE));
                    } catch (InterruptedException ex) {
                        logger.error("Exception occured during video recording", ex);
                    }
                    if (!running) {
                        writer.close();
                        try {
                            if (destination != null) {
                                if (destination.exists()) {
                                    destination.delete();
                                }
View Full Code Here

Examples of com.xuggle.mediatool.IMediaWriter

    long totalSampleCount = 0;

    // create a media writer and specify the output file

    final IMediaWriter writer = ToolFactory.makeWriter("myballs.mov");

    // add a viewer so we can see the media as it is created

    writer.addListener(ToolFactory.makeViewer(
        IMediaViewer.Mode.AUDIO_VIDEO, true,
        javax.swing.WindowConstants.EXIT_ON_CLOSE));

    // add the video stream

    writer.addVideoStream(videoStreamIndex, videoStreamId,
        width, height);

    // add the audio stream

    writer.addAudioStream(audioStreamIndex, audioStreamId,
        channelCount, sampleRate);

    // create some balls to show on the screen

    Balls balls = new MovingBalls(ballCount, width, height, sampleCount);

    // loop through clock time, which starts at zero and increases based
    // on the total number of samples created thus far

    for (long clock = 0; clock < duration; clock = IAudioSamples
           .samplesToDefaultPts(totalSampleCount, sampleRate))
    {
      // while the clock time exceeds the time of the next video frame,
      // get and encode the next video frame

      while (clock >= nextFrameTime)
      {
        BufferedImage frame = balls.getVideoFrame(frameRate);
        writer.encodeVideo(videoStreamIndex, frame, nextFrameTime,
          DEFAULT_TIME_UNIT);
        nextFrameTime += frameRate;
      }

      // compute and encode the audio for the balls

      short[] samples = balls.getAudioFrame(sampleRate);
      writer.encodeAudio(audioStreamIndex, samples, clock,
        DEFAULT_TIME_UNIT);
      totalSampleCount += sampleCount;
    }

    // manually close the writer
   
    writer.close();
 
View Full Code Here

Examples of com.xuggle.mediatool.IMediaWriter

    reader1.addListener(concatenator);
    reader2.addListener(concatenator);

    // create the media writer which listens to the concatenator

    IMediaWriter writer = ToolFactory.makeWriter(destinationUrl);
    concatenator.addListener(writer);

    // add the video stream

    writer.addVideoStream(videoStreamIndex, videoStreamId, width, height);

    // add the audio stream

    writer.addAudioStream(audioStreamIndex, audioStreamId, channelCount,
      sampleRate);

    // read packets from the first source file until done

    while (reader1.readPacket() == null)
      ;

    // read packets from the second source file until done

    while (reader2.readPacket() == null)
      ;

    // close the writer

    writer.close();
  }
View Full Code Here

Examples of com.xuggle.mediatool.IMediaWriter

      final Robot robot = new Robot();
      final Toolkit toolkit = Toolkit.getDefaultToolkit();
      final Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
     
      // First, let's make a IMediaWriter to write the file.
      final IMediaWriter writer = ToolFactory.makeWriter(outFile);
     
      // We tell it we're going to add one video stream, with id 0,
      // at position 0, and that it will have a fixed frame rate of
      // FRAME_RATE.
      writer.addVideoStream(0, 0,
          FRAME_RATE,
          screenBounds.width, screenBounds.height);
     
      // Now, we're going to loop
      long startTime = System.nanoTime();
      for (int index = 0; index < SECONDS_TO_RUN_FOR*FRAME_RATE.getDouble(); index++)
      {
        // take the screen shot
        BufferedImage screen = robot.createScreenCapture(screenBounds);
       
        // convert to the right image type
        BufferedImage bgrScreen = convertToType(screen,
            BufferedImage.TYPE_3BYTE_BGR);
       
        // encode the image
        writer.encodeVideo(0,bgrScreen,
            System.nanoTime()-startTime, TimeUnit.NANOSECONDS);

        System.out.println("encoded image: " +index);
       
        // sleep for framerate milliseconds
        Thread.sleep((long) (1000 / FRAME_RATE.getDouble()));

      }
      // Finally we tell the writer to close and write the trailer if
      // needed
      writer.close();
    }
    catch (Throwable e)
    {
      System.err.println("an error occurred: " + e.getMessage());
    }
View Full Code Here

Examples of com.xuggle.mediatool.IMediaWriter

    IMediaReader reader = ToolFactory.makeReader(inputFile.toString());
    reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);

    // create a writer and configure it's parameters from the reader
   
    IMediaWriter writer = ToolFactory.makeWriter(outputFile.toString(), reader);

    // create a tool which paints video time stamp into frame

    IMediaTool addTimeStamp = new TimeStampTool();

    // create a tool which reduces audio volume to 1/10th original

    IMediaTool reduceVolume = new VolumeAdjustTool(0.1);

    // create a tool chain:
    //   reader -> addTimeStamp -> reduceVolume -> writer

    reader.addListener(addTimeStamp);
    addTimeStamp.addListener(reduceVolume);
    reduceVolume.addListener(writer);

    // add a viewer to the writer, to see media modified media
   
    writer.addListener(ToolFactory.makeViewer());

    // read and decode packets from the source file and
    // then encode and write out data to the output file
   
    while (reader.readPacket() == null)
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.