htwahzs / Rtsp-Android-Client

Andoird rtsp client module, can use surfaceview to display
171 stars 62 forks source link

您好,可不可以帮我看看应该怎样设置? #3

Open xvusrmqj opened 7 years ago

xvusrmqj commented 7 years ago

空指针异常,H264Stream中的的header_sps和header_pps为空,注释了这两句但是播放不出来,应该怎么办?

    private void configMediaDecoder(){
        if(Build.VERSION.SDK_INT > 15) {
            mMeidaCodec = MediaCodec.createDecoderByType("Video/AVC");
            MediaFormat mediaFormat = new MediaFormat();
            mediaFormat.setString(MediaFormat.KEY_MIME, "Video/AVC");
            // * 这里的header_sps和header_pps为空。。。。注释了这两句也播放不出来。。。。 *
            mediaFormat.setByteBuffer("csd-0", ByteBuffer.wrap(header_sps));
            mediaFormat.setByteBuffer("csd-1", ByteBuffer.wrap(header_pps));
            mediaFormat.setInteger(MediaFormat.KEY_WIDTH, picWidth);
            mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, picHeight);
            mMeidaCodec.configure(mediaFormat, mSurfaceView.getHolder().getSurface(), null, 0);
            mMeidaCodec.start();
            inputBuffers = mMeidaCodec.getInputBuffers();
            isStop = false;
        }
    }

后面发现好像是: public static final Pattern regexSDPspspps = Pattern.compile("sprop-parameter-sets=(\\S+),(\\S+)",Pattern.CASE_INSENSITIVE); 这里没有匹配到,是不是要求rtsp里的视频有什么要求啊?我在vlc里可以播放的。

batimongolia commented 4 years ago

让系统系统获取, 不强行设置, 就可以了 MediaFormat mediaformat = MediaFormat.createVideoFormat("video/avc", 1920, 1080); mediaformat.setInteger(MediaFormat.KEY_BIT_RATE, 40000000); // 125000 mediaformat.setInteger(MediaFormat.KEY_FRAME_RATE, 30); mMeidaCodec = MediaCodec.createDecoderByType("Video/AVC"); //MediaFormat mediaFormat = new MediaFormat(); //mediaFormat.setString(MediaFormat.KEY_MIME, "Video/AVC"); //mediaFormat.setByteBuffer("csd-0", ByteBuffer.wrap(header_sps)); //mediaFormat.setByteBuffer("csd-1", ByteBuffer.wrap(header_pps)); //mediaFormat.setInteger(MediaFormat.KEY_WIDTH, picWidth); //mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, picHeight); //mMeidaCodec.configure(mediaFormat, mSurfaceView.getHolder().getSurface(), null, 0); mMeidaCodec.configure(mediaformat, mSurfaceView.getHolder().getSurface(), null, 0); mMeidaCodec.start();