gpt4 book ai didi

java - CameraToMpegTest.java 不工作,以 IllegalStateException : Can't stop due to wrong state 结束

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:54:41 28 4
gpt4 key购买 nike

我从 http://bigflake.com/mediacodec/ 运行 CameraToMpegTest.java 时遇到问题.当我从 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();
}

}

...

我以这个 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

经过一些测试后,我尝试围绕调用 mStManager.awaitNewImage();使用带有异常打印的 try-catch block ,我得到了这个:

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.

这似乎与这个问题(android: SurfaceTexure, camera frame wait time out)中的问题类似,但 CameraToMpegTest.java 使用单独的线程。

我的测试设备是运行 4.4.4 Android 的 Google Nexus 7 (2012) 32GB 3G。

最佳答案

如果您启动了 MediaMuxer 类,但尚未向其提供任何数据,则该类将抛出“无法停止”异常。这没有多大意义,但这就是它的工作原理。

根本问题是没有数据进入,这通常是由于您确定的问题所致(在 this answer 中详细描述了 SurfaceTexture 的一个怪癖)。您需要确保执行工作的线程没有 Looper。

您最好使用 Grafika作为示例代码。 “连续捕捉”等 Activity 展示了应用环境中的相机到 MPEG 路径,而不是 CTS 测试环境。

关于java - CameraToMpegTest.java 不工作,以 IllegalStateException : Can't stop due to wrong state 结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26487832/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com