小编Max*_*uta的帖子

Android MediaCodec 将原始视频编码为 h264

我正在尝试将我的手机相机输出转换为 .h264 es 格式,但 MediaCodec 编码器在第一帧后停留在 TRY_AGAIN_LATER 输出缓冲区状态。相机预览设置为 NV21。

这是相机到编码器:

    mCamera.setPreviewCallback(new Camera.PreviewCallback() {
            private long timestamp=0;
            @Override
            public void onPreviewFrame(byte[] data, Camera camera) {
                byte[] buffer = new byte[data.length];
                encode(data);
            }
        });
Run Code Online (Sandbox Code Playgroud)

编码器初始化:

private void initCodec() {
        try {
            mBufferInfo = new MediaCodec.BufferInfo();
            mMediaCodec = MediaCodec.createEncoderByType("video/avc");
        } catch (IOException e) {
            e.printStackTrace();
        }
        MediaFormat mediaFormat = MediaFormat.createVideoFormat("video/avc",
                1920,
                1080);
        mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 125000);
        mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
        mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,
             MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar);
        mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
        mMediaCodec.configure(mediaFormat,
                null,
                null,
                MediaCodec.CONFIGURE_FLAG_ENCODE);
        mMediaCodec.start();
    }
Run Code Online (Sandbox Code Playgroud)

和编码器本身:

private synchronized void encode(byte[] data) { …
Run Code Online (Sandbox Code Playgroud)

encoding android h.264 android-mediacodec

6
推荐指数
0
解决办法
4670
查看次数

使用具有约束布局的设计支持库

我尝试在 ConstraintLayout 中使用支持设计库中的 TextInputLayout,但出现错误:

android.widget.LinearLayout$LayoutParams 
cannot be cast to android.support.constraint.ConstraintLayout$LayoutParams
Run Code Online (Sandbox Code Playgroud)

如何实现与 support.design.widget.TextInputLayout 相同的功能,但使用 ConstraintLayout?

完整布局在这里:http : //pastebin.com/TjC0FAdS

问题是:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/constraintLayout">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <AutoCompleteTextView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:singleLine="true"
            android:id="@+id/email"
            android:hint="@string/prompt_email"
            app:layout_constraintLeft_toRightOf="@+id/imageView3"
            android:layout_marginStart="8dp"
            app:layout_constraintTop_toBottomOf="@+id/logo"
            android:layout_marginTop="16dp"
            app:layout_constraintRight_toRightOf="@+id/constraintLayout"
            android:layout_marginEnd="16dp" />
    </android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

android textinputlayout android-constraintlayout

3
推荐指数
1
解决办法
1737
查看次数