当前位置: 首页>>代码示例>>Java>>正文


Java IMediaWriter.encodeVideo方法代码示例

本文整理汇总了Java中com.xuggle.mediatool.IMediaWriter.encodeVideo方法的典型用法代码示例。如果您正苦于以下问题:Java IMediaWriter.encodeVideo方法的具体用法?Java IMediaWriter.encodeVideo怎么用?Java IMediaWriter.encodeVideo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.xuggle.mediatool.IMediaWriter的用法示例。


在下文中一共展示了IMediaWriter.encodeVideo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createVideoFromScreens

import com.xuggle.mediatool.IMediaWriter; //导入方法依赖的package包/类
public void createVideoFromScreens() {
  IMediaWriter writer = null;
  try {
    if (getOutputFile() == null) {
      throw new IllegalStateException(
          "Output video file cannot be null");
    }

    setStoppedCreation(false);

    writer = ToolFactory.makeWriter(getOutputFile()
        .getAbsolutePath());
    writer.addVideoStream(0, 0, SCREEEN_BOUNDS.width,
        SCREEEN_BOUNDS.height);

    long startTime = System.nanoTime();

    while (!getPleaseStop()) {
      BufferedImage screen = getDesktopScreenshot();
      BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR);

      writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);

      try {
        Thread.currentThread().sleep(1000 / FRAME_RATE);
      } catch (InterruptedException e) {
        // Ignore
      }
    }
    setStoppedCreation(true);
  } finally {
    if(writer!=null){
      writer.flush();
      writer.close();
    }
    
  }
}
 
开发者ID:barancev,项目名称:testng_samples,代码行数:39,代码来源:VideoCreator.java

示例2: main

import com.xuggle.mediatool.IMediaWriter; //导入方法依赖的package包/类
/**
 * Takes a screen shot of your entire screen and writes it to
 * output.flv
 * 
 * @param args
 */
public static void main(String[] args) {
    try {
        final String outFile;
        if (args.length > 0)
            outFile = args[0];
        else
            outFile = "output.mp4";
        // This is the robot for taking a snapshot of the
        // screen.  It's part of Java AWT
        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());
    }
}
 
开发者ID:destiny1020,项目名称:java-learning-notes-cn,代码行数:58,代码来源:CaptureScreenToFile.java


注:本文中的com.xuggle.mediatool.IMediaWriter.encodeVideo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。