gpt4 book ai didi

Android MediaRecorder 准备失败 -17

转载 作者:太空狗 更新时间:2023-10-29 14:30:50 27 4
gpt4 key购买 nike

我正在 try catch 视频并使用 Android MediaRecorder 对其进行编码。但是当我得到
准备失败:

-17
java.io.IOException: prepare failed.

这是我的代码:

mediaRecorder = new MediaRecorder();
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setOutputFile("/sdcard/test.mp4");
mediaRecorder.setVideoFrameRate(20);
mediaRecorder.setVideoSize(176, 144);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.prepare();

当我将 VideoEncoder 设置为 H263 并将 Outputformat 设置为 THREE_GPP 时,我没有收到此异常

这是完整的堆栈跟踪。

E/mm-camera 7x-vfe(   68): Received VFE start ACK!!! This is a user preview start.

D/QualcommCameraHardware( 68): startPreview X
E/AuthorDriver( 68): Command 13 completed with error -17
E/MediaRecorder( 6406): prepare failed: -17
W/System.err( 6406): java.io.IOException: prepare failed.
W/System.err( 6406): at android.media.MediaRecorder._prepare(Native Method)
W/System.err( 6406): at android.media.MediaRecorder.prepare(MediaRecorder.java:509)
W/System.err( 6406): at org.video.VideoStreamSender.prepare(VideoStreamSender.java:50)
W/System.err( 6406): at org.video.VideoPreview.surfaceCreated(VideoPreview.java:50)
W/System.err( 6406): at android.view.SurfaceView.updateWindow(SurfaceView.java:540)
W/System.err( 6406): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
W/System.err( 6406): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
W/System.err( 6406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
W/System.err( 6406): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
W/System.err( 6406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
W/System.err( 6406): at android.view.View.draw(View.java:6742)
W/System.err( 6406): at android.widget.FrameLayout.draw(FrameLayout.java:352)
W/System.err( 6406): at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
W/System.err( 6406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
W/System.err( 6406): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
W/System.err( 6406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
W/System.err( 6406): at android.view.View.draw(View.java:6742)
W/System.err( 6406): at android.widget.FrameLayout.draw(FrameLayout.java:352)
W/System.err( 6406): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1872)
W/System.err( 6406): at android.view.ViewRoot.draw(ViewRoot.java:1422)
W/System.err( 6406): at android.view.ViewRoot.performTraversals(ViewRoot.java:1167)
W/System.err( 6406): at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
W/System.err( 6406): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 6406): at android.os.Looper.loop(Looper.java:143)
W/System.err( 6406): at android.app.ActivityThread.main(ActivityThread.java:4914)
W/System.err( 6406): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 6406): at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err( 6406): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
W/System.err( 6406): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
W/System.err( 6406): at dalvik.system.NativeStart.main(Native Method)
I/CameraService( 68): [Camera KPI] 1st preview frame

最佳答案

在设置源和格式之前,您是否尝试过将相机设置到媒体记录器?像这样:

    mediaRecorder = new MediaRecorder();
Camera camera = Camera.open();

(可能需要解锁摄像头)

    (camera.unlock();)

mediaRecorder.setCamera(camera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
...

在我的例子中它有效。

关于Android MediaRecorder 准备失败 -17,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7120785/

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