Android MediaCodec API video plays too fast
Asked Answered
M

1

6

I'm currently working with Android Jelly Bean MediaCodec API to develop a simple video player.

I extract tracks, play audio and video in separate threads. The problem is that video track always is played too fast.

Where can be the problem hidden?
Both audio and video are treated almost the same way, except audio is played via AudioTrack and video is rendered to the surface.

Meter answered 17/10, 2012 at 9:36 Comment(3)
Where did you get to on this?Anthotaxy
Can you please post your code. It would be helpful inn debuggingSlavish
i am having the same problem, have you figured it out?Hasheem
B
4

If you render frames at maximum speed you'll hit 60fps on most devices. You need to pace it according to the presentation time stamps provided by the encoder.

For example, if the input is a format supported by Android (e.g. a typical .mp4 file), you can use the MediaExtractor class to extract each frame. The time stamp can be retrieved with getSampleTime(). You want to delay rendering by the difference between timestamps on consecutive frames -- don't assume that the first frame will have a timestamp of zero.

Also, don't assume that video frames appear at a constant rate (e.g. 30fps). For some sources the frames will arrive unevenly.

See the "Play video (TextureView)" example in Grafika, particularly the SpeedControlCallback class. The gen-eight-rects.mp4 video uses variable frame durations to exercise it. If you check the "Play at 60fps" box, the presentation time stamps are ignored.

Briquette answered 5/2, 2014 at 2:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.