我正在尝试使用Camera的onPreviewFrame回调来学习编码mp4或任何类型的视频文件。
目前,我正在尝试此帖子中的示例代码
Encoding H.264 from camera with Android MediaCodec
不幸的是,我一直在
上遇到IllegalExceptionmediaCodec.configure(mediaFormat,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
来自另一篇文章 IllegalStateException when MediaCodec.configure Android, 我注意到我必须为MediaCodec设置一些强制值。
我尝试了所有强制性mediacodec的强制性值,但仍然没有幸运的过去
IllegalException。
现在我有点想要尝试的想法。任何建议,意见或提示将不胜感激。
感谢
11-04 12:27:14.785 175-894/? E/mm-libcamera2﹕ PROFILE HAL: stopPreview(): E: 1383596834.803557773
11-04 12:27:14.795 175-175/? E/OMXNodeInstance﹕ !!! Observer died. Quickly, do something, ... anything...
11-04 12:27:14.795 208-5797/? E/mm-camera﹕ config_shutdown_pp Camera not in streaming mode. Returning.
11-04 12:27:14.795 208-5797/? E/mm-camera﹕ vfe_ops_deinit: E
11-04 12:27:14.825 175-5814/? E/OMX-VENC-720p﹕ ioctl VEN_IOCTL_CMD_READ_NEXT_MSG failed
11-04 12:27:14.825 175-175/? E/OMX-VENC-720p﹕ Destroy C2D instance
11-04 12:27:14.835 527-539/? E/qcom_sensors_hal﹕ hal_process_report_ind: Bad item quality: 11
11-04 12:28:17.642 6241-6247/? E/jdwp﹕ Failed sending reply to debugger: Broken pipe
11-04 12:28:17.912 527-539/? E/qcom_sensors_hal﹕ hal_process_report_ind: Bad item quality: 11
11-04 12:28:17.922 208-6264/? E/mm-camera﹕ sensor_load_chromatix: libchromatix_imx111_preview.so: 30
11-04 12:28:18.032 208-6264/? E/mm-camera﹕ vfe_ops_init: E
11-04 12:28:18.042 208-6264/? E/mm-camera﹕ vfe_legacy_stats_buffer_init: AEC_STATS_BUFNUM
11-04 12:28:18.052 208-6264/? E/mm-camera﹕ vfe_legacy_stats_buffer_init: AEC_STATS_BUFNUM
11-04 12:28:18.052 208-6264/? E/mm-camera﹕ mctl_init_stats_proc_info: snap_max_line_cnt =30096
11-04 12:28:18.213 6241-6241/? E/CamcorderProfile﹕ width: 720
11-04 12:28:18.213 6241-6241/? E/CamcorderProfile﹕ height: 480
11-04 12:28:18.213 6241-6241/? E/CamcorderProfile﹕ audioSampleRate: 48000
11-04 12:28:18.213 6241-6241/? E/CamcorderProfile﹕ videoBitRate: 5000000
11-04 12:28:18.213 6241-6241/? E/CamcorderProfile﹕ videoFrameRate: 30
11-04 12:28:18.233 175-617/? E/OMX-VENC-720p﹕ Is component secure 0
11-04 12:28:18.263 6241-6280/? E/ACodec﹕ [OMX.qcom.video.encoder.avc] does not support color format 19
11-04 12:28:18.263 6241-6280/? E/ACodec﹕ [OMX.qcom.video.encoder.avc] configureCodec returning error -2147483648
11-04 12:28:18.263 6241-6279/? E/MediaCodec﹕ Codec reported an error. (omx error 0x80001001, internalError -2147483648)
11-04 12:28:18.263 6241-6241/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:259)
at com.example.mediacodec.AvcEncoder.<init>(AvcEncoder.java:40)
at com.example.mediacodec.Preview.surfaceCreated(MediaCodecActivity.java:304)
at android.view.SurfaceView.updateWindow(SurfaceView.java:571)
at android.view.SurfaceView.access$000(SurfaceView.java:86)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:833)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1860)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
11-04 12:28:20.135 175-617/? E/mm-libcamera2﹕ PROFILE HAL: stopPreview(): E: 1383596900.149872429
11-04 12:28:20.135 175-575/? E/OMXNodeInstance﹕ !!! Observer died. Quickly, do something, ... anything...
11-04 12:28:20.135 208-6264/? E/mm-camera﹕ config_shutdown_pp Camera not in streaming mode. Returning.
11-04 12:28:20.145 208-6264/? E/mm-camera﹕ vfe_ops_deinit: E
11-04 12:28:20.165 175-6283/? E/OMX-VENC-720p﹕ ioctl VEN_IOCTL_CMD_READ_NEXT_MSG failed
11-04 12:28:20.165 175-575/? E/OMX-VENC-720p﹕ Destroy C2D instance
11-04 12:28:20.195 527-539/? E/qcom_sensors_hal﹕ hal_process_report_ind: Bad item quality: 11
答案 0 :(得分:5)
E/ACodec﹕ [OMX.qcom.video.encoder.avc] does not support color format 19
看起来您正在尝试在Qualcomm设备上使用颜色格式19(COLOR_FormatYUV420Planar,a / k / a I420)。对我的一个设备进行快速测试表明他们的编解码器需要颜色格式21(COLOR_FormatYUV420SemiPlanar,a / k / a NV12)。
EncodeDecodeTest sources中的缓冲区到缓冲区测试显示如何查询MediaCodecInfo
以获取适当的颜色格式。由于您正在接收来自摄像头的输入,因此您需要将预览格式设置为半平面布局(NV21),然后在将其传递给MediaCodec之前执行U/V swap。
如果您使用的是Android 4.3或更高版本,则可以跳过所有格式体操并使用Surface
预览输出。有关示例,请参阅CameraToMpegTest sources。