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


Java IMediaWriter.addVideoStream方法代码示例

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


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

示例3: concatenate

import com.xuggle.mediatool.IMediaWriter; //导入方法依赖的package包/类
/**
 * Concatenate two source files into one destination file.
 * 
 * @param sourceUrl1 the file which will appear first in the output
 * @param sourceUrl2 the file which will appear second in the output
 * @param destinationUrl the file which will be produced
 */

public static void concatenate(String sourceUrl1, String sourceUrl2,
        String destinationUrl) {
    out.printf("transcode %s + %s -> %s\n", sourceUrl1, sourceUrl2,
            destinationUrl);

    //////////////////////////////////////////////////////////////////////
    //                                                                  //
    // NOTE: be sure that the audio and video parameters match those of //
    // your input media                                                 //
    //                                                                  //
    //////////////////////////////////////////////////////////////////////

    // video parameters

    final int videoStreamIndex = 0;
    final int videoStreamId = 0;
    final int width = 1920;
    final int height = 1080;

    // audio parameters

    final int audioStreamIndex = 1;
    final int audioStreamId = 0;
    final int channelCount = 2;
    final int sampleRate = 48000; // Hz

    // create the first media reader

    IMediaReader reader1 = ToolFactory.makeReader(sourceUrl1);

    // create the second media reader

    IMediaReader reader2 = ToolFactory.makeReader(sourceUrl2);

    // create the media concatenator

    MediaConcatenator concatenator = new MediaConcatenator(
            audioStreamIndex, videoStreamIndex);

    // concatenator listens to both readers

    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();
}
 
开发者ID:destiny1020,项目名称:java-learning-notes-cn,代码行数:81,代码来源:ConcatenateAudioAndVideo.java


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