I am trying to create short sequential mp4 files from CameraPreview data via MediaCodec.createInputSurface() . However, to recreate MediaCodec and its associated surface, you need to stop the camera to allow another call to mCamera.setPreviewTexture(...) . This delay results in an unacceptable number of dropped frames.
Therefore, I need to periodically generate CODEC_CONFIG and END_OF_STREAM without recreating the input surface and, therefore, to call mCamera.setPreviewTexture(...) . Is it possible that the value of MediaFormat not changed?
(I am adapting fadden CameraToMpegTest . My full code is here )
Failed Attempts:
Calling MediaCodec.signalEndOfInputStream() , dropping MediaCodec , and then calling MediaCodec.flush() between the chunks IllegalStateException an IllegalStateException on the second call to MediaCodec.signalEndOfInputStream() .
Call MediaCodec.signalEndOfInputStream() , reset MediaCodec , and then call MediaCodec.stop(); MediaCodec.configure(...), MediaCodec.start() MediaCodec.stop(); MediaCodec.configure(...), MediaCodec.start() between fragments without calling MediaCodec.createInputSurface() again causes the following error:
09-30 13:12:49.889 17638-17719/x.xx.xxxx E/Surface﹕ queueBuffer: error queuing buffer to SurfaceTexture, -19 09-30 13:12:49.889 17638-17719/x.xx.xxxx E/IMGSRV﹕ :0: UnlockPostBuffer: Failed to queue buffer 0x592e1e70 09-30 13:12:49.889 17638-17719/x.xx.xxxx E/CameraToMpegTest﹕ Encoding loop exception! 09-30 13:12:49.889 17638-17719/x.xx.xxxx W/System.err﹕ java.lang.RuntimeException: eglSwapBuffers: EGL error: 0x300b 09-30 13:12:49.896 17638-17719/x.xx.xxxx W/System.err﹕ at x.xx.xxxx.ChunkedHWRecorder$CodecInputSurface.checkEglError(ChunkedHWRecorder.java:731) 09-30 13:12:49.896 17638-17719/x.xx.xxxx W/System.err﹕ at x.xx.xxxx.ChunkedHWRecorder$CodecInputSurface.swapBuffers(ChunkedHWRecorder.java:713) 09-30 13:12:49.896 17638-17719/x.xx.xxxx W/System.err﹕ at x.xx.xxxx.ChunkedHWRecorder.startRecording(ChunkedHWRecorder.java:164) 09-30 13:12:49.896 17638-17719/x.xx.xxxx W/System.err﹕ at x.xx.xxxx.HWRecorderActivity$CameraToMpegWrapper.run(HWRecorderActivity.java:76) 09-30 13:12:49.896 17638-17719/x.xx.xxxx W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
Solved Thanks fadden. The full source of the solution is here .
dbro source share