I have a problem running CameraToMpegTest.java from http://bigflake.com/mediacodec/. When I start it from the Activity:
public class MyActivity extends Activity {
private CameraToMpegTest ctmt = new CameraToMpegTest();
...
@Override
protected void onResume() {
super.onResume();
try {
ctmt.testEncodeCameraToMp4();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
...
I end with this logcat:
D/CameraToMpegTest﹕ video/avc output 640x480 @6000000
D/CameraToMpegTest﹕ Camera preview size is 640x480
I/OMXClient﹕ Using client-side OMX mux.
E/ACodec﹕ [OMX.Nvidia.h264.encoder] storeMetaDataInBuffers (output) failed w/ err -2147483648
I/ACodec﹕ setupVideoEncoder succeeded
D/libEGL﹕ loaded /system/lib/egl/libEGL_tegra.so
D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_tegra.so
D/libEGL﹕ loaded /system/lib/egl/libGLESv2_tegra.so
I/CameraToMpegTest﹕ Output file is /storage/emulated/0/test.640x480.mp4
W/System.err﹕ java.lang.IllegalStateException: Can't stop due to wrong state.
W/System.err﹕ at android.media.MediaMuxer.stop(MediaMuxer.java:229)
W/System.err﹕ at CameraToMpegTest.releaseEncoder(CameraToMpegTest.java:395)
W/System.err﹕ at CameraToMpegTest.encodeCameraToMpeg(CameraToMpegTest.java:216)
W/System.err﹕ at CameraToMpegTest.access$000(CameraToMpegTest.java:68)
W/System.err﹕ at CameraToMpegTest$CameraToMpegWrapper.run(CameraToMpegTest.java:128)
W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
D/OpenGLRenderer﹕ Enabling debug mode 0
After some testing I tried to surround calling mStManager.awaitNewImage(); with try-catch block with Exceptions printing and I got this:
D/CameraToMpegTest﹕ video/avc output 640x480 @6000000
D/CameraToMpegTest﹕ Camera preview size is 640x480
I/OMXClient﹕ Using client-side OMX mux.
E/ACodec﹕ [OMX.Nvidia.h264.encoder] storeMetaDataInBuffers (output) failed w/ err -2147483648
I/ACodec﹕ setupVideoEncoder succeeded
D/libEGL﹕ loaded /system/lib/egl/libEGL_tegra.so
D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_tegra.so
D/libEGL﹕ loaded /system/lib/egl/libGLESv2_tegra.so
I/CameraToMpegTest﹕ Output file is /storage/emulated/0/test.640x480.mp4
I/System.out﹕ java.lang.RuntimeException: Camera frame wait timed out
I/System.out﹕ java.lang.RuntimeException: Camera frame wait timed out
D/CameraToMpegTest﹕ encoder output format changed: {csd-1=java.nio.ByteArrayBuffer[position=0,limit=8,capacity=8], height=480, mime=video/avc, csd-0=java.nio.ByteArrayBuffer[position=0,limit=13,capacity=13], what=1869968451, width=640}
I/MPEG4Writer﹕ limits: 4294967295/0 bytes/us, bit rate: -1 bps and the estimated moov size 3072 bytes
I/MPEG4Writer﹕ setStartTimestampUs: 0
I/MPEG4Writer﹕ Earliest track starting time: 0
I/System.out﹕ java.lang.RuntimeException: Camera frame wait timed out
W/MPEG4Writer﹕ 0-duration samples found: 1
W/MPEG4Writer﹕ 0-duration samples found: 2
I/MPEG4Writer﹕ Received total/0-length (3/0) buffers and encoded 3 frames. - video
D/MPEG4Writer﹕ Stopping Video track
D/MPEG4Writer﹕ Stopping Video track source
D/MPEG4Writer﹕ Video track stopped
D/MPEG4Writer﹕ Stopping writer thread
D/MPEG4Writer﹕ 0 chunks are written in the last batch
D/MPEG4Writer﹕ Writer thread stopped
D/MPEG4Writer﹕ Stopping Video track
D/OpenGLRenderer﹕ Enabling debug mode 0
I/Choreographer﹕ Skipped 90 frames! The application may be doing too much work on its main thread.
It seems to be similar problem like in this question (android: SurfaceTexure, camera frame wait time out) but the CameraToMpegTest.java uses separate thread.
My testing device is Google Nexus 7 (2012) 32GB 3G running 4.4.4 Android.
The MediaMuxer
class will throw "unable to stop" exceptions if you have started it, but haven't yet fed it any data. This doesn't make much sense, but that's how it works.
The root problem is that there's no data going in, which is usually due to the issue you identified (a quirk of SurfaceTexture described in some detail in this answer). You need to make sure that the thread doing the work doesn't have a Looper.
You may be better off using Grafika as sample code. Activities like "continuous capture" demonstrate the camera-to-MPEG path in an app environment, rather than a CTS test environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With