在运行时过滤在 GLSurfaceView 上播放视频

Filter on playing video on GLSurfaceView at runtime

我用过 https://github.com/krazykira/VidEffects

在播放视频时应用滤镜。 但我想在运行时更改单击按钮时的过滤器,而不会在播放视频时出现任何故障。

根据

我应该使用

mVideoView.init(mMediaPlayer,new filter)

每次想改filter.But对播放视频没有影响

谁能帮帮我...我没有使用 GLSurfaceView 的经验。

这是我的javaclass

public class MainActivity extends Activity {

private static final String TAG = "MediaPlayerSurfaceStubActivity";

protected Resources mResources;
ShaderInterface d = null;
private  VideoSurfaceView mVideoView = null;
private MediaPlayer mMediaPlayer = null;
private Button button;
LinearLayout linear;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    mVideoView = (VideoSurfaceView) findViewById(R.id.mVideoSurfaceView);
    linear = (LinearLayout) findViewById(R.id.linear);
    button = (Button) findViewById(R.id.effects);


//HERE , on click of following button I want the effect to be applied at runtime.


    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            System.gc();

            mVideoView.init(mMediaPlayer, new VignetteEffect(2));

        }
    });
    mResources = getResources();
    mMediaPlayer = new MediaPlayer();

    try {

        AssetFileDescriptor afd = getAssets().openFd("sample.mp4");
        mMediaPlayer.setDataSource(afd.getFileDescriptor(),
                afd.getStartOffset(), afd.getLength());
    } catch (Exception e) {
        e.printStackTrace();
    }

    mVideoView.init(mMediaPlayer,
            new SepiaEffect());

}


@Override
protected void onResume() {
    super.onResume();
    mVideoView.onResume();
}
}

我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linear"
tools:context="videoeditor.xcs.com.videoeffect.MainActivity">

<com.sherazkhilji.videffect.view.VideoSurfaceView
    android:id="@+id/mVideoSurfaceView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="effects"
    android:id="@+id/effects"/>

</LinearLayout>

在此棕褐色效果中已设置,但我想将其更改为单击按钮时的晕影

只需在 onDrawFrame() 中添加这一行,您就会得到想要的结果

        mProgram = createProgram(mVertexShader,
                effect.getShader(mSurfaceView));

您的 onDrawFrame() 应如下所示:

 @Override
    public void onDrawFrame(GL10 glUnused) {
        synchronized (this) {
            if (updateSurface) {
                mSurface.updateTexImage();
                mSurface.getTransformMatrix(mSTMatrix);
                updateSurface = false;
            }
        }

        mProgram = createProgram(mVertexShader,
                effect.getShader(mSurfaceView));
        GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
        GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT
                | GLES20.GL_COLOR_BUFFER_BIT);

        GLES20.glUseProgram(mProgram);
        checkGlError("glUseProgram");

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID[0]);

        mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
        GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT,
                false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
                mTriangleVertices);
        checkGlError("glVertexAttribPointer maPosition");
        GLES20.glEnableVertexAttribArray(maPositionHandle);
        checkGlError("glEnableVertexAttribArray maPositionHandle");

        mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
        GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT,
                false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
                mTriangleVertices);
        checkGlError("glVertexAttribPointer maTextureHandle");
        GLES20.glEnableVertexAttribArray(maTextureHandle);
        checkGlError("glEnableVertexAttribArray maTextureHandle");

        Matrix.setIdentityM(mMVPMatrix, 0);
        GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix,
                0);
        GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);

        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
        checkGlError("glDrawArrays");
        GLES20.glFinish();

    }