【问题标题】:images to video Xuggler图像到视频 Xuggler
【发布时间】:2013-05-27 10:37:13
【问题描述】:

我使用 xuggler 但不明白。我有 ArrayList,我想用这些图像、视频制作。但是当我在视频图像上编译这段代码的前 5 秒没有改变,在视频上的最后 5 秒完全没有。如何解决。

public class ScreenRecordingExample {

    private static int FPS = 1000 / 25;
    private static final String outputFilename = "c:/mydesktop.mp4";
    private static Dimension screenBounds;

    public static void main(String[] args) throws IOException {

        final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);

        screenBounds = Toolkit.getDefaultToolkit().getScreenSize();

        writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,
                screenBounds.width / 2, screenBounds.height / 2);

        long startTime = System.nanoTime();

        List<BufferedImage> BIList = getImagesFromDirectory(null);

        for (int index = 0; index < BIList.size(); index++) {

            BufferedImage bgrScreen = convertToType(BIList.get(index),BufferedImage.TYPE_3BYTE_BGR);
            writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime,
                    TimeUnit.NANOSECONDS);

            try {
                Thread.sleep((long) (1000 / 15));
            } catch (InterruptedException e) {}
        }

        writer.close();

    }

    public static BufferedImage convertToType(BufferedImage sourceImage, int targetType) {

        BufferedImage image;

        // if the source image is already the target type, return the source image
        if (sourceImage.getType() == targetType) {
            image = sourceImage;
        } // otherwise create a new image of the target type and draw the new image
        else {
            image = new BufferedImage(sourceImage.getWidth(),
                    sourceImage.getHeight(), targetType);
            image.getGraphics().drawImage(sourceImage, 0, 0, null);
        }

        return image;

    }

    private static List<BufferedImage> getImagesFromDirectory(File directory) throws IOException {


        File dir = new File("C:\\fotos\\");
        final String[] EXTENSIONS = new String[]{"gif", "png", "bmp"};

        final List<BufferedImage> imageList = new ArrayList<BufferedImage>();

        FilenameFilter IMAGE_FILTER = new FilenameFilter() {

            @Override
            public boolean accept(final File dir, final String name) {
                for (final String ext : EXTENSIONS) {
                    if (name.endsWith("." + ext)) {
                        return (true);
                    }
                }
                return (false);
            }
        };
        if (dir.isDirectory()) { // make sure it's a directory
            for (final File f : dir.listFiles(IMAGE_FILTER)) {
                BufferedImage img = null;
                img = ImageIO.read(f);
                imageList.add(img);
            }
        }
        return imageList;
    }

【问题讨论】:

    标签: java xuggler xuggle


    【解决方案1】:

    编辑您的问题,它本身就是一个谜。 Dint 理解您所说的“视频图像的前 5 秒不变,视频的最后 5 秒根本不变”的意思。

    【讨论】:

      【解决方案2】:

      我希望你能找到答案,但这可能对其他人有帮助,在调用 getImagesFromDirectory 之后移动开始时间初始化

      long startTime = System.nanoTime();
      List<BufferedImage> BIList = getImagesFromDirectory(null);
      

      List<BufferedImage> BIList = getImagesFromDirectory(null);
      long startTime = System.nanoTime();*
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多