过滤运行时在 GLSurfaceView 上播放视频 [英] Filter on playing video on GLSurfaceView at runtime

查看:35
本文介绍了过滤运行时在 GLSurfaceView 上播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

to apply filter on playing video. But I want to change the filter on click of button at runtime without any glitch on playing video.

根据对正在播放的视频应用效果

我应该使用

mVideoView.init(mMediaPlayer,new filter)

每当我想改变过滤器.但播放视频没有效果

whenever I want to change filter.But there is no effect on playing video

有人可以帮我吗...我没有使用 GLSurfaceView 的经验.

Can someone help me... I am not experienced in using GLSurfaceView.

这是我的java类

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>

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

In this Sepia Effect is already set but I want to change that to vignette on button click

推荐答案

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

Just add this line in onDrawFrame() and you will get the desired result

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

你的 onDrawFrame() 应该是这样的:

Your onDrawFrame() should look something like this:

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

    }

这篇关于过滤运行时在 GLSurfaceView 上播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆