Search code examples
javavideojmf

Java Media Framework: how to get framerate from videostream


I am using the Java Media Framework to play a video file.

Now I would like to know the framerate of the videostream?

How is that possible? Thanks!

edit: instances of the following are available:

javax.media.Manager
javax.media.MediaLocator
javax.media.NoProcessorException
javax.media.Processor

Solution

  • try the following

            try {
                Processor myProcessor = Manager.createProcessor( myMediaLocator );
                Format relax = myProcessor.getContentDescriptor().relax();
                if(relax instanceof VideoFormat) {
                    double frameRate = ((VideoFormat)relax).getFrameRate();
                }
            } catch( NoProcessorException e ) {
            } catch( NotConfiguredError e ) {
            } catch( IOException e ) {
            }
    

    or perhaps form the content descriptor form the DataSource. For URLDataSource:

    DataSource dataSource = myProcessor.getDataOutput();
    if(dataSource instanceof URLDataSource){
        PullSourceStream[] streams = ((URLDataSource)dataSource).getStreams();
        if(streams.length > 0){
            Format relax = streams[0].getContentDescriptor().relax();
            if(relax instanceof VideoFormat) {
                System.out.println(((VideoFormat)relax).getFrameRate());
            }
        }
    }
    

    or at least, try to get the Format from the javax.media.Buffer:

    DataSource dataSource = myProcessor.getDataOutput();
    if(dataSource instanceof PullBufferDataSource){ // or PushBufferDataSource
        PullBufferStream[] streams = ((PullBufferDataSource)dataSource).getStreams();
        if(streams.length > 0){
            Format relax = streams[0].getFormat();
            if(relax instanceof VideoFormat) {
                System.out.println(((VideoFormat)relax).getFrameRate());
            }
        }
    }