簡體   English   中英

圖片到視頻Xuggler

[英]images to video Xuggler

我使用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;
    }

編輯您的問題,這本身就是一個難題。 Dint理解“在視頻圖像上的前5秒不變,而在視頻上的最后5秒完全不變”的含義。

我希望您能找到答案,但這可能會對其他人有所幫助,在調用getImagesFromDirectory之后將開始時間初始化

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM