问题描述
我正在尝试结合MediaCodec和Mp4Parser(封装为.mp4)在Android上使用API 16录制,编码并最终制作一部短片.
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).
除了.mp4的持续时间外,一切正常,它始终为3秒,运行速度约为正确"速度的两倍.
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.
- 编码器的输入为84帧(相隔100ms).
- 最后一帧设置流结束"标志.
- 我在
queueInputBuffer
上设置每帧的演示时间
- 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
我试图调整所有可能的参数-但似乎没有什么不同-电影总是3秒长-总是播放得太快了.
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.
那么什么决定了播放的渗透呢?如何以"natuarl"速度拍摄电影?
So what governs the playback seepd? how do I generate a film with 'natuarl' speed?
推荐答案
我知道了:用mp4parser封装时(如果目标API是18),则需要在mp4parser的API中设置速度.如果您未使用Android的内置混合器(仅可从API18获得),则您提供给queueInputBuffer
的演示时间似乎没有任何区别.
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).
我在github上偶然发现了这个问题,该问题表明需要以下内容:
I stumbled on this question on github, which indicates the following is required:
new H264TrackImpl(new FileDataSourceImpl(rawDataFile), "eng", 100, 10);
- 最后两个参数(timeScale和frameTick)将播放速度设置为"noraml".
这篇关于使用Android的MediaCodec + mp4parser编码时,什么决定播放速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!