我使用 MediaMuxer 混合音频和无线电数据,数据来自两个编码器,流是正确的,我得到输出并播放它。但是由于错误,当 writeSampleData 时 MediaMuxer 可能会失败:
E/MPEG4Writer: timestampUs 21932611 < lastTimestampUs 22055361 for Video track
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: FATAL EXCEPTION: MediaMuxer
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: Process: org.cocos2dx.simplegame, PID: 20089
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: java.lang.IllegalStateException: writeSampleData returned an error
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: at android.media.MediaMuxer.nativeWriteSampleData(Native Method)
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: at android.media.MediaMuxer.writeSampleData(MediaMuxer.java:334)
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: at com.duapps.durecorder.muxer.DuMediaMuxer.handleMessage(DuMediaMuxer.java:53)
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
10-14 14:23:41.580 20089-20230/org.cocos2dx.simplegame E/AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:61)
我看到 MPEG4Writer,错误的根本原因是视频的时间戳,它让 MediaMuxer 运行到 IllegalState。在我做了很多测试之后,我知道视频和音频时间戳都可能会出错,当我改变音频采样率时,重复率会改变。
当我只录制音频或收音机时,错误不会再次出现。
有人可以给我一些建议吗?