问题描述
|
我正在使用Java Media Framework播放视频文件。
现在我想知道视频流的帧率吗?
那怎么可能?谢谢!
编辑:
可以使用以下实例:
javax.media.Manager
javax.media.MediaLocator
javax.media.noprocessorException
javax.media.Processor
解决方法
尝试以下
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 ) {
}
或从数据源形成内容描述符。对于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());
}
}
}
或至少尝试从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());
}
}
}