如何从 JAVA 中的文件夹中获取所有视频的时长?

How to get duration of all videos from a folder in JAVA?

我想从 "New Folder" 获取所有视频文件的持续时间。

我有所有视频的列表,但我不知道如何达到他们的持续时间。

public static void main(String[] args) throws IOException {
        File file = new File("C:\y\ee\t\New Folder");
        File[] list = file.listFiles();
        for (int i = 0; i < list.length; i++) {
                System.out.println(list[i].getName() + "Video duration: ");
        }


    }

我想得到这样的东西

video1.webm Video duration: 0:34
video2.webm Video duration: 1:43
video3.webm Video duration: 0:54

您好,我找到了 2 种方法可以帮助您解决问题。

请试用。

1) 使用 xuggle 库。 (http://www.xuggle.com/downloads)

private static final String filename = "FILE_PATH";
IContainer container = IContainer.make();
int result = container.open(filename, IContainer.Type.READ, null);
long duration = container.getDuration();
long fileSize = container.getFileSize();

你可以在这里找到教程。 (https://examples.javacodegeeks.com/desktop-java/xuggler/inspect-a-video-file-with-xuggler/)

2) 使用windows MediaInfo.exe。 (http://www.javacreed.com/how-to-retrieve-the-video-properties/)