I'm trying to record, encode and finally create a short movie on Android (using API 16) with a combination of MediaCodec and Mp4Parser (to encapsulate into .mp4).
Everything is working just fine, except for the duration of the .mp4: its always 3 seconds long - and runs at about twice the 'right' speed.
- The input to encoder is 84 frames (taken 100ms apart).
- The last frame sets the 'end of stream' flag.
- I set the presentation time for each frame on
queueInputBuffer
I've tried to tweak every conceivable parameter - but nothing seems to make a difference - the film is always 3 seconds long - and always played way too fast.
So what governs the playback seepd? how do I generate a film with 'natuarl' speed?
I figured it out: When encapsulating with mp4parser (needed if you target API<18), you need to set the speed in mp4parser's API. The presentation time you provide to
queueInputBuffer
appearently make no difference if you're not using Android's built-in muxer (available only from API18).I stumbled on this question on github, which indicates the following is required: