如何获取 android os 中视频的帧率?
how to get frame rate of video in android os?
我想获取视频的帧率,但我不想使用 FFMPEG、JAVACV 库。
是否可以在 android 中获得视频的帧速率?
我读到 KEY_FRAME_RATE 是这样说的,"Specifically, MediaExtractor provides an integer value corresponding to the frame rate information of the track if specified and non-zero."
但是不知道怎么用?
如果您知道如何从视频中获取帧速率,请在此处回答。
MediaExtractor extractor = new MediaExtractor();
int frameRate = 24; //may be default
try {
//Adjust data source as per the requirement if file, URI, etc.
extractor.setDataSource(...);
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; ++i) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}finally {
//Release stuff
extractor.release();
}
注意:尝试运行工作线程中的上述代码。
更新 1 什么是 KEY_FRAME_RATE 并且可能 可选
KEY_FRAME_RATE
Added in API level 16
String KEY_FRAME_RATE
A key describing the frame rate of a video format in frames/sec. The associated value is normally an integer when the value is used by the platform, but video codecs also accept float configuration values. Specifically, MediaExtractor provides an integer value corresponding to the frame rate information of the track if specified and non-zero. Otherwise, this key is not present. MediaCodec accepts both float and integer values. This represents the desired operating frame rate if the KEY_OPERATING_RATE is not present and KEY_PRIORITY is 0 (realtime). For video encoders this value corresponds to the intended frame rate, although encoders are expected to support variable frame rate based on buffer timestamp. This key is not used in the MediaCodec input/output formats, nor by MediaMuxer.
常数值:"frame-rate"
更新 2 如果 KEY_FRAME_RATE 不存在,则代码检查是否存在 NPE。见上文
我想获取视频的帧率,但我不想使用 FFMPEG、JAVACV 库。 是否可以在 android 中获得视频的帧速率?
我读到 KEY_FRAME_RATE 是这样说的,"Specifically, MediaExtractor provides an integer value corresponding to the frame rate information of the track if specified and non-zero." 但是不知道怎么用?
如果您知道如何从视频中获取帧速率,请在此处回答。
MediaExtractor extractor = new MediaExtractor();
int frameRate = 24; //may be default
try {
//Adjust data source as per the requirement if file, URI, etc.
extractor.setDataSource(...);
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; ++i) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}finally {
//Release stuff
extractor.release();
}
注意:尝试运行工作线程中的上述代码。
更新 1 什么是 KEY_FRAME_RATE 并且可能 可选
KEY_FRAME_RATE Added in API level 16 String KEY_FRAME_RATE A key describing the frame rate of a video format in frames/sec. The associated value is normally an integer when the value is used by the platform, but video codecs also accept float configuration values. Specifically, MediaExtractor provides an integer value corresponding to the frame rate information of the track if specified and non-zero. Otherwise, this key is not present. MediaCodec accepts both float and integer values. This represents the desired operating frame rate if the KEY_OPERATING_RATE is not present and KEY_PRIORITY is 0 (realtime). For video encoders this value corresponds to the intended frame rate, although encoders are expected to support variable frame rate based on buffer timestamp. This key is not used in the MediaCodec input/output formats, nor by MediaMuxer.
常数值:"frame-rate"
更新 2 如果 KEY_FRAME_RATE 不存在,则代码检查是否存在 NPE。见上文