3

I've many video files. All the types are different (mkv, avi, mp4, flv, etc.). I want to iterate these files and get the duration of the movies.

Currently I use vlcj which is OK, but the code is a little bit confusing me. I have to play the media before I can get the length. Then stop the media. This is weird, isn't it.

Can I do that better somehow? I've heard about xuggler, but the development has stopped. I need an API or 3rdparty component that is still alive. And I don't want to play the media before I play :)

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
mudlee
  • 680
  • 12
  • 22
  • *"I have to play the media before I can get the length. Then stop the media. This is weird, isn't it."* Not weird at all. When media is VBR (Variable bit rate) it is typically impossible to get a length without playing the file from start to finish, or at least constructing it to the point it *could* be played. – Andrew Thompson Mar 27 '13 at 22:10
  • You're right, it's true. But in my mind the process should follow this: 1. open the media (process,analysis etc) 2. movie meta available 3. close media. Without playing. Maybe I should use Xuggler for that problem, and should not carry about the support (http://blog.xuggle.com/2013/02/05/on-hiatus/). Am I correct? – mudlee Mar 28 '13 at 08:00

2 Answers2

6

Finally, I've solved the problem with Xuggle. After setup I had to add these lines, and it works fine:

IContainer container = IContainer.make();
    if (container.open(movie, IContainer.Type.READ, null) < 0) {
        throw new RuntimeException("Cannot open '" + movie + "'");
    }

    logger.info("# Duration (ms): " + ((container.getDuration() == Global.NO_PTS) ? "unknown" : "" + container.getDuration() / 100));
    logger.info("# File size (bytes): " + container.getFileSize());
    logger.info("# Bit rate: " + container.getBitRate());

BTW, the setup was awful, but finally... got this code to work.

mudlee
  • 680
  • 12
  • 22
  • Is this possible for you to share your project as opensource. or write something about integration. and very important how many formats does it supports? – AZ_ Jun 10 '14 at 06:53
  • Check the duration. Should be divided by 1000 not 100 : container.getDuration() / 1000 – Radu Toader Jul 03 '15 at 16:44
  • It is definetly possible, I just shut down this project for a little time, but I have to go back again... :) I'll not here if it's ready. – mudlee Oct 12 '15 at 04:40
0

See Java Media Framework.

http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/index.html

Here you will find links to other similar projects also http://en.wikipedia.org/wiki/Java_Media_Framework

Łukasz Rzeszotarski
  • 5,791
  • 6
  • 37
  • 68
  • JMF only supports 1 of the 4 media types quoted in the question. If VLCJ or Xuggler or ffmpeg are unable to do this task, so will JMF be unable! – Andrew Thompson Mar 27 '13 at 22:13
  • Yes, exactly. I saw JMF, but everybody said it's more than just out dated. FFmpeg is also a good pick, I'm just worried about the cross platform thing... VLCJ has a library on windows an linux and I can choose at the application start, which I want to use. – mudlee Mar 28 '13 at 07:58