安卓无法实例化编解码器“video/avc”。

10

这是我的第一篇文章,所以请多包容。

我正在尝试在 Android 应用程序中将原始 H264 视频播放到 Surface 对象上。我在 HTC One 上使用的是 Android 5.0.1。阅读了 Android 文档后,我发现需要使用 MediaCodec 对象来解码原始字节,然后将它们释放到 Surface 上。我已经浏览了大量其他问题和文档,但似乎没有找到解决我的非常简单的问题的答案。这是我的一部分代码:

        @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" 看起来像是一种媒体类型而不是编解码器。请查看文档中有关视频编解码器的表格,以便在播放时进行解码。 - Robert Rowntree
我实例化了一个MediaCodecList,并使用上述MediaFormat的findDecoderForFormat方法。这会产生一个错误:video/avc的未识别配置文件2130706433。我走在正确的轨道上吗?如果我不关心音频,是否有帮助? - JMLoy
格式不等于MIME类型。文档中说支持H264/AVC。因此,请使用ffprobe或其他工具转储媒体的头数据,然后从那里开始。 - Robert Rowntree
3
关于bigflake (http://bigflake.com/mediacodec/) 和Grafika (https://github.com/google/grafika) 的一些例子。您可能想使用 createDecoderByType() 而不是按名称创建解码器。您的视频确实只有45像素乘45像素吗? - fadden
通过类型而不是名称创建解码器似乎解决了问题。此外,45p x 45p只是我随便选的数字。这是我第一次使用媒体编解码器,所以我只是随便选了一些。我仍然遇到一些与sps和pps头文件相关的问题,正在努力解决。我正在使用树莓派相机模块,并使用Python模块picamera在树莓派上进行操作。考虑到帖子的标题,我认为我们可以认为这个问题已经得到解答。谢谢你们两个的帮助! - JMLoy
1个回答

0
请使用createDecoderByType而不是createByCodecName。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接