How to determine a video file's framerate with MediaCodec, MediaExtractor or MediaMetadataRetriever?

前端 未结 3 1600
南笙
南笙 2021-01-14 03:19

How to I extract the frame rate of a recorded video file? I know that there is MediaFormat.KEY_FRAME_RATE and that I can access MediaFormat objects through MediaExtractor. H

3条回答
  •  野的像风
    2021-01-14 03:55

    When using MediaExtractor, if your video track has a stable FPS, then you know for sure your MediaExtractor is advancing by the frame duration you are searching for.

    Before doing anything, just after having set up your MediaExtractor, you can do the following:

    mediaExtractor.Advance();
    var fps = 1000000f / (float) mediaExtractor.SampleTime;
    mediaExtractor.SeekTo(0, MediaExtractorSeekTo.None);
    

    Like I said, you can't take for grant that all your frames have the same duration. Frame presentation time are totally arbitrary, but I feel it's not common to not have a stable FPS.

提交回复
热议问题