【问题标题】:Android Unable to instantiate codec 'video/avc'Android 无法实例化编解码器“video/avc”
【发布时间】:2015-11-21 04:39:28
【问题描述】:

这是我的第一篇文章,请多多包涵。

我正在尝试将原始 h264 视频播放到 Android 应用中的 Surface 对象上。我在 HTC 上使用 android 5.0.1。阅读完 android 文档后,我发现我需要使用 MediaCodec 对象来解码原始字节,然后将它们释放到 Surface。我已经翻阅了大量其他问题和文档,但还没有找到我看似非常简单的问题的答案。这是我的代码的 sn-p:

        @Override
        public void surfaceCreated(SurfaceHolder surfHolder) {
            try {
                String codecType = "video/avc";
                MediaFormat mf = MediaFormat.createVideoFormat(codecType, 45 ,45);
                mc = MediaCodec.createByCodecName(codecType);
                mc.configure(mf, surfHolder.getSurface(), null, 0);
                mc.setCallback(vcb);
                mc.start();
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }

但是,当它尝试按名称创建编解码器时,我遇到了问题,并收到此错误:

08-26 18:09:02.054    9132-9132/com.james.firstclient I/InputMethodManager﹕ [startInputInner] EditorInfo { packageName=com.james.firstclient, inputType=0x20001, imeOptions=0x48000005, privateImeOptions=null }, windowGainingFocus=android.view.ViewRootImpl$W@37cf53de, mServedView=android.widget.EditText{2a8889bf VFED..CL .F....I. 48,177-1032,290 #7f080001 app:id/hostText}, mServedInputConnectionWrapper=android.view.inputmethod.InputMethodManager$ControlledInputConnectionWrapper@3ed5088c
08-26 18:09:03.964    9132-9292/com.james.firstclient D/libc﹕ [NET] android_getaddrinfofornet+,hn 12(0x3139322e313638),sn(),hints(known),family 0,flags 4
08-26 18:09:03.964    9132-9292/com.james.firstclient D/libc﹕ [NET] android_getaddrinfofornet-, SUCCESS
08-26 18:09:04.094    9132-9298/com.james.firstclient W/ACodec﹕ Allocating component 'video/avc' failed, try next one.
08-26 18:09:04.094    9132-9298/com.james.firstclient E/ACodec﹕ Unable to instantiate codec 'video/avc'.
08-26 18:09:04.094    9132-9298/com.james.firstclient E/ACodec﹕ signalError(omxError 0x80001003, internalError -2147483648)
08-26 18:09:04.094    9132-9298/com.james.firstclient E/MediaCodec﹕ Codec reported err 0xfffffffe, actionCode 0, while in state 1
08-26 18:09:04.094    9132-9132/com.james.firstclient W/MediaCodec-JNI﹕ try to release MediaCodec from JMediaCodec::~JMediaCodec()...
08-26 18:09:04.094    9132-9132/com.james.firstclient W/MediaCodec-JNI﹕ done releasing MediaCodec from JMediaCodec::~JMediaCodec().
08-26 18:09:04.094    9132-9132/com.james.firstclient W/System.err﹕ java.lang.IllegalArgumentException: Failed to initialize video/avc, error 0xfffffffe
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.media.MediaCodec.native_setup(Native Method)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.media.MediaCodec.<init>(MediaCodec.java:486)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.media.MediaCodec.createByCodecName(MediaCodec.java:470)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at com.james.firstclient.WatchVideoActivity.surfaceCreated(WatchVideoActivity.java:63)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.SurfaceView.updateWindow(SurfaceView.java:579)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2050)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1106)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6018)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.Choreographer$CallbackRecord.run(Choreographer.java:792)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.Choreographer.doCallbacks(Choreographer.java:596)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.Choreographer.doFrame(Choreographer.java:557)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:778)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.os.Looper.loop(Looper.java:155)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5696)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
08-26 18:09:04.114    9132-9132/com.james.firstclient W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

有大量关于实例化 MediaCodec 对象后要做什么的信息,但基本上没有(据我所知)在这种情况下会发生什么。这有点让我希望这只是一个愚蠢的错误。有人知道吗?

提前致谢。

【问题讨论】:

  • "Video/avc" 看起来像 mime 类型,而不是编解码器。在播放时查看视频编解码器解码端表的文档媒体类型。
  • 我实例化了一个MediaCodecList,并使用了上面MediaFormat的findDecoderForFormat方法。这会产生错误:视频/avc 无法识别的配置文件 2130706433。我在正确的轨道上吗?补充一下我对音频不感兴趣会有所帮助吗?
  • 格式不等于 mime 类型。文档说支持 H264/AVC。所以使用 ffprobe 或其他东西来转储媒体的标题数据并从那里开始
  • bigflake (bigflake.com/mediacodec) 和 Grafika (github.com/google/grafika) 的一些示例。你可能想要createDecoderByType() 而不是名字。你的视频真的是 45 x 45 像素吗?
  • 按类型而不是名称创建解码器似乎已经成功了。此外,45p x 45p 只是我输入的数字。这是我第一次使用媒体编解码器,所以我选择了一些。我仍然遇到一些与我正在处理的 sps 和 pps 标头相关的问题。我正在使用树莓派相机模块并使用 python 模块 picamera 在树莓派上操作它。鉴于帖子的标题,我认为我们可以考虑回答这个问题。谢谢你们的帮助!

标签: android video-streaming h.264 android-mediacodec


【解决方案1】:

使用 createDecoderByType 而不是 createByCodecName。

【讨论】:

    猜你喜欢
    • 2013-09-30
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 2023-03-04
    相关资源
    最近更新 更多