10

This is my first post, so bear with me.

I'm trying to play raw h264 video onto a Surface object in an android app. I'm using android 5.0.1 on an HTC one. After reading through the android docs, I've found that I need to use a MediaCodec object to decode the raw bytes and then release them to the Surface. I've poured through tons of other questions and docs, but haven't found an answer to my seemingly very simple problem. Here is a snippet of my code:

        @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();
            }
        }

However, I am getting stuck when it tries to create the codec by name, and I get this error:

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)

There is tons of information on what to do after the MediaCodec object is instantiated, but basically nothing (from what I can find) on what happens in this scenario. This kinda makes me hopeful that it's just a silly mistake. Does anyone have any idea?

Thanks in advance.

JMLoy
  • 121
  • 1
  • 1
  • 6
  • "Video/avc" looks like a mime type and not a codec. Review the docs media types for the table of video codecs decode side since you are playing. – Robert Rowntree Aug 27 '15 at 00:07
  • I instantiated a MediaCodecList and used the findDecoderForFormat method using the above MediaFormat. This produces an error: Unrecognized profile 2130706433 for video/avc. Am I on the right track? Would it help to add that I'm not interested in audio? – JMLoy Aug 27 '15 at 00:40
  • Format not equal to a mime type. The docs say H264/AVC supported. So use ffprobe or something to dump the header data for your media and go fromthere – Robert Rowntree Aug 27 '15 at 00:57
  • 3
    Some examples on bigflake (http://bigflake.com/mediacodec/) and Grafika (https://github.com/google/grafika). You probably want `createDecoderByType()` rather than by name. Is your video really 45 pixels by 45 pixels? – fadden Aug 27 '15 at 01:03
  • Creating the decoder by type rather than name seems to have done the trick. Also, the 45p x 45p were just numbers I threw in there. This is my first go with the media codec so I just picked some. I'm still running into some problems related to the sps and pps headers that I'm working through. I'm using the raspberry pi camera module and using the python module picamera to manipulate that on the raspberry pi. Given the title of the post, I think we can consider this question answered. Thank you both for your help! – JMLoy Aug 27 '15 at 22:30

1 Answers1

0

Use createDecoderByType instead of createByCodecName.

Shailendra Yadav
  • 1,822
  • 1
  • 12
  • 16